Unist utility to check if a node passes a test. Useful when working with mdast or retext.
npm:
npm install unist-util-is
unist-util-is is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.
var is = require('.');
var node = {
'type': 'strong'
};
var parent = {
'type': 'paragraph',
'children': [node]
};
function test(node, n) {
return n === 5
}
is(null, node); // true
is('strong', node); // true
is('emphasis', node); // false
is(node, node) // true
is(node, {type: 'strong'}) // false
is(test, node); // false
is(test, node, 4, parent); // false
is(test, node, 5, parent); // true
Utility to check if a node passes a test.
Parameters:
-
test
(Function
,string
, orNode
, optional) — When not given, return is returntrue
.Passing a
string
is equal to passingfunction (node) {return node.type === test}
.Passing a
node
is equal to passingfunction (node) {return node === test}
. -
node
(Node
) — Node to test; -
index
(number
, optional) — Position ofnode
inparent
; -
parent
(Node
, optional) — Parent ofnode
; -
context
(*
, optional) — Parent ofnode
.
Returns: boolean
, whether test
passed.
Parameters:
node
(Node
) — Node to test;index
(number
?) — Position ofnode
inparent
.parent
(Node
?) — Parent ofnode
.
Context: The to is
given context.
Returns: boolean?
, whether this iteration passes.