{"id":13716632,"url":"https://github.com/syntax-tree/unist-util-assert","last_synced_at":"2025-07-12T07:38:05.689Z","repository":{"id":9879522,"uuid":"63640998","full_name":"syntax-tree/unist-util-assert","owner":"syntax-tree","description":"utility to assert nodes","archived":false,"fork":false,"pushed_at":"2023-07-07T10:04:12.000Z","size":134,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-27T23:04:17.972Z","etag":null,"topics":["assert","check","syntax-tree","test","unist","unist-util","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-07-18T22:18:11.000Z","updated_at":"2024-11-02T04:49:03.000Z","dependencies_parsed_at":"2024-01-14T22:03:35.359Z","dependency_job_id":"e42d2e76-794f-405e-9f80-d14b83c784fc","html_url":"https://github.com/syntax-tree/unist-util-assert","commit_stats":{"total_commits":78,"total_committers":2,"mean_commits":39.0,"dds":0.02564102564102566,"last_synced_commit":"4c74f03f685e964ba57c2ac1973b4b646557f6ae"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/unist-util-assert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/unist-util-assert/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-assert/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263672378,"owners_count":23494171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assert","check","syntax-tree","test","unist","unist-util","util"],"created_at":"2024-08-03T00:01:12.737Z","updated_at":"2025-07-12T07:38:05.414Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# unist-util-assert\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[unist][] utility to assert trees.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`assert(tree[, parent])`](#asserttree-parent)\n    *   [`parent(tree[, parent])`](#parenttree-parent)\n    *   [`literal(node[, parent])`](#literalnode-parent)\n    *   [`_void(node[, parent])`](#_voidnode-parent)\n    *   [`wrap(fn)`](#wrapfn)\n    *   [`AssertionError`](#assertionerror)\n*   [Extensions](#extensions)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a tiny utility that helps you deal with nodes.\n\n## When should I use this?\n\nThis utility is typically useful when you expect certain nodes in your APIs\nand want to make sure they’re valid and as expected.\n\nDifferent utilities, [`mdast-util-assert`][mdast-util-assert],\n[`hast-util-assert`][hast-util-assert], and [`nlcst-test`][nlcst-test],\ndo the same but for mdast, hast, and nlcst nodes, respectively.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install unist-util-assert\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {assert} from 'https://esm.sh/unist-util-assert@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {assert} from 'https://esm.sh/unist-util-assert@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {_void, assert, parent} from 'unist-util-assert'\n\nassert({type: 'root', children: []})\nassert({type: 'break'})\nassert({type: 'element', properties: {}, children: []})\n// All OK.\n\nassert({children: []})\n// AssertionError: node should have a type: `{ children: [] }`\n\nparent({type: 'break'})\n// AssertionError: parent should have `children`: `{ type: 'break' }`\n\nassert({type: 'element', properties: function() {}})\n// AssertionError: non-specced property `properties` should be JSON: `{ type: 'element', properties: [Function] }`\n\n_void({type: 'text', value: 'Alpha'})\n// AssertionError: void should not have `value`: `{ type: 'text', value: 'Alpha' }`\n\nassert({type: 'paragraph', children: ['foo']})\n// AssertionError: node should be an object: `'foo'` in `{ type: 'paragraph', children: [ 'foo' ] }`\n```\n\n## API\n\nThis package exports the identifiers [`_void`][void], [`assert`][assert],\n[`literal`][literal], [`parent`][parent], and [`wrap`][wrap].\nThere is no default export.\n\n### `assert(tree[, parent])`\n\nAssert that `tree` is a valid unist [`Node`][node].\n\nIf `tree` is a parent, all children will be asserted too.\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent-node], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `tree` (or its descendants) is not a node.\n\n### `parent(tree[, parent])`\n\nAssert that `tree` is a valid unist [`Parent`][parent-node].\n\nAll children will be asserted too.\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent-node], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `tree` is not a parent or its descendants are not nodes.\n\n### `literal(node[, parent])`\n\nAssert that `node` is a valid unist [`Literal`][literal-node].\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent-node], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `node` is not a literal.\n\n### `_void(node[, parent])`\n\nAssert that `node` is a valid void node.\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent-node], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `node` is not a node, a parent, or a literal.\n\n### `wrap(fn)`\n\nWrapper that adds the current node (and parent, if available) to error\nmessages.\n\n###### Parameters\n\n*   `fn` (`(node?: any, parent?: Parent | null | undefined) =\u003e asserts node is Node)`)\n    — custom assertion\n\n###### Returns\n\nWrapped `fn`.\n\n### `AssertionError`\n\nAssertion error from `node:assert` (TypeScript type).\n\n###### Type\n\n```ts\ntype AssertionError = import('node:assert').AssertionError\n```\n\n## Extensions\n\nThis module can be used as a base to test subsets of unist (for an example, see\n[`mdast-util-assert`][mdast-util-assert]).\nAll functions that are exposed from such a module, and functions used internally\nto test children, should be wrapped in `wrap`, which adds an inspectable string\nof the respective node, and its parent when available, to the exposed error\nmessage.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`AssertionError`][assertionerror].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `unist-util-assert@^4`,\ncompatible with Node.js 16.\n\n## Related\n\n*   [`mdast-util-assert`][mdast-util-assert]\n    — assert mdast nodes\n*   [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert)\n    — assert hast nodes\n*   [`nlcst-test`](https://github.com/syntax-tree/nlcst-test)\n    — assert nlcst nodes\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/unist-util-assert/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-assert/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-assert.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-assert\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-assert.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-assert\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=unist-util-assert\n\n[size]: https://bundlejs.com/?q=unist-util-assert\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[unist]: https://github.com/syntax-tree/unist\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[parent-node]: https://github.com/syntax-tree/unist#parent\n\n[literal-node]: https://github.com/syntax-tree/unist#literal\n\n[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert\n\n[hast-util-assert]: https://github.com/syntax-tree/hast-util-assert\n\n[nlcst-test]: https://github.com/syntax-tree/nlcst-test\n\n[assert]: #asserttree-parent\n\n[parent]: #parenttree-parent\n\n[literal]: #literalnode-parent\n\n[void]: #_voidnode-parent\n\n[wrap]: #wrapfn\n\n[assertionerror]: #assertionerror\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["unist utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Funist-util-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-assert/lists"}