Gathering detailed insights and metrics for unist-util-is
Gathering detailed insights and metrics for unist-util-is
Gathering detailed insights and metrics for unist-util-is
Gathering detailed insights and metrics for unist-util-is
unist-util-generated
unist utility to check if a node is generated
hast-util-is-element
hast utility to check if a node is a (certain) element
mdast-util-phrasing
mdast utility to check if a node is phrasing content
hast-util-whitespace
hast utility to check if a node is inter-element whitespace
npm install unist-util-is
Typescript
Module System
Node Version
NPM Version
99.4
Supply Chain
99.5
Quality
78.2
Maintenance
100
Vulnerability
100
License
JavaScript (68.92%)
TypeScript (31.08%)
Total Downloads
2,742,768,695
Last Day
991,703
Last Week
17,329,400
Last Month
74,185,394
Last Year
787,395,991
MIT License
42 Stars
127 Commits
8 Forks
9 Watchers
1 Branches
14 Contributors
Updated on Jun 21, 2025
Minified
Minified + Gzipped
Latest Version
6.0.0
Package Id
unist-util-is@6.0.0
Unpacked Size
26.48 kB
Size
6.76 kB
File Count
7
NPM Version
9.7.2
Node Version
20.0.0
Published on
Jul 07, 2023
Cumulative downloads
Total Downloads
Last Day
-0.9%
991,703
Compared to previous day
Last Week
-7.3%
17,329,400
Compared to previous week
Last Month
2.5%
74,185,394
Compared to previous month
Last Year
19.8%
787,395,991
Compared to previous year
1
unist utility to check if nodes pass a test.
This package is a small utility that checks that a node is a certain node.
Use this small utility if you find yourself repeating code for checking what nodes are.
A similar package, hast-util-is-element
, works on hast
elements.
For more advanced tests, unist-util-select
can be used
to match against CSS selectors.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install unist-util-is
In Deno with esm.sh
:
1import {is} from 'https://esm.sh/unist-util-is@6'
In browsers with esm.sh
:
1<script type="module"> 2 import {is} from 'https://esm.sh/unist-util-is@6?bundle' 3</script>
1import {is} from 'unist-util-is' 2 3const node = {type: 'strong'} 4const parent = {type: 'paragraph', children: [node]} 5 6is() // => false 7is({children: []}) // => false 8is(node) // => true 9is(node, 'strong') // => true 10is(node, 'emphasis') // => false 11 12is(node, node) // => true 13is(parent, {type: 'paragraph'}) // => true 14is(parent, {type: 'strong'}) // => false 15 16is(node, test) // => false 17is(node, test, 4, parent) // => false 18is(node, test, 5, parent) // => true 19 20function test(node, n) { 21 return n === 5 22}
This package exports the identifiers convert
and
is
.
There is no default export.
is(node[, test[, index, parent[, context]]])
Check if node
is a Node
and whether it passes the given test.
node
(unknown
, optional)
— thing to check, typically Node
test
(Test
, optional)
— a test for a specific elementindex
(number
, optional)
— the node’s position in its parentparent
(Node
, optional)
— the node’s parentcontext
(unknown
, optional)
— context object (this
) to call test
withWhether node
is a Node
and passes a test (boolean
).
When an incorrect test
, index
, or parent
is given.
There is no error thrown when node
is not a node.
convert(test)
Generate a check from a test.
Useful if you’re going to test many nodes, for example when creating a utility where something else passes a compatible test.
The created function is a bit faster because it expects valid input only:
a node
, index
, and parent
.
test
(Test
, optional)
— a test for a specific nodeA check (Check
).
Check
Check that an arbitrary value is a node (TypeScript type).
this
(unknown
, optional)
— context object (this
) to call test
withnode
(unknown
)
— anything (typically a node)index
(number
, optional)
— the node’s position in its parentparent
(Node
, optional)
— the node’s parentWhether this is a node and passes a test (boolean
).
Test
Check for an arbitrary node (TypeScript type).
1type Test = 2 | Array<Record<string, unknown> | TestFunction | string> 3 | Record<string, unknown> 4 | TestFunction 5 | string 6 | null 7 | undefined
Checks that the given thing is a node, and then:
string
, checks that the node has that tag namefunction
, see TestFunction
object
, checks that all keys in test are in node, and that they have
(strictly) equal valuesArray
, checks if one of the subtests passTestFunction
Check if a node passes a test (TypeScript type).
node
(Node
)
— a nodeindex
(number
or undefined
)
— the node’s position in its parentparent
(Node
or undefined
)
— the node’s parentWhether this node passes the test (boolean
, optional).
convert
1import {u} from 'unist-builder' 2import {convert} from 'unist-util-is' 3 4const test = convert('leaf') 5 6const tree = u('tree', [ 7 u('node', [u('leaf', '1')]), 8 u('leaf', '2'), 9 u('node', [u('leaf', '3'), u('leaf', '4')]), 10 u('leaf', '5') 11]) 12 13const leafs = tree.children.filter(function (child, index) { 14 return test(child, index, tree) 15}) 16 17console.log(leafs)
Yields:
1[{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]
This package is fully typed with TypeScript.
It exports the additional types Check
,
Test
,
TestFunction
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, unist-util-is@^6
,
compatible with Node.js 16.
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-filter
— create a new tree with nodes that pass a checkunist-util-remove
— remove nodes from treeSee 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, organization, or community you agree to abide by its terms.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More