unist-util-assert is a utility package within the unified/syntax-tree ecosystem designed to validate unist (Universal Syntax Tree) nodes. It provides functions to assert that given `tree` or `node` structures conform to the unist specification, including checks for parent, literal, and void nodes, and their children. The current stable version is 4.0.0. This package maintains an active release cadence, reflecting ongoing development and compatibility updates within the broader unified collective. Key differentiators include its tight integration with the unist specification, robust type checking (it ships with TypeScript types), and its focused approach to node validation, contrasting with more general-purpose assertion libraries or similar utilities for specific node types like mdast or hast.
npm install unist-util-assertVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `assert`, `parent`, and `_void` to validate unist nodes, including examples of valid and invalid node structures that trigger `AssertionError`.
Upgrade your Node.js environment to version 16 or newer. Use nvm or a similar tool to manage Node.js versions.
Migrate your codebase to use ES modules (`import`) instead of CommonJS `require()`. Ensure your project's `package.json` is configured for ESM (e.g., `"type": "module"` or `.mjs` files).
Update your own `@types/unist` dependency to align with the version required by unist-util-assert@4.0.0 or newer. Review any custom type definitions for compatibility.
Remove any custom type definitions for `unist-util-assert` and rely on the official types shipped with the package. Review your TypeScript configuration for any conflicts.
Always import symbols directly from `unist-util-assert` using their public API (e.g., `import { assert } from 'unist-util-assert'`). Avoid deep imports or relying on internal file structures.Ensure all unist nodes have a valid `type` string property, e.g., `{ type: 'root', children: [] }`.Only pass nodes with a `children` array (even if empty) to the `parent` assertion, e.g., `{ type: 'paragraph', children: [] }`.Ensure that any `properties` object on a unist node contains only JSON-compatible values (strings, numbers, booleans, arrays, null, or other JSON objects).
Only use `_void` assertion on nodes that are explicitly void and lack `value` or `children` properties, e.g., `{ type: 'break' }`.Ensure all children within a parent node's `children` array are valid unist node objects, not primitive values.
No dependency data recorded yet.