unist-util-select is a utility designed to query and match nodes within a unist (Universal Syntax Tree) abstract syntax tree using CSS-like selectors. The package is currently at stable version 5.1.0 and maintains an active release cadence, with multiple minor and major updates in the past year, reflecting ongoing development and adherence to modern JavaScript standards. Key differentiators include its ability to work with any unist syntax tree and select all node types, providing equivalents to DOM's `querySelector`, `querySelectorAll`, and `matches`. However, it's important to note that unlike the DOM, unist nodes do not inherently store parent references, meaning certain parent-sensitive selectors (e.g., `:first-child`) will not function as they do in a browser environment. For performance-critical scenarios involving numerous modifications, alternatives like `unist-util-visit` might be more efficient, as `unist-util-select` walks the entire tree on each call. For `hast` (HTML AST) specific element selections, `hast-util-select` is recommended.
npm install unist-util-selectVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `matches`, `select`, and `selectAll` to query a unist tree with CSS-like selectors, including handling different selector types and multiple results.
Upgrade Node.js to version 16 or higher, or pin to `unist-util-select@^4`.
Migrate all imports to use ES module syntax (e.g., `import { select } from 'unist-util-select'`).Update existing code to expect and handle `undefined` instead of `null` for no match.
Refactor logic to manually traverse parent/child relationships using `unist-util-visit` or `unist-util-parents` for context, or use simpler, node-specific selectors.
Consider optimizing operations that repeatedly query the tree. For complex modifications, use `unist-util-visit` to traverse once and make changes, or cache selection results if appropriate.
Change your import statements to use ES module syntax: `import { select } from 'unist-util-select';`Ensure you are using named ES module imports: `import { matches } from 'unist-util-select';`Revise your selector to avoid parent-sensitive pseudo-classes. If parent context is strictly needed, you may need to pre-process your tree (e.g., with `unist-util-parents`) or perform manual checks during traversal.
No dependency data recorded yet.