8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** unist** ] [ unist ] utility to find a node after another node.
11
+ [ unist] [ ] utility to find a node after another node.
12
12
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.
14
31
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
17
39
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] [ ] :
19
42
20
43
``` sh
21
44
npm install unist-util-find-after
22
45
```
23
46
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
+
24
61
## Use
25
62
26
63
``` js
@@ -29,75 +66,80 @@ import {findAfter} from 'unist-util-find-after'
29
66
30
67
const tree = u (' tree' , [
31
68
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' )]),
33
70
u (' leaf' , ' leaf 4' ),
34
- u (' node ' , [u (' leaf' , ' leaf 5' )]),
71
+ u (' parent ' , [u (' leaf' , ' leaf 5' )]),
35
72
u (' leaf' , ' leaf 6' ),
36
- u (' void ' ),
73
+ u (' empty ' ),
37
74
u (' leaf' , ' leaf 7' )
38
75
])
39
76
40
- console .log (findAfter (tree, 1 , ' node ' ))
77
+ console .log (findAfter (tree, 1 , ' parent ' ))
41
78
```
42
79
43
80
Yields:
44
81
45
82
``` js
46
- {type: ' node ' , children: [{ type: ' leaf' , value: ' leaf 5' }]}
83
+ {type: ' parent ' , children: [{ type: ' leaf' , value: ' leaf 5' }]}
47
84
```
48
85
49
86
## API
50
87
51
- This package exports the following identifiers: ` findAfter ` .
88
+ This package exports the identifier ` findAfter ` .
52
89
There is no default export.
53
90
54
91
### ` findAfter(parent, node|index[, test]) `
55
92
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 ] ).
58
96
59
- ###### Parameters
97
+ ###### Returns
60
98
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 ] ).
66
100
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
68
107
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.
70
112
71
113
## Related
72
114
73
115
* [ ` unist-util-visit ` ] ( https://github.com/syntax-tree/unist-util-visit )
74
- — Recursively walk over nodes
116
+ — walk the tree
75
117
* [ ` 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
77
119
* [ ` 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
79
121
* [ ` 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
81
123
* [ ` 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
83
125
then flattening
84
126
* [ ` 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
86
128
* [ ` 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
88
130
* [ ` 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
90
132
* [ ` 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
92
134
* [ ` 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
94
136
* [ ` 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
96
138
97
139
## Contribute
98
140
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.
101
143
See [ ` support.md ` ] [ support ] for ways to get help.
102
144
103
145
This project has a [ Code of Conduct] [ coc ] .
@@ -138,24 +180,28 @@ abide by its terms.
138
180
139
181
[ npm ] : https://docs.npmjs.com/cli/install
140
182
183
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
184
+
185
+ [ esmsh ] : https://esm.sh
186
+
187
+ [ typescript ] : https://www.typescriptlang.org
188
+
141
189
[ license ] : license
142
190
143
191
[ author ] : https://wooorm.com
144
192
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
148
194
149
- [ parent ] : https://github.com/syntax-tree/unist#parent-1
195
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
150
196
151
- [ child ] : https://github.com/syntax-tree/unist#child
197
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
152
198
153
- [ index ] : https://github.com/syntax-tree/unist#index
199
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
154
200
155
- [ is ] : https://github.com/syntax-tree/unist-util-is
201
+ [ unist ] : https://github.com/syntax-tree/unist
156
202
157
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
203
+ [ node ] : https://github.com/syntax-tree/unist#node
158
204
159
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
205
+ [ parent ] : https://github.com/syntax-tree/unist#parent-1
160
206
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