18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
20
* [ ` filter(tree[, options][, test]) ` ] ( #filtertree-options-test )
21
+ * [ ` Options ` ] ( #options )
21
22
* [ Types] ( #types )
22
23
* [ Compatibility] ( #compatibility )
23
24
* [ Related] ( #related )
@@ -42,7 +43,7 @@ To create trees, use [`unist-builder`][unist-builder].
42
43
## Install
43
44
44
45
This package is [ ESM only] [ esm ] .
45
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
46
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
46
47
47
48
``` sh
48
49
npm install unist-util-filter
@@ -51,14 +52,14 @@ npm install unist-util-filter
51
52
In Deno with [ ` esm.sh ` ] [ esmsh ] :
52
53
53
54
``` js
54
- import {filter } from " https://esm.sh/unist-util-filter@4"
55
+ import {filter } from ' https://esm.sh/unist-util-filter@4'
55
56
```
56
57
57
58
In browsers with [ ` esm.sh ` ] [ esmsh ] :
58
59
59
60
``` html
60
61
<script type =" module" >
61
- import {filter } from " https://esm.sh/unist-util-filter@4?bundle"
62
+ import {filter } from ' https://esm.sh/unist-util-filter@4?bundle'
62
63
</script >
63
64
```
64
65
@@ -93,40 +94,51 @@ Yields:
93
94
94
95
## API
95
96
96
- This package exports the identifier ` filter ` .
97
+ This package exports the identifier [ ` filter ` ] [ filter ] .
97
98
There is no default export.
98
99
99
100
### ` filter(tree[, options][, test]) `
100
101
101
- Create a new ` tree ` ([ ` Node ` ] [ node ] ) of copies of all nodes that pass ` test ` .
102
- (` Test ` from [ ` unist-util-is ` ] [ test ] ).
103
- The tree is walked in [ preorder] [ ] (NLR), visiting the node itself, then its
104
- head, etc.
105
-
106
- ##### ` options `
102
+ Create a new ` tree ` of copies of all nodes that pass ` test ` .
107
103
108
- Configuration (optional).
104
+ The tree is walked in * [ preorder] [ ] * (NLR), visiting the node itself, then its
105
+ head, etc.
109
106
110
- ###### ` options.cascade `
107
+ ###### Parameters
111
108
112
- Whether to drop parent nodes if they had children, but all their children were
113
- filtered out (` boolean ` , default: ` true ` ).
109
+ * ` tree ` ([ ` Node ` ] [ node ] )
110
+ — tree to filter
111
+ * ` options ` ([ ` Options ` ] [ options ] , optional)
112
+ — configuration
113
+ * ` test ` ([ ` Test ` ] [ test ] , optional)
114
+ — ` unist-util-is ` compatible test
114
115
115
116
###### Returns
116
117
117
- New filtered tree ([ ` Node? ` ] [ node ] ).
118
+ New filtered tree ([ ` Node ` ] [ node ] or ` null ` ).
119
+
118
120
` null ` is returned if ` tree ` itself didn’t pass the test, or is cascaded away.
119
121
122
+ ### ` Options `
123
+
124
+ Configuration (TypeScript type).
125
+
126
+ ###### Fields
127
+
128
+ * ` cascade ` (` boolean ` , default: ` true ` )
129
+ — whether to drop parent nodes if they had children, but all their
130
+ children were filtered out
131
+
120
132
## Types
121
133
122
134
This package is fully typed with [ TypeScript] [ ] .
123
- It exports the additional type ` Options ` .
135
+ It exports the additional type [ ` Options ` ] [ options ] .
124
136
125
137
## Compatibility
126
138
127
139
Projects maintained by the unified collective are compatible with all maintained
128
140
versions of Node.js.
129
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
141
+ As of now, that is Node.js 14.14+ and 16 .0+.
130
142
Our projects sometimes work with older versions, but this is not guaranteed.
131
143
132
144
## Related
@@ -217,3 +229,7 @@ abide by its terms.
217
229
[ unist-builder ] : https://github.com/syntax-tree/unist-builder
218
230
219
231
[ test ] : https://github.com/syntax-tree/unist-util-is#test
232
+
233
+ [ filter ] : #filtertree-options-test
234
+
235
+ [ options ] : #options
0 commit comments