Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 28, 2022
1 parent 75e7663 commit 69aeb26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
* @typedef {boolean} AllowApostrophes
* @typedef {NormalizeOptions & {allowLiterals?: boolean}} SearchOptions
*
* @typedef {Array.<string>} PhrasesList
* @typedef {Object.<string, unknown>} PhrasesMap
* @typedef {Array<string>} PhrasesList
* @typedef {Record<string, unknown>} PhrasesMap
*
* @typedef {(nodes: Content[], index: number, parent: Parent, pattern: string) => void} Handler
* @typedef {(nodes: Array<Content>, index: number, parent: Parent, pattern: string) => void} Handler
*/

import {visit} from 'unist-util-visit'
Expand All @@ -29,7 +29,7 @@ const own = {}.hasOwnProperty
* @param {AllowApostrophes|SearchOptions} [options=false]
*/
export function search(tree, phrases, handler, options) {
/** @type {Object.<string, Array.<string>>} */
/** @type {Record<string, Array<string>>} */
const byWord = {'*': []}
let index = -1
/** @type {string} */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.44.0"
"xo": "^0.49.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
Expand Down
20 changes: 8 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ There is no default export.

Search for patterns a [tree][].

##### Throws

`Error` — When not given `node` or `patterns`.

##### Parameters

###### `node`
Expand All @@ -87,10 +83,10 @@ Search for patterns a [tree][].

###### `patterns`

Patterns to search for (`Array.<string>` or `Object`).
Patterns to search for (`Array<string>` or `Record<string, unknown>`).
If an `Object`, uses its keys as patterns.
Each pattern is a space-delimited list of words, where each word is
[normalize][]d to remove casing, apostrophes, and dashes.
Each pattern is a space-separated list of words, where each word is
[normalized][nlcst-normalize] to remove casing, apostrophes, and dashes.
Spaces in a pattern mean zero or more white space nodes in the tree.
Instead of a word, it’s also possible to use a wildcard symbol (`*`, an
asterisk), that matches any word in a pattern (`alpha * charlie`).
Expand All @@ -105,25 +101,25 @@ Treated as `options.allowApostrophes`.

###### `options.allowApostrophes`

Passed to [`nlcst-normalize`][normalize] (`boolean`, default: `false`).
Passed to [`nlcst-normalize`][nlcst-normalize] (`boolean`, default: `false`).

###### `options.allowDashes`

Passed to [`nlcst-normalize`][normalize] (`boolean`, default: `false`).
Passed to [`nlcst-normalize`][nlcst-normalize] (`boolean`, default: `false`).

###### `options.allowLiterals`

Include [literal][] phrases (`boolean`, default: `false`).

## `function handler(nodes, index, parent, pattern)`
### `function handler(nodes, index, parent, pattern)`

Handler invoked when a match is found.

##### Parameters

###### `nodes`

List of [sibling][]s that match `pattern` ([`Array.<Node>`][node]).
List of [sibling][]s that match `pattern` ([`Array<Node>`][node]).

###### `index`

Expand Down Expand Up @@ -204,7 +200,7 @@ abide by its terms.

[literal]: https://github.com/syntax-tree/nlcst-is-literal

[normalize]: https://github.com/syntax-tree/nlcst-normalize
[nlcst-normalize]: https://github.com/syntax-tree/nlcst-normalize

[fn-handler]: #function-handlernodes-index-parent-pattern

Expand Down

0 comments on commit 69aeb26

Please sign in to comment.