Skip to content

Commit 5d54f51

Browse files
committed
Refactor example in readme.md
1 parent 4273967 commit 5d54f51

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

readme.md

+31-22
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,48 @@ npm install unist-util-remove
1111
## Usage
1212

1313
```js
14-
var u = require('unist-builder');
15-
var remove = require('unist-util-remove');
16-
var inspect = require('unist-util-inspect');
14+
var u = require('unist-builder')
15+
var remove = require('.')
1716

18-
var ast = u('root', [
19-
u('leaf', 1),
17+
var tree = u('root', [
18+
u('leaf', '1'),
2019
u('node', [
21-
u('leaf', 2),
22-
u('node', [
23-
u('leaf', 3),
24-
u('other', 4)
25-
]),
26-
// this node will be removed as well because of `opts.cascade`.
27-
u('node', [
28-
u('leaf', 5),
29-
])
20+
u('leaf', '2'),
21+
u('node', [u('leaf', '3'), u('other', '4')]),
22+
u('node', [u('leaf', '5')])
3023
]),
31-
u('leaf', 6)
32-
]);
24+
u('leaf', '6')
25+
])
3326

3427
// Remove all nodes of type `leaf`.
35-
remove(ast, 'leaf')
36-
//=> root[1]
37-
// └─ node[1]
38-
// └─ node[1]
39-
// └─ other: "4"
28+
remove(tree, 'leaf')
29+
30+
console.log(tree)
31+
```
32+
33+
Yields: (note the parent of `5` is also removed, due to `opts.cascade`)
34+
35+
```js
36+
{
37+
type: 'root',
38+
children: [{
39+
type: 'node',
40+
children: [{
41+
type: 'node',
42+
children: [{
43+
type: 'other',
44+
value: '4'
45+
}]
46+
}]
47+
}]
48+
}
4049
```
4150

4251
## API
4352

4453
### `remove(tree, [opts], test)`
4554

46-
Mutate `tree` to remove all nodes that pass `test`.
55+
Mutate `tree` by removing all nodes that pass `test`.
4756
The tree is filtered in [preorder][].
4857

4958
###### Parameters

0 commit comments

Comments
 (0)