Skip to content

ChristianMurphy/hast-util-assert

 
 

Repository files navigation

hast-util-assert

Build Coverage Downloads Size Sponsors Backers Chat

hast utility to assert trees.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install hast-util-assert

Use

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

assert({type: 'root', children: []})
assert({type: 'element', tagName: 'a', properties: {}, children: []})
// All OK.

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

assert({type: 'element', properties: {}, children: []})
// AssertionError: `element` should have a `tagName`: `{ type: 'element', properties: {}, children: [] }`

API

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

assert(tree)

Assert that the given tree is a valid hast tree. 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 included.

Security

hast-util-assert does not change the syntax tree so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

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.

License

MIT © Titus Wormer

About

utility to assert hast nodes

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 93.7%
  • TypeScript 6.3%