{"id":13716745,"url":"https://github.com/syntax-tree/mdast-util-assert","last_synced_at":"2025-06-29T22:03:42.669Z","repository":{"id":57293484,"uuid":"63641610","full_name":"syntax-tree/mdast-util-assert","owner":"syntax-tree","description":"utility to assert mdast trees","archived":false,"fork":false,"pushed_at":"2023-07-08T14:29:28.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-23T14:20:06.917Z","etag":null,"topics":["assert","markdown","mdast","mdast-util","syntax-tree","unist","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:31:29.000Z","updated_at":"2022-12-26T07:33:10.000Z","dependencies_parsed_at":"2024-01-14T22:03:35.862Z","dependency_job_id":"895aafc7-178c-422a-bba0-af46af62fabe","html_url":"https://github.com/syntax-tree/mdast-util-assert","commit_stats":{"total_commits":86,"total_committers":3,"mean_commits":"28.666666666666668","dds":"0.046511627906976716","last_synced_commit":"b5457a33decca574866eb2e05e9495a706a090b0"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/mdast-util-assert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/mdast-util-assert/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-assert/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262026438,"owners_count":23246929,"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","markdown","mdast","mdast-util","syntax-tree","unist","util"],"created_at":"2024-08-03T00:01:13.919Z","updated_at":"2025-06-29T22:03:42.599Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# mdast-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[mdast][] 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*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\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\nA different utility, [`unist-util-assert`][unist-util-assert], does the same but\nfor any [unist][] node.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-assert\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {assert} from 'https://esm.sh/mdast-util-assert@5'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {assert} from 'https://esm.sh/mdast-util-assert@5?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {assert} from 'mdast-util-assert'\n\nassert({type: 'root', children: []})\nassert({type: 'break'})\nassert({type: 'listItem', checked: true, children: []})\n// All OK.\n\nassert({children: []})\n// AssertionError: node should have a type: `{ children: [] }`\n\nassert({type: 'paragraph', value: 'foo'})\n// AssertionError: parent should have children: `{ type: 'paragraph', value: 'foo' }`\n```\n\n## API\n\nThis package exports the identifiers [`_void`][api-void],\n[`assert`][api-assert], [`literal`][api-literal], [`parent`][api-parent],\nand [`wrap`][api-wrap].\nThere is no default export.\n\n### `assert(tree[, parent])`\n\nAssert that `tree` is a valid mdast [`Node`][node].\n\nIf `tree` is a parent, all children will be asserted too.\n\nSupports unknown mdast nodes.\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `tree` (or its descendants) is not an mdast node\n([`AssertionError`][api-assertion-error]).\n\n### `parent(tree[, parent])`\n\nAssert that `tree` is a valid mdast [`Parent`][parent].\n\nAll children will be asserted too.\n\nSupports unknown mdast nodes.\n\n###### Parameters\n\n*   `tree` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent], 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([`AssertionError`][api-assertion-error])\n\n### `literal(node[, parent])`\n\nAssert that `node` is a valid mdast [`Literal`][literal].\n\nSupports unknown mdast nodes.\n\n###### Parameters\n\n*   `node` (`unknown`)\n    — thing to assert\n*   `parent` ([`Parent`][parent], optional)\n    — optional, valid parent\n\n###### Returns\n\nNothing.\n\n###### Throws\n\nWhen `node` is not an mdast literal ([`AssertionError`][api-assertion-error]).\n\n### `_void(node[, parent])`\n\nRe-exported from [`unist-util-assert`][unist-util-assert-void].\n\n### `wrap(fn)`\n\nRe-exported from [`unist-util-assert`][unist-util-assert-wrap].\n\n### `AssertionError`\n\nRe-exported from [`unist-util-assert`][unist-util-assert-assertionerror].\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`AssertionError`][api-assertion-error].\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, `mdast-util-assert@^5`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `mdast-util-assert` does not involve **[hast][]** so there are no\nopenings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`unist-util-assert`][unist-util-assert]\n    — check unist nodes\n*   [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert)\n    — check hast nodes\n*   [`nlcst-test`](https://github.com/syntax-tree/nlcst-test)\n    — check 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/mdast-util-assert/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-assert/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-assert.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-assert\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-assert.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-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=mdast-util-assert\n\n[size]: https://bundlejs.com/?q=mdast-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[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[unist]: https://github.com/syntax-tree/unist\n\n[unist-util-assert]: https://github.com/syntax-tree/unist-util-assert\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[node]: https://github.com/syntax-tree/mdast#nodes\n\n[literal]: https://github.com/syntax-tree/mdast#literal\n\n[parent]: https://github.com/syntax-tree/mdast#parent\n\n[hast]: https://github.com/syntax-tree/hast\n\n[api-void]: #_voidnode-parent\n\n[api-assert]: #asserttree-parent\n\n[api-literal]: #literalnode-parent\n\n[api-parent]: #parenttree-parent\n\n[api-wrap]: #wrapfn\n\n[api-assertion-error]: #assertionerror\n\n[unist-util-assert-void]: https://github.com/syntax-tree/unist-util-assert#_voidnode-parent\n\n[unist-util-assert-wrap]: https://github.com/syntax-tree/unist-util-assert#wrapfn\n\n[unist-util-assert-assertionerror]: https://github.com/syntax-tree/unist-util-assert#assertionerror\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["mdast utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fmdast-util-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-assert/lists"}