{"name":"unist-util-find","version":"1.0.1","description":"Unist node finder utility. Useful for working with remark, rehype and retext.","repository":{"type":"git","url":"git+https://github.com/blahah/unist-util-find.git"},"main":"index.js","scripts":{"test":"standard && node test.js"},"keywords":["unist","remark","retext","rehype","hast","mdast","nlcst","find","search"],"author":{"name":"Richard Smith-Unna","email":"rik@fathomlabs.io"},"license":"MIT","devDependencies":{"standard":"^7.1.2","tape":"^4.6.0"},"dependencies":{"lodash.iteratee":"^4.5.0","remark":"^5.0.1","unist-util-visit":"^1.1.0"},"gitHead":"42bfcad402ba9ecaf1ac0f37db79b884800aea57","bugs":{"url":"https://github.com/blahah/unist-util-find/issues"},"homepage":"https://github.com/blahah/unist-util-find#readme","_id":"unist-util-find@1.0.1","_shasum":"1062bbb6928c7a97c6adc89b53745d4c46c222a2","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"blahah","email":"rds45@cam.ac.uk"},"maintainers":[{"name":"blahah","email":"rds45@cam.ac.uk"}],"dist":{"shasum":"1062bbb6928c7a97c6adc89b53745d4c46c222a2","tarball":"http://registry-npm.ywwl.com/unist-util-find/download/unist-util-find-1.0.1.tgz","integrity":"sha512-rhh6ITnBZy6vGl2dTO1iXHW/YSrC43AbfqBmsdTKw/LFrfv5kRww7KRIXTPD3lKbbDArp1MUVDuAWu2Q8Y6s4g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChhxFOfzcUVqNfYnBiRk0zCw50L1idCEyjuh1TX34u1AIgBTDosp91N/ENt1ZvnqSgVGjYHKyIXrnUvzzwUKw4dWo="}],"size":3362,"noattachment":false,"key":"/unist-util-find/-/unist-util-find-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/unist-util-find-1.0.1.tgz_1467298322288_0.8231010283343494"},"directories":{},"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":1467298324132,"_cnpm_publish_time":1467298324132,"dist-tags":{"latest":"3.0.0"}}