The unist-util-select package is a utility for selecting nodes in a Unist syntax tree using CSS-like selectors. It allows for querying and manipulating nodes in a tree structure, making it easier to work with abstract syntax trees (ASTs) in JavaScript.
What are unist-util-select's main functionalities?
Select a single node
This feature allows you to select a single node from the tree that matches the given selector. In this example, it selects the first 'paragraph' node in the tree.
This feature allows you to select all nodes from the tree that match the given selector. In this example, it selects all 'paragraph' nodes in the tree.
This feature allows you to select nodes that have specific attributes. In this example, it selects all nodes with a 'data-id' attribute equal to 'intro'.
unist-util-visit is a utility for recursively visiting nodes in a Unist syntax tree. It allows for more complex traversal and manipulation of nodes compared to unist-util-select, but does not use CSS-like selectors.
hast-util-select is similar to unist-util-select but is specifically designed for working with HAST (Hypertext Abstract Syntax Tree) nodes. It provides CSS-like selectors for querying HAST nodes.
unist-builder is a utility for creating Unist syntax trees. While it does not provide querying capabilities like unist-util-select, it is useful for constructing trees programmatically.
unist-util-select
unist utility with equivalents for querySelector,
querySelectorAll, and matches.
Note that the DOM has references to their parent nodes, meaning that
document.body.matches(':last-child') can be evaluated.
This information is not stored in unist, so selectors like that don’t work.
Check that the given node matches selector.
Returns boolean, whether the node matches or not.
This only checks the element itself, not the surrounding tree.
Thus, nesting in selectors is not supported (paragraph strong,
paragraph > strong), nor are selectors like :first-child, etc.
This only checks that the given element matches the selector.
var u = require('unist-builder')
var matches = require('unist-util-select').matchesmatches('strong, em', u('strong', [u('text', 'important')])) // => truematches('[lang]', u('code', {lang: 'js'}, 'console.log(1)')) // => true
select.select(selector, tree)
Select the first node matching selector in the given tree (could be the
tree itself).
Returns the found node, if any.
unist utility to select nodes with CSS-like selectors
The npm package unist-util-select receives a total of 135,432 weekly downloads. As such, unist-util-select popularity was classified as popular.
We found that unist-util-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 30 Oct 2020
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.