Skip to content

Commit 15b97a7

Browse files
committed
Add improved docs
1 parent 01aeb1f commit 15b97a7

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

lib/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {convert} from 'unist-util-is'
1616
const empty = []
1717

1818
/**
19-
* Mutate the given `tree` by removing all nodes that pass `test`.
19+
* Change the given `tree` by removing all nodes that pass `test`.
20+
*
2021
* The tree is walked in preorder (NLR), visiting the node itself, then its
2122
* head, etc.
2223
*
@@ -25,13 +26,14 @@ const empty = []
2526
* @param options
2627
* Configuration (optional).
2728
* @param test
28-
* `unist-util-is`-compatible test.
29+
* `unist-util-is` compatible test.
2930
* @returns
3031
* The given `tree` without nodes that pass `test`.
3132
*
3233
* `null` is returned if `tree` itself didn’t pass the test or is cascaded
3334
* away.
3435
*/
36+
// To do: next major: don’t return `tree`.
3537
export const remove =
3638
/**
3739
* @type {(

readme.md

+32-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [Use](#use)
1919
* [API](#api)
2020
* [`remove(tree[, options], test)`](#removetree-options-test)
21+
* [`Options`](#options)
2122
* [Types](#types)
2223
* [Compatibility](#compatibility)
2324
* [Related](#related)
@@ -43,7 +44,7 @@ To create trees, use [`unist-builder`][unist-builder].
4344
## Install
4445

4546
This package is [ESM only][esm].
46-
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
47+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4748

4849
```sh
4950
npm install unist-util-remove
@@ -52,14 +53,14 @@ npm install unist-util-remove
5253
In Deno with [`esm.sh`][esmsh]:
5354

5455
```js
55-
import {remove} from "https://esm.sh/unist-util-remove@3"
56+
import {remove} from 'https://esm.sh/unist-util-remove@3'
5657
```
5758

5859
In browsers with [`esm.sh`][esmsh]:
5960

6061
```html
6162
<script type="module">
62-
import {remove} from "https://esm.sh/unist-util-remove@3?bundle"
63+
import {remove} from 'https://esm.sh/unist-util-remove@3?bundle'
6364
</script>
6465
```
6566

@@ -104,34 +105,45 @@ Yields:
104105
105106
## API
106107

107-
This package exports the identifier `remove`.
108+
This package exports the identifier [`remove`][api-remove].
108109
There is no default export.
109110

110111
### `remove(tree[, options], test)`
111112

112-
Mutate the given `tree` ([`Node`][node]) by removing all nodes that pass `test`
113-
(`Test` from [`unist-util-is`][test]).
114-
The tree is walked in [preorder][] (NLR), visiting the node itself, then its
115-
head, etc.
113+
Change the given `tree` by removing all nodes that pass `test`.
116114

117-
##### `options`
115+
The tree is walked in *[preorder][]* (NLR), visiting the node itself, then its
116+
head, etc.
118117

119-
Configuration (optional).
118+
###### Parameters
120119

121-
###### `options.cascade`
120+
* `tree` ([`Node`][node])
121+
— tree to change
122+
* `options` ([`Options`][api-options], optional)
123+
— configuration
124+
* `test` ([`Test`][test], optional)
125+
`unist-util-is` compatible test
122126

123-
Whether to drop parent nodes if they had children, but all their children were
124-
filtered out (`boolean`, default: `true`).
127+
###### Returns
125128

126-
##### Returns
129+
A changed given `tree`, without nodes that pass `test`.
127130

128-
The given `tree` without nodes that pass `test` ([`Node?`][node]).
129131
`null` is returned if `tree` itself didn’t pass the test or is cascaded away.
130132

133+
### `Options`
134+
135+
Configuration (TypeScript type).
136+
137+
###### Fields
138+
139+
* `cascade` (`boolean`, default: `true`)
140+
— whether to drop parent nodes if they had children, but all their children
141+
were filtered out
142+
131143
## Types
132144

133145
This package is fully typed with [TypeScript][].
134-
It exports no additional types.
146+
It exports the additional type [`Options`][api-options].
135147

136148
## Compatibility
137149

@@ -228,3 +240,7 @@ abide by its terms.
228240
[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit
229241

230242
[unist-builder]: https://github.com/syntax-tree/unist-builder
243+
244+
[api-remove]: #removetree-options-test
245+
246+
[api-options]: #options

0 commit comments

Comments
 (0)