{"_id":"@cjser/unist-util-is","name":"@cjser/unist-util-is","dist-tags":{"latest":"6.0.1-cjser.2"},"versions":{"6.0.1-cjser.2":{"name":"@cjser/unist-util-is","version":"6.0.1-cjser.2","description":"unist utility to check if a node passes a test","license":"MIT","keywords":["unist","unist-util","util","utility","tree","node","is","equal","check","test","type"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"bugs":{"url":"https://github.com/syntax-tree/unist-util-is/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},{"name":"Christian Murphy","email":"christian.murphy.42@gmail.com"},{"name":"Lucas Brandstaetter","email":"lucas@brandstaetter.tech","url":"https://github.com/Roang-zero1"}],"sideEffects":false,"type":"module","exports":{"require":"./dist-cjser/index.cjs","default":"./index.js"},"dependencies":{"@types/unist":"^3.0.0"},"devDependencies":{"@types/mdast":"^4.0.0","@types/node":"^24.0.0","c8":"^10.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-wooorm":"^11.0.0","tsd":"^0.33.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.58.0"},"scripts":{"build":"tsc --build --clean && tsc --build && tsd && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"#":"needed `any`s","ignoreFiles":["lib/index.d.ts"],"ignoreCatch":true,"strict":true},"xo":{"overrides":[{"files":["**/*.ts"],"rules":{"@typescript-eslint/consistent-type-definitions":"off","@typescript-eslint/no-unnecessary-type-arguments":"off","@typescript-eslint/no-unsafe-argument":"off","@typescript-eslint/no-unsafe-assignment":"off","import/no-extraneous-dependencies":"off"}}],"prettier":true},"main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"6.0.1","cjserVersion":2,"original":{"name":"unist-util-is","version":"6.0.1","exports":"./index.js","repository":"syntax-tree/unist-util-is","dependencies":{"@types/unist":"^3.0.0"},"files":["lib/","index.d.ts.map","index.d.ts","index.js"],"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && tsd && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"}}},"_id":"@cjser/unist-util-is@6.0.1-cjser.2","gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-XIC6tXRnOMgfTmQMPQc5jaNLYyiFkUgNpnuagTKleKjtKOt/DI5MQJusFLYmACzASDMdUKdjMC1BhKaY+45hZw==","shasum":"f7c9b83f977261147cae52651f4157fa2800868e","tarball":"https://registry.npmjs.org/@cjser/unist-util-is/-/unist-util-is-6.0.1-cjser.2.tgz","fileCount":10,"unpackedSize":39290,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIH0p1YDwkGec2q/OOQj1ruvKnOu1nic/t1v0Rv1Y8/GaAiEApgqASnOLrMqgUp4eUR/mTnayParXLL7w5AdyunDddgA="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"directories":{},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/unist-util-is_6.0.1-cjser.2_1778160518755_0.37559442133811105"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T13:28:38.650Z","6.0.1-cjser.2":"2026-05-07T13:28:38.944Z","modified":"2026-05-07T13:28:39.181Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"unist utility to check if a node passes a test","keywords":["unist","unist-util","util","utility","tree","node","is","equal","check","test","type"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},{"name":"Christian Murphy","email":"christian.murphy.42@gmail.com"},{"name":"Lucas Brandstaetter","email":"lucas@brandstaetter.tech","url":"https://github.com/Roang-zero1"}],"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"bugs":{"url":"https://github.com/syntax-tree/unist-util-is/issues"},"license":"MIT","readme":"# unist-util-is\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 check if nodes pass a test.\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  * [`is(node[, test[, index, parent[, context]]])`](#isnode-test-index-parent-context)\n  * [`convert(test)`](#converttest)\n  * [`Check`](#check)\n  * [`Test`](#test)\n  * [`TestFunction`](#testfunction)\n* [Examples](#examples)\n  * [Example of `convert`](#example-of-convert)\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 small utility that checks that a node is a certain node.\n\n## When should I use this?\n\nUse this small utility if you find yourself repeating code for checking what\nnodes are.\n\nA similar package, [`hast-util-is-element`][hast-util-is-element], works on hast\nelements.\n\nFor more advanced tests, [`unist-util-select`][unist-util-select] can be used\nto match against CSS selectors.\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-is\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {is} from 'https://esm.sh/unist-util-is@6'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {is} from 'https://esm.sh/unist-util-is@6?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {is} from 'unist-util-is'\n\nconst node = {type: 'strong'}\nconst parent = {type: 'paragraph', children: [node]}\n\nis() // => false\nis({children: []}) // => false\nis(node) // => true\nis(node, 'strong') // => true\nis(node, 'emphasis') // => false\n\nis(node, node) // => true\nis(parent, {type: 'paragraph'}) // => true\nis(parent, {type: 'strong'}) // => false\n\nis(node, test) // => false\nis(node, test, 4, parent) // => false\nis(node, test, 5, parent) // => true\n\nfunction test(node, n) {\n  return n === 5\n}\n```\n\n## API\n\nThis package exports the identifiers [`convert`][api-convert] and\n[`is`][api-is].\nThere is no default export.\n\n### `is(node[, test[, index, parent[, context]]])`\n\nCheck if `node` is a `Node` and whether it passes the given test.\n\n###### Parameters\n\n* `node` (`unknown`, optional)\n  — thing to check, typically [`Node`][node]\n* `test` ([`Test`][api-test], optional)\n  — a test for a specific element\n* `index` (`number`, optional)\n  — the node’s position in its parent\n* `parent` ([`Node`][node], optional)\n  — the node’s parent\n* `context` (`unknown`, optional)\n  — context object (`this`) to call `test` with\n\n###### Returns\n\nWhether `node` is a [`Node`][node] and passes a test (`boolean`).\n\n###### Throws\n\nWhen an incorrect `test`, `index`, or `parent` is given.\nThere is no error thrown when `node` is not a node.\n\n### `convert(test)`\n\nGenerate a check from a test.\n\nUseful if you’re going to test many nodes, for example when creating a\nutility where something else passes a compatible test.\n\nThe created function is a bit faster because it expects valid input only:\na `node`, `index`, and `parent`.\n\n###### Parameters\n\n* `test` ([`Test`][api-test], optional)\n  — a test for a specific node\n\n###### Returns\n\nA check ([`Check`][api-check]).\n\n### `Check`\n\nCheck that an arbitrary value is a node (TypeScript type).\n\n###### Parameters\n\n* `this` (`unknown`, optional)\n  — context object (`this`) to call `test` with\n* `node` (`unknown`)\n  — anything (typically a node)\n* `index` (`number`, optional)\n  — the node’s position in its parent\n* `parent` ([`Node`][node], optional)\n  — the node’s parent\n\n###### Returns\n\nWhether this is a node and passes a test (`boolean`).\n\n### `Test`\n\nCheck for an arbitrary node (TypeScript type).\n\n###### Type\n\n```ts\ntype Test =\n  | Array<Record<string, unknown> | TestFunction | string>\n  | Record<string, unknown>\n  | TestFunction\n  | string\n  | null\n  | undefined\n```\n\nChecks that the given thing is a node, and then:\n\n* when `string`, checks that the node has that tag name\n* when `function`, see  [`TestFunction`][api-test-function]\n* when `object`, checks that all keys in test are in node, and that they have\n  (strictly) equal values\n* when `Array`, checks if one of the subtests pass\n\n### `TestFunction`\n\nCheck if a node passes a test (TypeScript type).\n\n###### Parameters\n\n* `node` ([`Node`][node])\n  — a node\n* `index` (`number` or `undefined`)\n  — the node’s position in its parent\n* `parent` ([`Node`][node] or `undefined`)\n  — the node’s parent\n\n###### Returns\n\nWhether this node passes the test (`boolean`, optional).\n\n## Examples\n\n### Example of `convert`\n\n```js\nimport {u} from 'unist-builder'\nimport {convert} from 'unist-util-is'\n\nconst test = convert('leaf')\n\nconst tree = u('tree', [\n  u('node', [u('leaf', '1')]),\n  u('leaf', '2'),\n  u('node', [u('leaf', '3'), u('leaf', '4')]),\n  u('leaf', '5')\n])\n\nconst leafs = tree.children.filter(function (child, index) {\n  return test(child, index, tree)\n})\n\nconsole.log(leafs)\n```\n\nYields:\n\n```js\n[{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Check`][api-check],\n[`Test`][api-test],\n[`TestFunction`][api-test-function].\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-is@^6`,\ncompatible with Node.js 16.\n\n## Related\n\n* [`unist-util-find-after`](https://github.com/syntax-tree/unist-util-find-after)\n  — find a node after another node\n* [`unist-util-find-before`](https://github.com/syntax-tree/unist-util-find-before)\n  — find a node before another node\n* [`unist-util-find-all-after`](https://github.com/syntax-tree/unist-util-find-all-after)\n  — find all nodes after another node\n* [`unist-util-find-all-before`](https://github.com/syntax-tree/unist-util-find-all-before)\n  — find all nodes before another node\n* [`unist-util-find-all-between`](https://github.com/mrzmmr/unist-util-find-all-between)\n  — find all nodes between two nodes\n* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)\n  — create a new tree with nodes that pass a check\n* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)\n  — remove nodes from tree\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<!-- Definitions -->\n\n[api-check]: #check\n\n[api-convert]: #converttest\n\n[api-is]: #isnode-test-index-parent-context\n\n[api-test]: #test\n\n[api-test-function]: #testfunction\n\n[author]: https://wooorm.com\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-is/actions\n\n[build-badge]: https://github.com/syntax-tree/unist-util-is/workflows/main/badge.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[collective]: https://opencollective.com/unified\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-is\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-is.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-is\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-is.svg\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[hast-util-is-element]: https://github.com/syntax-tree/hast-util-is-element\n\n[health]: https://github.com/syntax-tree/.github\n\n[license]: license\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[size]: https://bundlejs.com/?q=unist-util-is\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-is\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[typescript]: https://www.typescriptlang.org\n\n[unist]: https://github.com/syntax-tree/unist\n\n[unist-util-select]: https://github.com/syntax-tree/unist-util-select\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/syntax-tree/unist-util-is\n","readmeFilename":"readme.md","_rev":"1-f3390fda999dd543e7675efcd166f492"}