unist-util-is
Unist utility to check if a node passes a test.
Installation
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()
is(null, {children: []})
is(null, node)
is('strong', node)
is('emphasis', node)
is(node, node)
is({type: 'paragraph'}, parent)
is({type: 'strong'}, parent)
is(test, node)
is(test, node, 4, parent)
is(test, node, 5, parent)
API
is(test, node[, index, parent[, context]])
Parameters
test
(Function
, string
, Object
, or Array.<Test>
, optional)
— When not given, checks if node
is a Node
.
When string
, works like passing function (node) {return node.type === test}
.
When array
, checks any one of the subtests pass.
When object
, checks that all keys in test
are in node
,
and that they have (strictly) equal valuesnode
(Node
) — Node to check. false
is returnedindex
(number
, optional) — Position of node
in parent
parent
(Node
, optional) — Parent of node
context
(*
, optional) — Context object to invoke test
with
Returns
boolean
— Whether test
passed and node
is a Node
(object
with type
set to non-empty string
).
function test(node[, index, parent])
Parameters
node
(Node
) — Node to testindex
(number?
) — Position of node
in parent
parent
(Node?
) — Parent of node
Context
*
— The to is
given context
.
Returns
boolean?
— Whether node
matches.
Related
Contribute
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.
License
MIT © Titus Wormer