unist-util-is is a lightweight utility within the unified (remark/rehype) ecosystem designed to check if a unist (Universal Syntax Tree) node satisfies a given condition. It provides the `is` function to test nodes against various criteria, including their `type`, specific properties, or custom predicate functions. Additionally, it offers `convert` to pre-process tests, which is beneficial for performance when repeatedly checking multiple nodes. The package is currently stable at version 6.0.1 and maintains an active development pace, releasing updates for new Node.js versions and refining type definitions, generally aligning with the broader unified ecosystem's release cadence. It serves as a focused tool for basic node matching, distinguishing itself from `hast-util-is-element` (which targets HAST elements) and providing a simpler alternative to the more complex CSS selector-based matching of `unist-util-select`. Full TypeScript type definitions are included.
npm install unist-util-isVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the `is` function with various test types: no test, object checks, string types, direct node comparison, and a custom predicate function with index and parent context.
Upgrade your Node.js environment to version 16 or newer.
Migrate your codebase to use ES Module `import` syntax. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Review your TypeScript code and update type annotations. Replace deprecated types with `Check` and `TestFunction` as appropriate. Ensure `@types/unist` is also updated to its latest compatible version.
Always use named imports: `import { is, convert } from 'unist-util-is'`.When debugging, be aware that `is(null)` or `is(undefined)` will return `false`, whereas `is(node, null, 'invalid-index')` would throw an error. Handle `node` parameter validity separately if an explicit error is desired.
Change your import statement to use `import { is } from 'unist-util-is'` and ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`).Use a named import: `import { is } from 'unist-util-is'`.Update your code to use the new type aliases introduced in v6.0.0, specifically `Check` and `TestFunction`. Ensure `@types/unist` is also up-to-date.
1. Verify Node.js version is 16+. 2. Ensure `@types/unist` is installed: `npm install @types/unist`. 3. Confirm your `tsconfig.json` (if applicable) and `package.json` are correctly configured for ES Modules.