Skip to content

Commit b9489a8

Browse files
committed
Refactor prose
1 parent e344af0 commit b9489a8

File tree

1 file changed

+80
-37
lines changed

1 file changed

+80
-37
lines changed

readme.md

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
# unist-util-remove [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
1+
# unist-util-remove
22

3-
Modify the given [unist][] tree to remove all nodes that pass the given test.
3+
[![Build][build-badge]][build]
4+
[![Coverage][coverage-badge]][coverage]
5+
[![Downloads][downloads-badge]][downloads]
6+
[![Size][size-badge]][size]
7+
8+
[**unist**][unist] utility to modify the given tree by removing all nodes that
9+
pass the given test.
410

511
## Install
612

13+
[npm][]:
14+
715
```sh
816
npm install unist-util-remove
917
```
@@ -27,80 +35,115 @@ var tree = u('root', [
2735
// Remove all nodes of type `leaf`.
2836
remove(tree, 'leaf')
2937

30-
console.log(tree)
38+
console.dir(tree, {depth: null})
3139
```
3240

3341
Yields: (note the parent of `5` is also removed, due to `opts.cascade`)
3442

3543
```js
3644
{
3745
type: 'root',
38-
children: [{
39-
type: 'node',
40-
children: [{
46+
children: [
47+
{
4148
type: 'node',
42-
children: [{
43-
type: 'other',
44-
value: '4'
45-
}]
46-
}]
47-
}]
49+
children: [
50+
{ type: 'node', children: [ { type: 'other', value: '4' } ] }
51+
]
52+
}
53+
]
4854
}
4955
```
5056

5157
## API
5258

53-
### `remove(tree, [opts], test)`
59+
### `remove(tree[, options][, test])`
5460

55-
Mutate `tree` by removing all nodes that pass `test`.
56-
The tree is filtered in [preorder][].
61+
Mutate the given [tree][] by removing all nodes that pass `test`.
62+
The tree is walked in [preorder][] (NLR), visiting the node itself, then its
63+
[head][], etc.
5764

5865
###### Parameters
5966

6067
* `tree` ([`Node?`][node])
61-
— Tree to filter
62-
* `opts.cascade` (`boolean`, default: `true`)
63-
— Whether to drop parent nodes if they had children, but all their
64-
children were filtered out
65-
* `test`
66-
— See [`unist-util-is`][is] for details
68+
[Tree][] to filter
69+
* `options.cascade` (`boolean`, default: `true`)
70+
— Whether to drop parent nodes if they had children, but all their children
71+
were filtered out
72+
* `test` ([`Test`][is], optional) — [`is`][is]-compatible test (such as a
73+
[type][])
6774

6875
###### Returns
6976

70-
The given `tree` ([`Node?`][node]) with nodes for which `test` returned `true`
71-
removed. `null` is returned if `tree` itself didn’t pass the test, or is
72-
cascaded away.
77+
[`Node?`][node] — The given `tree` with nodes for which `test` passed removed.
78+
`null` is returned if `tree` itself didn’t pass the test, or is cascaded away.
79+
80+
## Related
81+
82+
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
83+
— Create a new tree with all nodes that pass the given function
84+
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
85+
— Create a new tree by expanding a node into many
86+
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
87+
— Create a new tree by mapping nodes
88+
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
89+
— Select nodes with CSS-like selectors
90+
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
91+
— Recursively walk over nodes
92+
* [`unist-builder`](https://github.com/syntax-tree/unist-builder)
93+
— Creating trees
7394

7495
## Contribute
7596

76-
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
97+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
7798
started.
99+
See [`support.md`][support] for ways to get help.
78100

79-
This organisation has a [Code of Conduct][coc]. By interacting with this
80-
repository, organisation, or community you agree to abide by its terms.
101+
This project has a [Code of Conduct][coc].
102+
By interacting with this repository, organisation, or community you agree to
103+
abide by its terms.
81104

82105
## License
83106

84-
[MIT][] © Eugene Sharygin
107+
[MIT][license] © Eugene Sharygin
108+
109+
<!-- Definitions -->
110+
111+
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-filter.svg
112+
113+
[build]: https://travis-ci.org/syntax-tree/unist-util-filter
114+
115+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-filter.svg
85116

86-
[mit]: license
117+
[coverage]: https://codecov.io/github/syntax-tree/unist-util-filter
118+
119+
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-filter.svg
120+
121+
[downloads]: https://www.npmjs.com/package/unist-util-filter
122+
123+
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-filter.svg
124+
125+
[size]: https://bundlephobia.com/result?p=unist-util-filter
126+
127+
[npm]: https://docs.npmjs.com/cli/install
128+
129+
[license]: license
87130

88131
[unist]: https://github.com/syntax-tree/unist
89132

90133
[node]: https://github.com/syntax-tree/unist#node
91134

92-
[is]: https://github.com/syntax-tree/unist-util-is
135+
[tree]: https://github.com/syntax-tree/unist#tree
93136

94-
[preorder]: https://en.wikipedia.org/wiki/Tree_traversal
137+
[preorder]: https://www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/
95138

96-
[build-page]: https://travis-ci.org/syntax-tree/unist-util-remove
139+
[head]: https://github.com/syntax-tree/unist#head
97140

98-
[build-badge]: https://travis-ci.org/syntax-tree/unist-util-remove.svg?branch=master
141+
[type]: https://github.com/syntax-tree/unist#type
99142

100-
[coverage-page]: https://codecov.io/github/syntax-tree/unist-util-remove?branch=master
143+
[is]: https://github.com/syntax-tree/unist-util-is
101144

102-
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-remove.svg?branch=master
145+
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
103146

104-
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
147+
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
105148

106-
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md
149+
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md

0 commit comments

Comments
 (0)