Skip to content

Commit 1408662

Browse files
committed
Add improved docs
1 parent e2dfd84 commit 1408662

File tree

2 files changed

+91
-45
lines changed

2 files changed

+91
-45
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {convert} from 'unist-util-is'
1212
export const findAfter =
1313
/**
1414
* @type {(
15-
* (<T extends Node>(node: Parent, index: Node|number, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>) => T|null) &
15+
* (<T extends Node>(node: Parent, index: Node|number, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>) => T|null) &
1616
* ((node: Parent, index: Node|number, test?: null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => Node|null)
1717
* )}
1818
*/

readme.md

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,56 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**unist**][unist] utility to find a node after another node.
11+
[unist][] utility to find a node after another node.
1212

13-
## Install
13+
## Contents
14+
15+
* [What is this?](#what-is-this)
16+
* [When should I use this?](#when-should-i-use-this)
17+
* [Install](#install)
18+
* [Use](#use)
19+
* [API](#api)
20+
* [`findAfter(parent, node|index[, test])`](#findafterparent-nodeindex-test)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Related](#related)
24+
* [Contribute](#contribute)
25+
* [License](#license)
26+
27+
## What is this?
28+
29+
This is a tiny utility that you can use to find a node after another node or
30+
after an index in a parent.
1431

15-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16-
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
32+
## When should I use this?
33+
34+
This is super tiny.
35+
You can of course do it yourself.
36+
But this helps when integrating with the rest of unified and unist.
37+
38+
## Install
1739

18-
[npm][]:
40+
This package is [ESM only][esm].
41+
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
1942

2043
```sh
2144
npm install unist-util-find-after
2245
```
2346

47+
In Deno with [`esm.sh`][esmsh]:
48+
49+
```js
50+
import {findAfter} from "https://esm.sh/unist-util-find-after@4"
51+
```
52+
53+
In browsers with [`esm.sh`][esmsh]:
54+
55+
```html
56+
<script type="module">
57+
import {findAfter} from "https://esm.sh/unist-util-find-after@4?bundle"
58+
</script>
59+
```
60+
2461
## Use
2562

2663
```js
@@ -29,75 +66,80 @@ import {findAfter} from 'unist-util-find-after'
2966

3067
const tree = u('tree', [
3168
u('leaf', 'leaf 1'),
32-
u('node', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),
69+
u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),
3370
u('leaf', 'leaf 4'),
34-
u('node', [u('leaf', 'leaf 5')]),
71+
u('parent', [u('leaf', 'leaf 5')]),
3572
u('leaf', 'leaf 6'),
36-
u('void'),
73+
u('empty'),
3774
u('leaf', 'leaf 7')
3875
])
3976

40-
console.log(findAfter(tree, 1, 'node'))
77+
console.log(findAfter(tree, 1, 'parent'))
4178
```
4279

4380
Yields:
4481

4582
```js
46-
{type: 'node', children: [{ type: 'leaf', value: 'leaf 5'}]}
83+
{type: 'parent', children: [{ type: 'leaf', value: 'leaf 5'}]}
4784
```
4885

4986
## API
5087

51-
This package exports the following identifiers: `findAfter`.
88+
This package exports the identifier `findAfter`.
5289
There is no default export.
5390

5491
### `findAfter(parent, node|index[, test])`
5592

56-
Find the first [child][] after `index` (or `node`) in `parent`, that passes
57-
`test`.
93+
Find the first node in `parent` ([`Parent`][parent]) after another `node`
94+
([`Node`][node]) or after an index, that passes `test` (`Test` from
95+
[`unist-util-is`][test]).
5896

59-
###### Parameters
97+
###### Returns
6098

61-
* `parent` ([`Node`][node]) — [Parent][] node
62-
* `node` ([`Node`][node]) — [Child][] of `parent`
63-
* `index` (`number`, optional) — [Index][] in `parent`
64-
* `test` (`Function`, `string`, `Object`, `Array`, optional)
65-
— See [`unist-util-is`][is]
99+
Child of `parent` that passes `test`, if found ([`Node?`][node]).
66100

67-
###### Returns
101+
## Types
102+
103+
This package is fully typed with [TypeScript][].
104+
It exports no additional types (types for the test are in `unist-util-is`).
105+
106+
## Compatibility
68107

69-
[`Node?`][node][Child][] of `parent` passing `test`.
108+
Projects maintained by the unified collective are compatible with all maintained
109+
versions of Node.js.
110+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
111+
Our projects sometimes work with older versions, but this is not guaranteed.
70112

71113
## Related
72114

73115
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
74-
Recursively walk over nodes
116+
— walk the tree
75117
* [`unist-util-visit-parents`](https://github.com/syntax-tree/unist-util-visit-parents)
76-
Like `visit`, but with a stack of parents
118+
walk the tree with a stack of parents
77119
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
78-
Create a new tree with all nodes that pass a test
120+
create a new tree with all nodes that pass a test
79121
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
80-
Create a new tree with all nodes mapped by a given function
122+
create a new tree with all nodes mapped by a given function
81123
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
82-
Create a new tree by mapping (to an array) with the provided function and
124+
create a new tree by mapping (to an array) with the provided function and
83125
then flattening
84126
* [`unist-util-find-before`](https://github.com/syntax-tree/unist-util-find-before)
85-
Find a node before another node
127+
find a node before another node
86128
* [`unist-util-find-all-after`](https://github.com/syntax-tree/unist-util-find-all-after)
87-
Find all nodes after another node
129+
find all nodes after another node
88130
* [`unist-util-find-all-before`](https://github.com/syntax-tree/unist-util-find-all-before)
89-
Find all nodes before another node
131+
find all nodes before another node
90132
* [`unist-util-find-all-between`](https://github.com/mrzmmr/unist-util-find-all-between)
91-
Find all nodes between two nodes
133+
find all nodes between two nodes
92134
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
93-
Remove nodes from a tree that pass a test
135+
remove nodes from a tree that pass a test
94136
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
95-
Select nodes with CSS-like selectors
137+
select nodes with CSS-like selectors
96138

97139
## Contribute
98140

99-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
100-
started.
141+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
142+
ways to get started.
101143
See [`support.md`][support] for ways to get help.
102144

103145
This project has a [Code of Conduct][coc].
@@ -138,24 +180,28 @@ abide by its terms.
138180

139181
[npm]: https://docs.npmjs.com/cli/install
140182

183+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
184+
185+
[esmsh]: https://esm.sh
186+
187+
[typescript]: https://www.typescriptlang.org
188+
141189
[license]: license
142190

143191
[author]: https://wooorm.com
144192

145-
[unist]: https://github.com/syntax-tree/unist
146-
147-
[node]: https://github.com/syntax-tree/unist#node
193+
[health]: https://github.com/syntax-tree/.github
148194

149-
[parent]: https://github.com/syntax-tree/unist#parent-1
195+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
150196

151-
[child]: https://github.com/syntax-tree/unist#child
197+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
152198

153-
[index]: https://github.com/syntax-tree/unist#index
199+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
154200

155-
[is]: https://github.com/syntax-tree/unist-util-is
201+
[unist]: https://github.com/syntax-tree/unist
156202

157-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
203+
[node]: https://github.com/syntax-tree/unist#node
158204

159-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
205+
[parent]: https://github.com/syntax-tree/unist#parent-1
160206

161-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
207+
[test]: https://github.com/syntax-tree/unist-util-is#test

0 commit comments

Comments
 (0)