Skip to content

Commit 24b806a

Browse files
committed
Refactor prose
1 parent 639ba25 commit 24b806a

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

Diff for: readme.md

+41-22
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,44 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**Unist**][unist] utility to find nodes before another node.
11+
[**unist**][unist] utility to find nodes before another node.
1212

13-
## Installation
13+
## Install
1414

1515
[npm][]:
1616

17-
```bash
17+
```sh
1818
npm install unist-util-find-all-before
1919
```
2020

2121
## Usage
2222

2323
```js
24-
var remark = require('remark')
24+
var u = require('unist-builder')
2525
var findAllBefore = require('unist-util-find-all-before')
2626

27-
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.')
28-
var paragraph = tree.children[0]
29-
var code = paragraph.children[paragraph.children.length - 1]
27+
var tree = u('tree', [
28+
u('leaf', 'leaf 1'),
29+
u('node', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),
30+
u('leaf', 'leaf 4'),
31+
u('node', [u('leaf', 'leaf 5')]),
32+
u('leaf', 'leaf 6'),
33+
u('void'),
34+
u('leaf', 'leaf 7')
35+
])
3036

31-
console.log(findAllBefore(paragraph, code, 'text'))
37+
var leaf6 = tree.children[4]
38+
39+
console.log(findAllBefore(tree, leaf6, 'leaf'))
3240
```
3341

3442
Yields:
3543

3644
```js
37-
[ { type: 'text', value: ', and ' },
38-
{ type: 'text', value: ', ' },
39-
{ type: 'text', value: 'Some ' } ]
45+
[
46+
{ type: 'leaf', value: 'leaf 4' },
47+
{ type: 'leaf', value: 'leaf 1' }
48+
]
4049
```
4150

4251
## API
@@ -48,15 +57,15 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
4857

4958
###### Parameters
5059

51-
* `parent` ([`Node`][node]) — Context node
52-
* `node` ([`Node`][node]) — Node in `parent`
53-
* `index` (`number`, optional) — Position of a `node` in `parent`
54-
* `test` (`Function`, `string`, or `Node`, optional)
60+
* `parent` ([`Node`][node]) — [Parent][] node
61+
* `node` ([`Node`][node]) — [Child][] of `parent`
62+
* `index` (`number`, optional) — [Index][] in `parent`
63+
* `test` (`Function`, `string`, `Object`, `Array`, optional)
5564
— See [`unist-util-is`][is]
5665

5766
###### Returns
5867

59-
[`Array.<Node>`][node] — Child nodes of `parent` passing `test`.
68+
[`Array.<Node>`][node][Child][]ren of `parent` passing `test`.
6069

6170
## Related
6271

@@ -73,11 +82,13 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
7382

7483
## Contribute
7584

76-
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
85+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
7786
started.
87+
See [`support.md`][support] for ways to get help.
7888

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.
89+
This project has a [Code of Conduct][coc].
90+
By interacting with this repository, organisation, or community you agree to
91+
abide by its terms.
8192

8293
## License
8394

@@ -117,12 +128,20 @@ repository, organisation, or community you agree to abide by its terms.
117128

118129
[author]: https://wooorm.com
119130

131+
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
132+
133+
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
134+
135+
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
136+
120137
[unist]: https://github.com/syntax-tree/unist
121138

122139
[node]: https://github.com/syntax-tree/unist#node
123140

124-
[is]: https://github.com/syntax-tree/unist-util-is
141+
[parent]: https://github.com/syntax-tree/unist#parent-1
142+
143+
[child]: https://github.com/syntax-tree/unist#child
125144

126-
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
145+
[index]: https://github.com/syntax-tree/unist#index
127146

128-
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md
147+
[is]: https://github.com/syntax-tree/unist-util-is

0 commit comments

Comments
 (0)