{"id":13717087,"url":"https://github.com/syntax-tree/nlcst-search","last_synced_at":"2025-09-08T15:42:01.621Z","repository":{"id":62354820,"uuid":"49678550","full_name":"syntax-tree/nlcst-search","owner":"syntax-tree","description":"utility to search for patterns in an nlcst tree","archived":false,"fork":false,"pushed_at":"2023-07-17T14:05:08.000Z","size":145,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-28T03:18:37.326Z","etag":null,"topics":["nlcst","nlcst-util","search","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":{"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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2016-01-14T22:09:10.000Z","updated_at":"2024-04-14T09:12:15.000Z","dependencies_parsed_at":"2024-06-18T15:33:03.040Z","dependency_job_id":"0409e24a-6814-42bf-a1f4-dbe3847f3a13","html_url":"https://github.com/syntax-tree/nlcst-search","commit_stats":{"total_commits":115,"total_committers":4,"mean_commits":28.75,"dds":0.02608695652173909,"last_synced_commit":"0f0b0f767586eaabecf7ca3d75e2992f067fe335"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fnlcst-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fnlcst-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fnlcst-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fnlcst-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/nlcst-search/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252826898,"owners_count":21810200,"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":["nlcst","nlcst-util","search","syntax-tree","unist","util"],"created_at":"2024-08-03T00:01:17.767Z","updated_at":"2025-05-07T06:31:53.708Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# nlcst-search\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[nlcst][] utility to search for phrases in a tree.\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    *   [`search(tree, phrases, handler[, options])`](#searchtree-phrases-handler-options)\n    *   [`Handler`](#handler)\n    *   [`Options`](#options)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis utility can search for phrases (words and phrases) in trees.\n\n## When should I use this?\n\nThis package is a tiny utility that helps when you’re searching for words\nand phrases.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install nlcst-search\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {search} from 'https://esm.sh/nlcst-search@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {search} from 'https://esm.sh/nlcst-search@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {search} from 'nlcst-search'\nimport {toString} from 'nlcst-to-string'\n\nconst tree = {\n  type: 'SentenceNode',\n  children: [\n    {\n      type: 'WordNode',\n      children: [\n        {type: 'TextNode', value: 'Don'},\n        {type: 'PunctuationNode', value: '’'},\n        {type: 'TextNode', value: 't'}\n      ]\n    },\n    {type: 'WhiteSpaceNode', value: ' '},\n    {\n      type: 'WordNode',\n      children: [{type: 'TextNode', value: 'do'}]\n    },\n    {type: 'WhiteSpaceNode', value: ' '},\n    {\n      type: 'WordNode',\n      children: [\n        {type: 'TextNode', value: 'Block'},\n        {type: 'PunctuationNode', value: '-'},\n        {type: 'TextNode', value: 'level'}\n      ]\n    }\n  ]\n}\n\nsearch(tree, ['dont'], function(nodes) {\n  console.log(toString(nodes))\n})\n// `Don’t`\n\nsearch(tree, ['do blocklevel'], function(nodes) {\n  console.log(toString(nodes))\n})\n// `do Block-level`\n```\n\n## API\n\nThis package exports the identifier [`search`][api-search].\nThere is no default export.\n\n### `search(tree, phrases, handler[, options])`\n\nSearch for phrases in a tree.\n\nEach phrase is a space-separated list of words, where each word will be\n[normalized][nlcst-normalize] to remove casing, apostrophes, and dashes.\nSpaces in a pattern mean one or more whitespace nodes in the tree.\nInstead of a word with letters, it’s also possible to use a wildcard symbol\n(`*`, an asterisk) which will match any word in a pattern (`alpha * charlie`).\n\n##### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to search\n*   `phrases` (`Array\u003cstring\u003e`)\n    — phrases to search for\n*   `handler` ([`Handler`][api-handler])\n    — handle a match\n*   `options` ([`Options`][api-options])\n    — configuration\n\n###### Returns\n\nNothing (`undefined`).\n\n### `Handler`\n\nHandle a match (TypeScript type).\n\n###### Parameters\n\n*   `nodes` ([`Array\u003cNode\u003e`][node])\n    — match\n*   `index` (`number`)\n    — index of first node of `nodes` in `parent`\n*   `parent` ([`Node`][node])\n    — parent of `nodes`\n*   `phrase` (`string`)\n    — the phrase that matched\n\n###### Returns\n\nNothing (`undefined`).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `allowApostrophes` (`boolean`, default: `false`)\n    — passed to [`nlcst-normalize`][nlcst-normalize]\n*   `allowDashes` (`boolean`, default: `false`)\n    — passed to [`nlcst-normalize`][nlcst-normalize]\n*   `allowLiterals` (`boolean`, default: `false`)\n    — include [literal][] phrases\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Handler`][api-handler] and\n[`Options`][api-options].\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, `nlcst-search@^4`,\ncompatible with Node.js 16.\n\n## Related\n\n*   [`nlcst-normalize`](https://github.com/syntax-tree/nlcst-normalize)\n    — normalize a word for easier comparison\n*   [`nlcst-is-literal`](https://github.com/syntax-tree/nlcst-is-literal)\n    — check whether a node is meant literally\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/nlcst-search/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/nlcst-search/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/nlcst-search.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/nlcst-search\n\n[downloads-badge]: https://img.shields.io/npm/dm/nlcst-search.svg\n\n[downloads]: https://www.npmjs.com/package/nlcst-search\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=nlcst-search\n\n[size]: https://bundlejs.com/?q=nlcst-search\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[nlcst]: https://github.com/syntax-tree/nlcst\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[literal]: https://github.com/syntax-tree/nlcst-is-literal\n\n[nlcst-normalize]: https://github.com/syntax-tree/nlcst-normalize\n\n[api-search]: #searchtree-phrases-handler-options\n\n[api-handler]: #handler\n\n[api-options]: #options\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["nlcst utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fnlcst-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fnlcst-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fnlcst-search/lists"}