Skip to content

Commit b898080

Browse files
committed
Refactor readme.md
1 parent 67ca812 commit b898080

File tree

2 files changed

+58
-36
lines changed

2 files changed

+58
-36
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@
3030
"unist-util-is": "^2.0.0"
3131
},
3232
"devDependencies": {
33+
"remark-cli": "^5.0.0",
34+
"remark-preset-wooorm": "^4.0.0",
3335
"tape": "^4.4.0",
3436
"unist-builder": "^1.0.0"
3537
},
3638
"scripts": {
39+
"format": "remark . -qfo",
3740
"test": "tape test/*.js",
3841
"cov": "nyc --reporter lcov tape test/*.js"
42+
},
43+
"remarkConfig": {
44+
"plugins": [
45+
"preset-wooorm"
46+
]
3947
}
4048
}

readme.md

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
[![npm](https://nodei.co/npm/unist-util-remove.png)](https://npmjs.com/package/unist-util-remove)
1+
# unist-util-remove [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
22

3-
# unist-util-remove
3+
Modify the given [unist][] tree to remove all nodes that pass the given test.
44

5-
[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]
6-
7-
Remove one or more nodes from [Unist] tree, mutating it.
8-
9-
[unist]: https://github.com/wooorm/unist
10-
[is]: https://github.com/syntax-tree/unist-util-is#api
5+
## Install
116

12-
[travis]: https://travis-ci.org/eush77/unist-util-remove
13-
[travis-badge]: https://travis-ci.org/eush77/unist-util-remove.svg?branch=master
14-
[david]: https://david-dm.org/eush77/unist-util-remove
15-
[david-badge]: https://david-dm.org/eush77/unist-util-remove.png
7+
```sh
8+
npm install unist-util-remove
9+
```
1610

17-
## Example
11+
## Usage
1812

1913
```js
2014
var u = require('unist-builder');
@@ -45,39 +39,59 @@ remove(ast, 'leaf')
4539
// └─ other: "4"
4640
```
4741

48-
If the root node gets removed, the entire tree is destroyed and `remove` returns `null`. That's the only case in which `remove` doesn't return the original root node.
49-
50-
```js
51-
remove(ast, ast)
52-
//=> null
53-
```
54-
5542
## API
5643

57-
### `remove(ast, [opts], predicate)`
44+
### `remove(tree, [opts], test)`
5845

59-
- `ast`[Unist] tree.
60-
- `predicate` — any `test` as given to [`unist-util-is`][is].
46+
Mutate `tree` to remove all nodes that pass `test`.
47+
The tree is filtered in [preorder][].
6148

62-
Iterates over `ast` in preorder traversal and removes all nodes matching `predicate` from `ast`. Returns a modified [Unist] tree.
49+
###### Parameters
6350

64-
> Note: `unist-util-is` used to remove a node when given as `test`.
65-
> This no longer works. To migrate, pass a function as a predicate, like so:
66-
> `remove(ast, function (node) { return node === predicate; })`.
51+
* `tree` ([`Node?`][node])
52+
— Tree to filter
53+
* `opts.cascade` (`boolean`, default: `true`)
54+
— Whether to drop parent nodes if they had children, but all their
55+
children were filtered out
56+
* `test`
57+
— See [`unist-util-is`][is] for details
6758

68-
##### `opts.cascade`
59+
###### Returns
6960

70-
Type: `Boolean`<br>
71-
Default: `true`
61+
The given `tree` ([`Node?`][node]) with nodes for which `test` returned `true`
62+
removed. `null` is returned if `tree` itself didn’t pass the test, or is
63+
cascaded away.
7264

73-
If `true`, removing of the last child triggers removal of its parent node.
65+
## Contribute
7466

75-
## Install
67+
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
68+
started.
7669

77-
```
78-
npm install unist-util-remove
79-
```
70+
This organisation has a [Code of Conduct][coc]. By interacting with this
71+
repository, organisation, or community you agree to abide by its terms.
8072

8173
## License
8274

83-
MIT
75+
[MIT][] © Eugene Sharygin
76+
77+
[mit]: LICENSE
78+
79+
[unist]: https://github.com/syntax-tree/unist
80+
81+
[node]: https://github.com/syntax-tree/unist#node
82+
83+
[is]: https://github.com/syntax-tree/unist-util-is
84+
85+
[preorder]: https://en.wikipedia.org/wiki/Tree_traversal
86+
87+
[build-page]: https://travis-ci.org/syntax-tree/unist-util-remove
88+
89+
[build-badge]: https://travis-ci.org/syntax-tree/unist-util-remove.svg?branch=master
90+
91+
[coverage-page]: https://codecov.io/github/syntax-tree/unist-util-remove?branch=master
92+
93+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-remove.svg?branch=master
94+
95+
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
96+
97+
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md

0 commit comments

Comments
 (0)