Skip to content

Commit

Permalink
Update @types/nlcst, utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 17, 2023
1 parent e94ccc7 commit 44cf1bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
42 changes: 21 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
/**
* @typedef {import('unist').Parent} UnistParent
* @typedef {import('nlcst').Nodes} Nodes
* @typedef {import('nlcst').Sentence} Sentence
* @typedef {import('nlcst').Root} Root
* @typedef {import('nlcst').Content} Content
* @typedef {import('nlcst').SentenceContent} SentenceContent
* @typedef {import('nlcst-normalize').Options} NormalizeOptions
*/

/**
* @typedef {Root | Content} Node
* @typedef {Extract<Node, UnistParent>} Parent
* @callback Handler
* Handle a match.
* @param {Array<SentenceContent>} nodes
* Match.
* @param {number} index
* Index of first node of `nodes` in `parent`.
* @param {Root | Sentence} parent
* Parent of `nodes`.
* @param {string} phrase
* The phrase that matched.
* @returns {void}
* Nothing.
*
* @typedef {NormalizeOptions & {allowLiterals?: boolean}} Options
* Configuration (optional).
Expand All @@ -24,19 +35,6 @@
*
* @typedef {Record<string, unknown>} PhrasesMap
* Map where the keys are phrases.
*
* @callback Handler
* Handle a match.
* @param {Array<Content>} nodes
* Match.
* @param {number} index
* Index of first node of `nodes` in `parent`.
* @param {Parent} parent
* Parent of `nodes`.
* @param {string} phrase
* The phrase that matched.
* @returns {void}
* Nothing.
*/

import {visit} from 'unist-util-visit'
Expand All @@ -48,7 +46,7 @@ const own = {}.hasOwnProperty
/**
* Search for phrases in a tree.
*
* @param {Node} tree
* @param {Nodes} tree
* Tree to search.
* @param {PhrasesList | PhrasesMap} phrases
* Phrases to search for.
Expand Down Expand Up @@ -96,7 +94,7 @@ export function search(tree, phrases, handler, options) {
visit(tree, 'WordNode', (node, position, parent) => {
if (
!parent ||
position === null ||
position === undefined ||
(!config.allowLiterals && isLiteral(parent, position))
) {
return
Expand Down Expand Up @@ -124,12 +122,14 @@ export function search(tree, phrases, handler, options) {
* Normalized phrase.
* @param {number} position
* Index in `parent`.
* @param {Parent} parent
* @param {Root | Sentence} parent
* Parent node.
* @returns {Array<Content> | void}
* @returns {Array<SentenceContent> | void}
* Match, if found.
*/
function test(phrase, position, parent) {
/** @type {Array<SentenceContent>} */
// @ts-expect-error: content in a root must be of the same content type.
const siblings = parent.children
const start = position
const expressions = phrase.split(' ').slice(1)
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"@types/unist": "^2.0.0",
"nlcst-is-literal": "^2.0.0",
"nlcst-normalize": "^3.0.0",
"unist-util-visit": "^4.0.0"
"@types/nlcst": "^2.0.0",
"nlcst-is-literal": "^3.0.0",
"nlcst-normalize": "^4.0.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
Expand Down

0 comments on commit 44cf1bd

Please sign in to comment.