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
, orNode
, optional) — When not given, checks ifnode
is aNode
. Whenstring
, works like passingfunction (node) {return node.type === test}
. Whenobject
, checks that all keys intest
are innode
, and that they have (strictly) equal values.node
(Node
) — Node to check.false
is returned;index
(number
, optional) — Position ofnode
inparent
;parent
(Node
, optional) — Parent ofnode
;context
(*
, optiona) — 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 test;index
(number?
) — Position ofnode
inparent
;parent
(Node?
) — Parent ofnode
.
*
— The to is
given context
.
boolean?
— Whether node
matches.