1818* [ Use] ( #use )
1919* [ API] ( #api )
2020 * [ ` filter(tree[, options][, test]) ` ] ( #filtertree-options-test )
21+ * [ ` Options ` ] ( #options )
2122* [ Types] ( #types )
2223* [ Compatibility] ( #compatibility )
2324* [ Related] ( #related )
@@ -42,7 +43,7 @@ To create trees, use [`unist-builder`][unist-builder].
4243## Install
4344
4445This 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] [ ] :
4647
4748``` sh
4849npm install unist-util-filter
@@ -51,14 +52,14 @@ npm install unist-util-filter
5152In Deno with [ ` esm.sh ` ] [ esmsh ] :
5253
5354``` js
54- import {filter } from " https://esm.sh/unist-util-filter@4"
55+ import {filter } from ' https://esm.sh/unist-util-filter@4'
5556```
5657
5758In browsers with [ ` esm.sh ` ] [ esmsh ] :
5859
5960``` html
6061<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'
6263 </script >
6364```
6465
@@ -93,40 +94,51 @@ Yields:
9394
9495## API
9596
96- This package exports the identifier ` filter ` .
97+ This package exports the identifier [ ` filter ` ] [ filter ] .
9798There is no default export.
9899
99100### ` filter(tree[, options][, test]) `
100101
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 ` .
107103
108- Configuration (optional).
104+ The tree is walked in * [ preorder] [ ] * (NLR), visiting the node itself, then its
105+ head, etc.
109106
110- ###### ` options.cascade `
107+ ###### Parameters
111108
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
114115
115116###### Returns
116117
117- New filtered tree ([ ` Node? ` ] [ node ] ).
118+ New filtered tree ([ ` Node ` ] [ node ] or ` null ` ).
119+
118120` null ` is returned if ` tree ` itself didn’t pass the test, or is cascaded away.
119121
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+
120132## Types
121133
122134This package is fully typed with [ TypeScript] [ ] .
123- It exports the additional type ` Options ` .
135+ It exports the additional type [ ` Options ` ] [ options ] .
124136
125137## Compatibility
126138
127139Projects maintained by the unified collective are compatible with all maintained
128140versions 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+.
130142Our projects sometimes work with older versions, but this is not guaranteed.
131143
132144## Related
@@ -217,3 +229,7 @@ abide by its terms.
217229[ unist-builder ] : https://github.com/syntax-tree/unist-builder
218230
219231[ test ] : https://github.com/syntax-tree/unist-util-is#test
232+
233+ [ filter ] : #filtertree-options-test
234+
235+ [ options ] : #options
0 commit comments