nlcst-search is a utility designed to locate specific word patterns and phrases within Natural Language Concrete Syntax Tree (NLCST) structures. It provides a programmatic way to search text that has been parsed into an NLCST tree, useful for linguistic analysis, linting, or text transformation tasks. The package currently sits at a stable version 4.0.0 and is actively maintained as part of the `unified` collective. Major versions typically signify significant shifts, such as environment compatibility updates (e.g., Node.js versions) or module system changes (e.g., ESM adoption). Key differentiators include its tight integration with the `nlcst` ecosystem, robust pattern matching with normalization options (casing, apostrophes, dashes), and support for wildcards. It ships with full TypeScript type definitions, ensuring a strong developer experience.
npm install nlcst-searchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import `search` and `toString` (from `nlcst-to-string`), define an example NLCST tree, and then use `search` to find single words and multi-word phrases, including patterns with wildcards, logging the matched text.
Upgrade your Node.js environment to version 16 or higher. Alternatively, use an older version of `nlcst-search` if constrained by Node.js version.
Migrate your project to use ES modules (`import ... from '...'`) or dynamically import the package if still primarily using CommonJS (`const { search } = await import('nlcst-search')`).Change `search(tree, phrases, handler, allowApostrophes)` to `search(tree, phrases, handler, {allowApostrophes: boolean})`.Update TypeScript definitions or type annotations from `PhrasesList` to `Array<string>`.
Ensure the `phrases` argument is always an `Array<string>`, where each string represents a phrase to search for.
Ensure your TypeScript configuration is compatible, or update `@types/nlcst` if you are using it explicitly.
Use ES module `import` syntax: `import { search } from 'nlcst-search'`.Ensure you are using named import: `import { search } from 'nlcst-search'`.Pass `allowApostrophes` within the options object: `search(tree, phrases, handler, { allowApostrophes: true })`.