You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.js
+33-15Lines changed: 33 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,50 @@
4
4
*
5
5
* @typedef {import('unist-util-is').Type} Type
6
6
* @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.
7
16
*/
8
17
9
18
/**
10
-
* Check if a node passes a test
19
+
* Check if a node passes a test.
11
20
*
12
-
* @template {Node} Tree Node type that is checked.
21
+
* @template {Node} Tree
22
+
* Node type that is checked for.
13
23
* @callback TestFunction
14
24
* @param {Tree} node
15
25
* @param {number|null|undefined} [index]
16
26
* @param {Parent|null|undefined} [parent]
17
27
* @returns {boolean|void}
18
28
*/
19
29
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
-
25
30
import{convert}from'unist-util-is'
26
31
27
-
/** @type {Array<Node>} */
32
+
/** @type {Array<unknown>} */
28
33
constempty=[]
29
34
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
+
*/
30
51
exportconstremove=
31
52
/**
32
53
* @type {(
@@ -36,18 +57,15 @@ export const remove =
36
57
*/
37
58
(
38
59
/**
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)
0 commit comments