unist-util-is
unist utility to check if a node passes a test.
Install
npm:
npm install unist-util-is
Usage
var is = require('unist-util-is')
var node = {type: 'strong'}
var parent = {type: 'paragraph', children: [node]}
function test(node, n) {
return n === 5
}
is() // => false
is(null, {children: []}) // => false
is(null, node) // => true
is('strong', node) // => true
is('emphasis', node) // => false
is(node, node) // => true
is({type: 'paragraph'}, parent) // => true
is({type: 'strong'}, parent) // => false
is(test, node) // => false
is(test, node, 4, parent) // => false
is(test, node, 5, parent) // => true
API
is(test, node[, index, parent[, context]])
Parameters
test(Function,string,Object, orArray.<Test>, optional) — When not given, checks ifnodeis aNode. Whenstring, works like passingnode => node.type === test. Whenarray, checks if any one of the subtests pass. Whenobject, checks that all keys intestare innode, and that they have strictly equal valuesnode(Node) — Node to check.falseis returnedindex(number, optional) — Index ofnodeinparentparent(Node, optional) — Parent ofnodecontext(*, optional) — Context object to invoketestwith
Returns
boolean — Whether test passed and node is a Node (object
with type set to a non-empty string).
function test(node[, index, parent])
Parameters
node(Node) — Node to testindex(number?) — Position ofnodeinparentparent(Node?) — Parent ofnode
Context
* — The to is given context.
Returns
boolean? — Whether node matches.
Related
unist-util-find-after— Find a node after another nodeunist-util-find-before— Find a node before another nodeunist-util-find-all-after— Find all nodes after another nodeunist-util-find-all-before— Find all nodes before another nodeunist-util-find-all-between— Find all nodes between two nodesunist-util-find— Find nodes matching a predicateunist-util-filter— Create a new tree with nodes that pass a checkunist-util-remove— Remove nodes from tree
Contribute
See contributing.md in syntax-tree/.github for ways to get
started.
See support.md for ways to get help.
This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.