Unist utility to check if a node passes a test.
npm:
npm install unist-util-is
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
test
(Function
,string
,Object
, orArray.<Test>
, optional) — When not given, checks ifnode
is aNode
. Whenstring
, works like passingfunction (node) {return node.type === test}
. Whenarray
, checks any one of the subtests pass. Whenobject
, checks that all keys intest
are innode
, and that they have (strictly) equal valuesnode
(Node
) — Node to check.false
is returnedindex
(number
, optional) — Position ofnode
inparent
parent
(Node
, optional) — Parent ofnode
context
(*
, optional) — Context object to invoketest
with
boolean
— Whether test
passed and node
is a Node
(object
with type
set to non-empty string
).
node
(Node
) — Node to testindex
(number?
) — Position ofnode
inparent
parent
(Node?
) — Parent ofnode
*
— The to is
given context
.
boolean?
— Whether node
matches.
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
See contributing.md
in syntax-tree/unist
for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.