- Notifications
You must be signed in to change notification settings - Fork0
utility to check assert an nlcst node
License
syntax-tree/nlcst-test
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
nlcst 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 nlcst-test
In Deno withesm.sh
:
import{assert}from'https://esm.sh/nlcst-test@4'
In browsers withesm.sh
:
<scripttype="module">import{assert}from'https://esm.sh/nlcst-test@4?bundle'</script>
import{assert}from'nlcst-test'assert({type:'RootNode',children:[]})assert({type:'SourceNode',value:'fn()'})assert({type:'WordNode',children:[{type:'TextNode',value:'Hi'}]})// All OK.assert({children:[]})// AssertionError: node should have a type: `{ children: [] }`assert({type:'WordNode',value:'foo'})// AssertionError: parent should have children: `{ type: 'WordNode', value: 'foo' }`
This package exports the identifiers_void
,assert
,literal
,parent
, andwrap
.There is no default export.
Assert thattree
is a valid nlcstNode
.
Iftree
is a parent, all children will be asserted too.
Supports unknown nlcst nodes.
tree
(unknown
)— thing to assertparent
(Parent
, optional)— optional, valid parent
Nothing.
Whentree
(or its descendants) is not an nlcst node(AssertionError
).
Assert thattree
is a valid nlcstParent
.
All children will be asserted too.
Supports unknown nlcst 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 nlcstLiteral
.
Supports unknown nlcst nodes.
node
(unknown
)— thing to assertparent
(Parent
, optional)— optional, valid parent
Nothing.
Whennode
is not an nlcst 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,nlcst-test@^4
,compatible with Node.js 16.
unist-util-assert
— assert unist treesmdast-util-assert
— assert mdast treeshast-util-assert
— assert hast trees
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 check assert an nlcst node