Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

utility to search for patterns in an nlcst tree

License

NotificationsYou must be signed in to change notification settings

syntax-tree/nlcst-search

BuildCoverageDownloadsSizeSponsorsBackersChat

nlcst utility to search for phrases in a tree.

Contents

What is this?

This utility can search for phrases (words and phrases) in trees.

When should I use this?

This package is a tiny utility that helps when you’re searching for wordsand phrases.

Install

This package isESM only.In Node.js (version 16+), install withnpm:

npm install nlcst-search

In Deno withesm.sh:

import{search}from'https://esm.sh/nlcst-search@4'

In browsers withesm.sh:

<scripttype="module">import{search}from'https://esm.sh/nlcst-search@4?bundle'</script>

Use

import{search}from'nlcst-search'import{toString}from'nlcst-to-string'consttree={type:'SentenceNode',children:[{type:'WordNode',children:[{type:'TextNode',value:'Don'},{type:'PunctuationNode',value:'’'},{type:'TextNode',value:'t'}]},{type:'WhiteSpaceNode',value:' '},{type:'WordNode',children:[{type:'TextNode',value:'do'}]},{type:'WhiteSpaceNode',value:' '},{type:'WordNode',children:[{type:'TextNode',value:'Block'},{type:'PunctuationNode',value:'-'},{type:'TextNode',value:'level'}]}]}search(tree,['dont'],function(nodes){console.log(toString(nodes))})// `Don’t`search(tree,['do blocklevel'],function(nodes){console.log(toString(nodes))})// `do Block-level`

API

This package exports the identifiersearch.There is no default export.

search(tree, phrases, handler[, options])

Search for phrases in a tree.

Each phrase is a space-separated list of words, where each word will benormalized to remove casing, apostrophes, and dashes.Spaces in a pattern mean one or more whitespace nodes in the tree.Instead of a word with letters, it’s also possible to use a wildcard symbol(*, an asterisk) which will match any word in a pattern (alpha * charlie).

Parameters
  • tree (Node)— tree to search
  • phrases (Array<string>)— phrases to search for
  • handler (Handler)— handle a match
  • options (Options)— configuration
Returns

Nothing (undefined).

Handler

Handle a match (TypeScript type).

Parameters
  • nodes (Array<Node>)— match
  • index (number)— index of first node ofnodes inparent
  • parent (Node)— parent ofnodes
  • phrase (string)— the phrase that matched
Returns

Nothing (undefined).

Options

Configuration (TypeScript type).

Fields
  • allowApostrophes (boolean, default:false)— passed tonlcst-normalize
  • allowDashes (boolean, default:false)— passed tonlcst-normalize
  • allowLiterals (boolean, default:false)— includeliteral phrases

Types

This package is fully typed withTypeScript.It exports the additional typesHandler andOptions.

Compatibility

Projects maintained by the unified collective are compatible with maintainedversions of Node.js.

When we cut a new major release, we drop support for unmaintained versions ofNode.This means we try to keep the current release line,nlcst-search@^4,compatible with Node.js 16.

Related

Contribute

Seecontributing.md insyntax-tree/.github forways to get started.Seesupport.md for ways to get help.

This project has acode of conduct.By interacting with this repository, organization, or community you agree toabide by its terms.

License

MIT ©Titus Wormer

About

utility to search for patterns in an nlcst tree

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp