Skip to content

Commit 3a428cb

Browse files
committed
Refactor docs
1 parent d64e951 commit 3a428cb

File tree

1 file changed

+46
-55
lines changed

1 file changed

+46
-55
lines changed

Diff for: readme.md

+46-55
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,76 @@
1-
# unist-util-find-before [![Build Status](https://img.shields.io/travis/wooorm/unist-util-find-before.svg)](https://travis-ci.org/wooorm/unist-util-find-before) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/unist-util-find-before.svg)](https://codecov.io/github/wooorm/unist-util-find-before?branch=master)
1+
# unist-util-find-before [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
22

3-
[**Unist**](https://github.com/wooorm/unist) utility to find a node 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 a node 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-before
1311
```
1412

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

2315
```js
24-
var mdast = require('mdast');
16+
var remark = require('remark');
2517
var findBefore = require('unist-util-find-before');
26-
var inspect = require('unist-util-inspect');
27-
28-
function log(node) {
29-
console.log(node && inspect(node));
30-
}
31-
32-
mdast.use(function () {
33-
return function (ast) {
34-
var paragraph = ast.children[0];
35-
var children = paragraph.children;
36-
37-
log(findBefore(paragraph, 4));
38-
log(findBefore(paragraph, children[4]));
39-
log(findBefore(paragraph, children[4], 'emphasis'));
40-
log(findBefore(paragraph, children[4], children[5]));
41-
log(findBefore(paragraph, children[4], function (node, n) {
42-
return n === 1;
43-
}));
44-
};
45-
}).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(findBefore(paragraph, code, 'emphasis'));
4624
```
4725

4826
Yields:
4927

50-
```text
51-
strong[1]
52-
└─ text: 'strongness'
53-
strong[1]
54-
└─ text: 'strongness'
55-
emphasis[1]
56-
└─ text: 'emphasis'
57-
null
58-
emphasis[1]
59-
└─ text: 'emphasis'
28+
```js
29+
{ type: 'emphasis',
30+
children: [ { type: 'text', value: 'emphasis' } ] }
6031
```
6132

6233
## API
6334

64-
### findBefore(parent, index|node\[, test\])
35+
### `findBefore(parent, node|index[, test])`
6536

66-
Find the first child before `index` (or `node`), that passes `test` (when
67-
given).
37+
Find the first child before `index` (or `node`) in `parent`, that passes `test`
38+
(when given).
6839

69-
**Parameters**:
40+
###### Parameters
7041

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

73-
* `node` (`Node`)
74-
[Node](https://github.com/wooorm/unist#unist-nodes) to search before;
48+
###### Returns
7549

76-
* `index` (`number`) — Position of child to search before;
50+
[`Node?`][node] — Child node of `parent` passing `test`.
7751

78-
* `test` (`Function`, `string`, or `Node`; optional)
79-
— See [`is()`](https://github.com/wooorm/unist-util-is#istest-node-index-parent-context).
52+
## License
8053

81-
**Returns**: `node?`, when found. Child node of `parent` which passes `test`.
54+
[MIT][license] © [Titus Wormer][author]
8255

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

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

0 commit comments

Comments
 (0)