Project: syntax-tree/mdast-util-assert

Package: mdast-util-assert@4.0.0

  1. Dependents: 0
  2. mdast utility to assert trees
  1. util 147
  2. utility 143
  3. unist 131
  4. mdast 86
  5. mdast-util 31
  6. check 11
  7. test 6
  8. assert 4


Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to assert trees.


What is this?

This package is a tiny utility that helps you deal with nodes.

When should I use this?

This utility is typically useful when you expect certain nodes in your APIs and want to make sure they’re valid and as expected.

A different utility, unist-util-assert, does the same but for any unist node.


This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install mdast-util-assert

In Deno with esm.sh:

import {assert} from 'https://esm.sh/mdast-util-assert@4'

In browsers with esm.sh:

<script type="module">
  import {assert} from 'https://esm.sh/mdast-util-assert@4?bundle'


import {assert} from 'mdast-util-assert'

assert({type: 'root', children: []})
assert({type: 'break'})
assert({type: 'listItem', checked: true, children: []})
// All OK.

assert({children: []})
// AssertionError: node should have a type: `{ children: [] }`

assert({type: 'paragraph', value: 'foo'})
// AssertionError: parent should have children: `{ type: 'paragraph', value: 'foo' }`


This package exports the identifiers assert, parent, literal, _void, and wrap. There is no default export.


Assert that tree is a valid mdast node. If tree is a parent, all children will be asserted as well.

The parent, literal, _void, and wrap methods from unist-util-assert are also exported.


When node, or one of its children, is not a valid mdast node.




This package is fully typed with TypeScript. It does not export additional types.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.


Use of mdast-util-assert does not involve hast so there are no openings for cross-site scripting (XSS) attacks.


See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer