{"id":13339481,"url":"https://github.com/syntax-tree/unist-util-find","last_synced_at":"2025-06-29T22:03:40.365Z","repository":{"id":9497526,"uuid":"62315006","full_name":"syntax-tree/unist-util-find","owner":"syntax-tree","description":"utility to find a node","archived":false,"fork":false,"pushed_at":"2025-02-04T14:59:55.000Z","size":278,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-27T16:58:38.794Z","etag":null,"topics":["find","syntax-tree","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":{"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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2016-06-30T14:00:38.000Z","updated_at":"2025-06-03T11:34:21.000Z","dependencies_parsed_at":"2023-10-15T03:43:14.955Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/unist-util-find","commit_stats":null,"previous_names":["syntax-tree/unist-util-find","blahah/unist-find","blahah/unist-util-find"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/unist-util-find","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-find","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-find/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-find/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-find/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/unist-util-find/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-find/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262674946,"owners_count":23346741,"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":["find","syntax-tree","unist","unist-util","util"],"created_at":"2024-07-29T19:20:03.865Z","updated_at":"2025-06-29T22:03:40.335Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","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\u003cscript type=\"module\"\u003e\n  import {find} from 'https://esm.sh/unist-util-find@3?bundle'\n\u003c/script\u003e\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\u003cstring, unknown\u003e;\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\n\n\u003c!-- Definition --\u003e\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\u0026query=$.size.compressedSize\u0026url=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[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","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-find","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Funist-util-find","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-find/lists"}