This package, `hast-util-is-element`, is a fundamental utility within the HAST (Hypertext Abstract Syntax Tree) ecosystem, primarily designed to check if a given HAST node represents an HTML element. It offers flexible testing capabilities, allowing developers to verify not only if a node is an element but also if it matches specific tag names, an array of tag names, or even complex criteria through a predicate function. The library is currently stable at version 3.0.0, which introduced significant changes, including a migration to ESM-only distribution and a requirement for Node.js 16 or newer. Its release cadence is generally tied to updates within the broader syntax-tree ecosystem, including HAST type definition improvements and Node.js version alignment. A key differentiator is its specialized focus on HAST nodes, providing a more targeted and potentially performant alternative compared to the more generic `unist-util-is` for general Unist nodes. For advanced matching based on CSS selectors, `hast-util-select` offers more robust capabilities, positioning `hast-util-is-element` as a lightweight yet powerful tool for basic and custom element checks.
npm install hast-util-is-elementVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `isElement` function to check different HAST nodes against various criteria, including tag names, arrays of tag names, and custom predicate functions.
Migrate your project to use ES modules (`import`/`export`) or stick to an older version (<3.0.0) if CommonJS is strictly required.
Ensure your Node.js environment is version 16 or newer. Upgrade Node.js if necessary.
Only use the public API as exported from the main package entry point (`import { ... } from 'hast-util-is-element'`).Update your TypeScript code to use the new type names: `Check`, `Test`, `TestFunction`. Remove explicit type parameters where they are no longer necessary.
Always ensure that `test`, `index`, and `parent` arguments conform to the expected types and structure to avoid runtime errors. Validate `element` type before calling if strict node type checking is needed.
Change `const { isElement } = require('hast-util-is-element');` to `import { isElement } from 'hast-util-is-element';` and ensure your project is configured for ESM.Verify that you are using `import { isElement } from 'hast-util-is-element';` in an ESM context. If using a bundler, check its ESM/CommonJS compatibility settings.Update your TypeScript code to use the new type names introduced in v3: `Check`, `Test`, or `TestFunction`.
No dependency data recorded yet.