- Notifications
You must be signed in to change notification settings - Fork0
utility to assert mdast trees
License
syntax-tree/mdast-util-assert
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
mdast utility to assert trees.
This package is a tiny utility that helps you deal with nodes.
This utility is typically useful when you expect certain nodes in your APIsand want to make sure they’re valid and as expected.
A different utility,unist-util-assert
, does the same butfor anyunist node.
This package isESM only.In Node.js (version 16+), install withnpm:
npm install mdast-util-assert
In Deno withesm.sh
:
import{assert}from'https://esm.sh/mdast-util-assert@5'
In browsers withesm.sh
:
<scripttype="module">import{assert}from'https://esm.sh/mdast-util-assert@5?bundle'</script>
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_void
,assert
,literal
,parent
,andwrap
.There is no default export.
Assert thattree
is a valid mdastNode
.
Iftree
is a parent, all children will be asserted too.
Supports unknown mdast nodes.
tree
(unknown
)— thing to assertparent
(Parent
, optional)— optional, valid parent
Nothing.
Whentree
(or its descendants) is not an mdast node(AssertionError
).
Assert thattree
is a valid mdastParent
.
All children will be asserted too.
Supports unknown mdast nodes.
tree
(unknown
)— thing to assertparent
(Parent
, optional)— optional, valid parent
Nothing.
Whentree
is not a parent or its descendants are not nodes(AssertionError
)
Assert thatnode
is a valid mdastLiteral
.
Supports unknown mdast nodes.
node
(unknown
)— thing to assertparent
(Parent
, optional)— optional, valid parent
Nothing.
Whennode
is not an mdast literal (AssertionError
).
Re-exported fromunist-util-assert
.
Re-exported fromunist-util-assert
.
Re-exported fromunist-util-assert
.
This package is fully typed withTypeScript.It exports the additional typeAssertionError
.
Projects maintained by the unified collective are compatible with maintainedversions of Node.js.
When we cut a new major release, we drop support for unmaintained versions ofNode.This means we try to keep the current release line,mdast-util-assert@^5
,compatible with Node.js 16.
Use ofmdast-util-assert
does not involvehast so there are noopenings forcross-site scripting (XSS) attacks.
unist-util-assert
— check unist nodeshast-util-assert
— check hast nodesnlcst-test
— check nlcst nodes
Seecontributing.md
insyntax-tree/.github
forways to get started.Seesupport.md
for ways to get help.
This project has acode of conduct.By interacting with this repository, organization, or community you agree toabide by its terms.
About
utility to assert mdast trees