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 assert mdast trees

License

NotificationsYou must be signed in to change notification settings

syntax-tree/mdast-util-assert

Repository files navigation

BuildCoverageDownloadsSizeSponsorsBackersChat

mdast 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 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>

Use

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

API

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

assert(tree[, parent])

Assert thattree is a valid mdastNode.

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

Supports unknown mdast nodes.

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

Nothing.

Throws

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

parent(tree[, parent])

Assert thattree is a valid mdastParent.

All children will be asserted too.

Supports unknown mdast 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 mdastLiteral.

Supports unknown mdast nodes.

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

Nothing.

Throws

Whennode is not an mdast 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,mdast-util-assert@^5,compatible with Node.js 16.

Security

Use ofmdast-util-assert does not involvehast so there are noopenings forcross-site scripting (XSS) attacks.

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