{"name":"unist-util-find","version":"2.0.0","description":"unist utility to find a node","license":"MIT","keywords":["find","hast","mdast","nlcst","node","rehype","remark","retext","search","unist","unist-util","util","utility"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/unist-util-find.git"},"bugs":{"url":"https://github.com/syntax-tree/unist-util-find/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Richard Smith-Unna","email":"rik@fathomlabs.io"},"contributors":[{"name":"Richard Smith-Unna","email":"rik@fathomlabs.io"},{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","exports":"./index.js","dependencies":{"@types/unist":"^2.0.0","lodash.iteratee":"^4.0.0","unist-util-visit":"^4.0.0"},"devDependencies":{"@types/lodash.iteratee":"^4.0.0","@types/tape":"^5.0.0","c8":"^8.0.0","mdast-util-from-markdown":"^1.0.0","prettier":"^2.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.54.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test.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,"ignoreCatch":true,"strict":true},"xo":{"prettier":true},"types":"./index.d.ts","gitHead":"bd42f831d33d9e5d18e34eec119adae2760d2365","homepage":"https://github.com/syntax-tree/unist-util-find#readme","_id":"unist-util-find@2.0.0","_nodeVersion":"20.0.0","_npmVersion":"9.6.4","dist":{"integrity":"sha512-I4NH8M2r7B9pGNXl41fftwCCi/WhG50RUdZDYcpEmiQEgHUYtfWpcCX4/R6s4XtK0ztxUSwC6u9sztlnDQAoaA==","shasum":"143403ad4b221a2a35b324760e858ad5c54fc675","tarball":"http://registry-npm.ywwl.com/unist-util-find/download/unist-util-find-2.0.0.tgz","fileCount":5,"unpackedSize":11865,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEiUA0nB6C9KXAKweoJc8t5GOP8p/i+XwUmE6TVFpl9gIgFQraYjh8UnGXSEsUKX3VkJH8Eh0/w/dQJsgsj11eN58="}],"size":4335,"noattachment":false,"key":"/unist-util-find/-/unist-util-find-2.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"blahah","email":"rik@fathomlabs.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unist-util-find_2.0.0_1688201361307_0.4601989453523174"},"_hasShrinkwrap":false,"readme":"# unist-util-find\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 find a node.\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    *   [`find(tree, condition)`](#findtree-condition)\n    *   [`TestFn`](#testfn)\n    *   [`TestObj`](#testobj)\n    *   [`TestStr`](#teststr)\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 utility that takes any [unist][] (whether mdast, hast, etc)\nnode and returns the first node that matches a given condition.\n\n## When should I use this?\n\nThis utility is the simplest way to find a single node in a tree.\n\nFor much more powerful tree walking, see [`unist-util-visit`][visit].\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-find\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {find} from 'https://esm.sh/unist-util-find@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {find} from 'https://esm.sh/unist-util-find@3?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {find} from 'unist-util-find'\n\nconst tree = fromMarkdown('Some _emphasis_, **strongness**, and `code`.')\n\n// String condition:\nconsole.log(find(tree, 'value'))\n\n// Object condition:\nconsole.log(find(tree, {value: 'emphasis'}))\n\n// Function condition:\nconsole.log(\n  find(tree, function (node) {\n    return node.type === 'inlineCode'\n  })\n)\n```\n\nYields:\n\n```js\n// string condition: 'value'\n{\n  type: 'text',\n  value: 'Some ',\n  position: {\n    start: { line: 1, column: 1, offset: 0 },\n    end: { line: 1, column: 6, offset: 5 }\n  }\n}\n\n// object condition: { value: 'emphasis' }\n{\n  type: 'text',\n  value: 'emphasis',\n  position: {\n    start: { line: 1, column: 7, offset: 6 },\n    end: { line: 1, column: 15, offset: 14 }\n  }\n}\n\n// function condition: function (node) { return node.type === 'inlineCode' }\n{\n  type: 'inlineCode',\n  value: 'code',\n  position: {\n    start: { line: 1, column: 38, offset: 37 },\n    end: { line: 1, column: 44, offset: 43 }\n  }\n}\n```\n\n## API\n\nThis package exports the identifier [`find`][api-find].\nThere is no default export.\n\n### `find(tree, condition)`\n\nFind a node in `tree` matching `condition`.\n\n###### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to search in\n*   `condition` ([`TestFn`][api-test-fn], [`TestObj`][api-test-obj], or\n    [`TestStr`][api-test-str])\n    — condition used to test each node\n\n###### Returns\n\nThe first node ([`Node`][node]) that matches condition, or `undefined` if no\nnode matches\n\n### `TestFn`\n\nFind the first node for which function returns `true` when passed node as\nargument (TypeScript type).\n\n###### Parameters\n\n*   `node` ([`Node`][node])\n    — node to check\n\n###### Returns\n\nWhether `node` matches your condition (`boolean`).\n\n### `TestObj`\n\nFind the first node that has matching values for all properties of object\n(TypeScript type).\n\n###### Type\n\n```ts\ntype TestObj = Record<string, unknown>;\n```\n\n### `TestStr`\n\nFind the first node with a truthy property matching `string` (TypeScript type).\n\n###### Type\n\n```ts\ntype TestStr = string;\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`TestFn`][api-test-fn],\n[`TestObj`][api-test-obj], and [`TestStr`][api-test-str].\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-find@^3`,\ncompatible with Node.js 16.\n\n## Security\n\nThis project is safe.\n\n## Related\n\n*   [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)\n    — visit nodes\n\n## Contribute\n\nSee [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get\nstarted.\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] © [Richard Smith-Unna][author]\n\n<!-- Definition -->\n\n[build-badge]: https://github.com/syntax-tree/unist-util-find/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-find/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-find.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-find\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-find.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-find\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-find\n\n[size]: https://bundlejs.com/?q=unist-util-find\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[license]: license\n\n[author]: https://twitter.com/blahah404\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\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[visit]: https://github.com/syntax-tree/unist-util-visit\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[api-find]: #findtree-condition\n\n[api-test-fn]: #testfn\n\n[api-test-obj]: #testobj\n\n[api-test-str]: #teststr\n","publish_time":1688201361459,"_cnpm_publish_time":1688201361459,"dist-tags":{"latest":"3.0.0"}}