Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

utility to check assert an nlcst node

License

NotificationsYou must be signed in to change notification settings

syntax-tree/nlcst-test

Repository files navigation

BuildCoverageDownloadsSizeSponsorsBackersChat

nlcst utility to assert trees.

Contents

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 APIsand want to make sure they’re valid and as expected.

A different utility,unist-util-assert, does the same butfor anyunist node.

Install

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>

Use

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' }`

API

This package exports the identifiers_void,assert,literal,parent, andwrap.There is no default export.

assert(tree[, parent])

Assert thattree is a valid nlcstNode.

Iftree is a parent, all children will be asserted too.

Supports unknown nlcst nodes.

Parameters
  • tree (unknown)— thing to assert
  • parent (Parent, optional)— optional, valid parent
Returns

Nothing.

Throws

Whentree (or its descendants) is not an nlcst node(AssertionError).

parent(tree[, parent])

Assert thattree is a valid nlcstParent.

All children will be asserted too.

Supports unknown nlcst nodes.

Parameters
  • tree (unknown)— thing to assert
  • parent (Parent, optional)— optional, valid parent
Returns

Nothing.

Throws

Whentree is not a parent or its descendants are not nodes(AssertionError)

literal(node[, parent])

Assert thatnode is a valid nlcstLiteral.

Supports unknown nlcst nodes.

Parameters
  • node (unknown)— thing to assert
  • parent (Parent, optional)— optional, valid parent
Returns

Nothing.

Throws

Whennode is not an nlcst literal (AssertionError).

_void(node[, parent])

Re-exported fromunist-util-assert.

wrap(fn)

Re-exported fromunist-util-assert.

AssertionError

Re-exported fromunist-util-assert.

Types

This package is fully typed withTypeScript.It exports the additional typeAssertionError.

Compatibility

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.

Related

Contribute

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.

License

MIT ©Titus Wormer


[8]ページ先頭

©2009-2025 Movatter.jp