Skip to content

Commit 4aa6241

Browse files
committed
Refactor docs
1 parent 21f386e commit 4aa6241

File tree

1 file changed

+49
-59
lines changed

1 file changed

+49
-59
lines changed

readme.md

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,77 @@
1-
# unist-util-find-all-before [![Build Status](https://img.shields.io/travis/wooorm/unist-util-find-all-before.svg)](https://travis-ci.org/wooorm/unist-util-find-all-before) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/unist-util-find-all-before.svg)](https://codecov.io/github/wooorm/unist-util-find-all-before?branch=master)
1+
# unist-util-find-all-before [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
22

3-
[**Unist**](https://github.com/wooorm/unist) utility to find nodes before
4-
another node. Useful when working with [**mdast**](https://github.com/wooorm/mdast)
5-
or [**retext**](https://github.com/wooorm/retext).
3+
[**Unist**][unist] utility to find nodes before another node.
64

75
## Installation
86

9-
[npm](https://docs.npmjs.com/cli/install):
7+
[npm][]:
108

119
```bash
1210
npm install unist-util-find-all-before
1311
```
1412

15-
**unist-util-find-all-before** is also available for
16-
[bower](http://bower.io/#install-packages) and [duo](http://duojs.org/#getting-started),
17-
and as an AMD, CommonJS, and globals module, [uncompressed](unist-util-find-all-before.js)
18-
and [compressed](unist-util-find-all-before.min.js).
19-
2013
## Usage
2114

2215
```js
23-
var mdast = require('mdast');
16+
var remark = require('remark');
2417
var findAllBefore = require('unist-util-find-all-before');
25-
var inspect = require('unist-util-inspect');
26-
27-
function log(nodes) {
28-
console.log(nodes && inspect(nodes));
29-
console.log();
30-
}
31-
32-
mdast.use(function () {
33-
return function (ast) {
34-
var paragraph = ast.children[0];
35-
var children = paragraph.children;
36-
37-
log(findAllBefore(paragraph, 4));
38-
log(findAllBefore(paragraph, children[4]));
39-
log(findAllBefore(paragraph, children[4], 'emphasis'));
40-
};
41-
}).process('Some _emphasis_, **strongness**, and `code`.');
18+
19+
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
20+
var paragraph = tree.children[0];
21+
var code = paragraph.children[paragraph.children.length - 1];
22+
23+
console.log(findAllBefore(paragraph, code, 'text'));
4224
```
4325

44-
Yields (note the order of nodes):
45-
46-
```text
47-
strong[1]
48-
└─ text: 'strongness'
49-
text: ', '
50-
emphasis[1]
51-
└─ text: 'emphasis'
52-
text: 'Some '
53-
54-
strong[1]
55-
└─ text: 'strongness'
56-
text: ', '
57-
emphasis[1]
58-
└─ text: 'emphasis'
59-
text: 'Some '
60-
61-
emphasis[1]
62-
└─ text: 'emphasis'
26+
Yields:
27+
28+
```js
29+
[ { type: 'text', value: ', and ' },
30+
{ type: 'text', value: ', ' },
31+
{ type: 'text', value: 'Some ' } ]
6332
```
6433

6534
## API
6635

67-
### findAllBefore(parent, index|node\[, test])
36+
### `findAllBefore(parent, node|index[, test])`
37+
38+
Find the first child before `index` (or `node`) in `parent`, that passes `test`
39+
(when given).
6840

69-
Find the nodes before `index` (or `node`), that pass `test` (when given).
41+
###### Parameters
7042

71-
**Parameters**:
43+
* `parent` ([`Node`][node]) — Context node;
44+
* `node` ([`Node`][node]) — Node in `parent`;
45+
* `index` (`number`, optional) — Position of a `node` in `parent`;
46+
* `test` (`Function`, `string`, or `Node`, optional)
47+
— See [`unist-util-is`][is].
7248

73-
* `parent` (`Node`) — Parent to search in;
49+
###### Returns
7450

75-
* `node` (`Node`)
76-
[Node](https://github.com/wooorm/unist#unist-nodes) to search before;
51+
[`Array.<Node>`][node] — Child nodes of `parent` passing `test`.
7752

78-
* `index` (`number`) — Position of child to search before;
53+
## License
7954

80-
* `test` (`Function`, `string`, or `Node`; optional)
81-
— See [`is()`](https://github.com/wooorm/unist-util-is#istest-node-index-parent-context).
55+
[MIT][license] © [Titus Wormer][author]
8256

83-
**Returns**: `Array.<node>?`. Child nodes of `parent` which pass `test`.
57+
<!-- Definitions -->
8458

85-
## License
59+
[travis-badge]: https://img.shields.io/travis/wooorm/unist-util-find-all-before.svg
60+
61+
[travis]: https://travis-ci.org/wooorm/unist-util-find-all-before
62+
63+
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/unist-util-find-all-before.svg
64+
65+
[codecov]: https://codecov.io/github/wooorm/unist-util-find-all-before
66+
67+
[npm]: https://docs.npmjs.com/cli/install
68+
69+
[license]: LICENSE
70+
71+
[author]: http://wooorm.com
72+
73+
[unist]: https://github.com/wooorm/unist
74+
75+
[node]: https://github.com/wooorm/unist#node
8676

87-
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
77+
[is]: https://github.com/wooorm/unist-util-is

0 commit comments

Comments
 (0)