hast-util-select provides a suite of utilities for querying and matching nodes within a HAST (HTML Abstract Syntax Tree) structure using CSS selectors. It offers functions equivalent to DOM's `matches`, `querySelector`, and `querySelectorAll` for HTML trees. The current stable version is 6.0.4, with active maintenance and a regular release cadence, including recent major updates. A key differentiator is its specific application to HAST, which means it operates differently from DOM selectors in certain aspects, particularly regarding parent-sensitive selectors (e.g., `:first-child`, descendant selectors) due to HAST nodes not storing parent references. While powerful for targeted queries, it advises caution for high-frequency use, suggesting `unist-util-visit` for bulk modifications due to its tree-walking overhead.
npm install hast-util-selectVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `matches`, `select`, and `selectAll` functions with a HAST tree to find and match elements based on CSS selectors.
Migrate your project to use ESM imports (`import ... from 'pkg'`) and ensure Node.js 16+ is used. Update your `package.json` with `"type": "module"` if necessary for your environment.
Update your code to expect and handle `undefined` when no element is found, instead of `null`. E.g., `if (node === undefined)` rather than `if (node === null)`.
Review and update complex CSS selectors to adhere to modern CSS Selectors Level 4 syntax. Replace `:any` with `:is()` where appropriate.
Avoid parent-sensitive CSS selectors. For operations requiring tree traversal or parent context, consider using utilities like `unist-util-visit` or performing manual tree traversal after selecting direct children.
If performance is critical for large trees or frequent operations, consider using `unist-util-visit` to traverse the tree once and apply transformations or checks, rather than multiple calls to `select` or `selectAll`.
Change your import statement from `const { symbol } = require('hast-util-select')` to `import { symbol } from 'hast-util-select'`. Ensure your `package.json` is configured for ESM (`"type": "module"`).Replace `:any` with the standard `:is()` pseudo-class in your selectors. Review other deprecated CSS selectors and update them to modern equivalents.
Update your conditional checks from `if (node === null)` to `if (node === undefined)` (or `if (!node)` for both `null` and `undefined`).
No dependency data recorded yet.