Skip to content

Commit 9a36afd

Browse files
committed
Refactor code-style
* Add more docs to JSDoc * Add support for `null` in input of API types
1 parent ccb4c43 commit 9a36afd

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
/**
2+
* @typedef {import('./lib/index.js').Options} Options
3+
*/
4+
5+
// To do: next major: remove.
6+
/**
7+
* @typedef {Options} RemoveOptions
8+
*/
9+
110
export {remove} from './lib/index.js'

lib/index.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
/**
22
* @typedef {import('unist').Node} Node
33
* @typedef {import('unist').Parent} Parent
4-
*
5-
* @typedef {string} Type
6-
* @typedef {Record<string, unknown>} Props
4+
* @typedef {import('unist-util-is').Test} Test
75
*
86
* @typedef Options
9-
* @property {boolean} [cascade=true]
7+
* Configuration.
8+
* @property {boolean | null | undefined} [cascade=true]
109
* Whether to drop parent nodes if they had children, but all their children
1110
* were filtered out.
12-
*
13-
* @typedef {Options} RemoveOptions
14-
* @deprecated
15-
* Use `Options` instead.
16-
*/
17-
18-
/**
19-
* Check if a node passes a test.
20-
*
21-
* @template {Node} Tree
22-
* Node type that is checked for.
23-
* @callback TestFunction
24-
* @param {Tree} node
25-
* @param {number|null|undefined} [index]
26-
* @param {Parent|null|undefined} [parent]
27-
* @returns {boolean|void}
2811
*/
2912

3013
import {convert} from 'unist-util-is'
@@ -39,28 +22,29 @@ const empty = []
3922
*
4023
* @param tree
4124
* Tree to change.
42-
* @param [options]
25+
* @param options
4326
* Configuration (optional).
44-
* @param [test]
27+
* @param test
4528
* `unist-util-is`-compatible test.
4629
* @returns
4730
* The given `tree` without nodes that pass `test`.
31+
*
4832
* `null` is returned if `tree` itself didn’t pass the test or is cascaded
4933
* away.
5034
*/
5135
export const remove =
5236
/**
5337
* @type {(
54-
* (<Tree extends Node>(node: Tree, options: RemoveOptions, test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>>) => Tree|null) &
55-
* (<Tree extends Node>(node: Tree, test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>>) => Tree|null)
38+
* (<Tree extends Node>(node: Tree, options: Options, test: Test) => Tree | null) &
39+
* (<Tree extends Node>(node: Tree, test: Test) => Tree | null)
5640
* )}
5741
*/
5842
(
5943
/**
6044
* @param {Node} tree
61-
* @param {RemoveOptions} [options]
62-
* @param {Type|Props|TestFunction<Node>|Array<Type|Props|TestFunction<Node>>} [test]
63-
* @returns {Node|null}
45+
* @param {Options | null | undefined} [options]
46+
* @param {Test | null | undefined} [test]
47+
* @returns {Node | null}
6448
*/
6549
function (tree, options, test) {
6650
const is = convert(test || options)
@@ -76,9 +60,9 @@ export const remove =
7660
* For each composite node, modify its children array in-place.
7761
*
7862
* @param {Node} node
79-
* @param {number|undefined} [index]
80-
* @param {Parent|undefined} [parent]
81-
* @returns {Node|null}
63+
* @param {number | null | undefined} [index]
64+
* @param {Parent | null | undefined} [parent]
65+
* @returns {Node | null}
8266
*/
8367
function preorder(node, index, parent) {
8468
/** @type {Array<Node>} */

0 commit comments

Comments
 (0)