mdast-util-assert is a focused utility from the unified collective designed to validate the structure and properties of mdast (Markdown Abstract Syntax Tree) nodes. It provides functions to assert that a given object conforms to the expected shape of mdast nodes, including parent, literal, and void nodes. This package is particularly useful within API contexts where specific node types are expected, ensuring data integrity and preventing unexpected runtime errors. The current stable version is 5.0.0, which requires Node.js 16+ and is exclusively an ES Module (ESM). Release cadence generally follows semver, with major versions introducing breaking changes related to Node.js compatibility or module systems, while minor versions address bug fixes and documentation. Its key differentiator is its specialization for mdast nodes, building upon and re-exporting parts of the more general `unist-util-assert` for universal syntax trees.
npm install mdast-util-assertVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `assert` to validate mdast nodes, showing successful and failing assertions with error handling.
Upgrade your Node.js environment to version 16 or later to use `mdast-util-assert@5`.
Migrate your project to use ES Modules (import/export syntax). If you are unable to migrate, you might need to pin to a version below 4.0.0 or use dynamic `import()` for ESM-only packages.
Update `@types/mdast` to the latest compatible version (`npm install @types/mdast@latest`).
Review and update your TypeScript configurations and type usage to align with the type definitions introduced in v3.
Ensure all mdast nodes passed to assertion functions have a `type` property, for example: `{ type: 'root', children: [] }`.Correct the node structure. Parent nodes should have a `children` array property, while `Literal` nodes have a `value` property.
This package is ESM-only since v4. Migrate your code to use `import` statements (e.g., `import { assert } from 'mdast-util-assert';`) and ensure your project is configured for ESM.