Skip to content

Commit 1337642

Browse files
committed
Add improved jsdoc
1 parent 65725cb commit 1337642

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

index.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,50 @@
44
*
55
* @typedef {import('unist-util-is').Type} Type
66
* @typedef {import('unist-util-is').Props} Props
7+
*
8+
* @typedef Options
9+
* @property {boolean} [cascade=true]
10+
* Whether to drop parent nodes if they had children, but all their children
11+
* were filtered out.
12+
*
13+
* @typedef {Options} RemoveOptions
14+
* @deprecated
15+
* Use `Options` instead.
716
*/
817

918
/**
10-
* Check if a node passes a test
19+
* Check if a node passes a test.
1120
*
12-
* @template {Node} Tree Node type that is checked.
21+
* @template {Node} Tree
22+
* Node type that is checked for.
1323
* @callback TestFunction
1424
* @param {Tree} node
1525
* @param {number|null|undefined} [index]
1626
* @param {Parent|null|undefined} [parent]
1727
* @returns {boolean|void}
1828
*/
1929

20-
/**
21-
* @typedef RemoveOptions
22-
* @property {boolean} [cascade] Whether to drop parent nodes if they had children, but all their children were filtered out test
23-
*/
24-
2530
import {convert} from 'unist-util-is'
2631

27-
/** @type {Array<Node>} */
32+
/** @type {Array<unknown>} */
2833
const empty = []
2934

35+
/**
36+
* Mutate the given `tree` by removing all nodes that pass `test`.
37+
* The tree is walked in preorder (NLR), visiting the node itself, then its
38+
* head, etc.
39+
*
40+
* @param tree
41+
* Tree to change.
42+
* @param [options]
43+
* Configuration (optional).
44+
* @param [test]
45+
* `unist-util-is`-compatible test.
46+
* @returns
47+
* The given `tree` without nodes that pass `test`.
48+
* `null` is returned if `tree` itself didn’t pass the test or is cascaded
49+
* away.
50+
*/
3051
export const remove =
3152
/**
3253
* @type {(
@@ -36,18 +57,15 @@ export const remove =
3657
*/
3758
(
3859
/**
39-
* Mutate the given tree by removing all nodes that pass `test`.
40-
* The tree is walked in preorder (NLR), visiting the node itself, then its head, etc.
41-
*
42-
* @param {Node} tree Tree to filter
43-
* @param {RemoveOptions} options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is `{cascade: true}`
44-
* @param {Type|Props|TestFunction<Node>|Array<Type|Props|TestFunction<Node>>} test is-compatible test (such as a type)
60+
* @param {Node} tree
61+
* @param {RemoveOptions} [options]
62+
* @param {Type|Props|TestFunction<Node>|Array<Type|Props|TestFunction<Node>>} [test]
4563
* @returns {Node|null}
4664
*/
4765
function (tree, options, test) {
4866
const is = convert(test || options)
4967
const cascade =
50-
options.cascade === undefined || options.cascade === null
68+
!options || options.cascade === undefined || options.cascade === null
5169
? true
5270
: options.cascade
5371

0 commit comments

Comments
 (0)