8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** unist** ] [ unist ] utility to find nodes before another node.
11
+ [ unist] [ ] utility to find nodes before 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
+ * [ ` findAllBefore(parent, node|index[, test]) ` ] ( #findallbeforeparent-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 nodes before another node or
30
+ before an index in a parent.
31
+
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.
14
37
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.
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-all-before
22
45
```
23
46
47
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
48
+
49
+ ``` js
50
+ import {findAllBefore } from " https://esm.sh/unist-util-find-all-before@4"
51
+ ```
52
+
53
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
54
+
55
+ ``` html
56
+ <script type =" module" >
57
+ import {findAllBefore } from " https://esm.sh/unist-util-find-all-before@4?bundle"
58
+ </script >
59
+ ```
60
+
24
61
## Use
25
62
26
63
``` js
@@ -29,11 +66,11 @@ import {findAllBefore} from 'unist-util-find-all-before'
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
@@ -46,62 +83,67 @@ Yields:
46
83
47
84
``` js
48
85
[
49
- { type: ' leaf' , value: ' leaf 4 ' },
50
- { type: ' leaf' , value: ' leaf 1 ' }
86
+ { type: ' leaf' , value: ' leaf 1 ' },
87
+ { type: ' leaf' , value: ' leaf 4 ' }
51
88
]
52
89
```
53
90
54
91
## API
55
92
56
- This package exports the following identifiers: ` findAllBefore ` .
93
+ This package exports the identifier ` findAllBefore ` .
57
94
There is no default export.
58
95
59
96
### ` findAllBefore(parent, node|index[, test]) `
60
97
61
- Find the first child before ` index ` (or ` node ` ) in ` parent ` , that passes ` test `
62
- (when given).
98
+ Find the nodes in ` parent ` ([ ` Parent ` ] [ parent ] ) before another ` node `
99
+ ([ ` Node ` ] [ node ] ) or before an index, that pass ` test ` (` Test ` from
100
+ [ ` unist-util-is ` ] [ test ] ).
101
+
102
+ ###### Returns
63
103
64
- ###### Parameters
104
+ Children of ` parent ` that pass ` test ` ( [ ` Array<Node> ` ] [ node ] ).
65
105
66
- * ` parent ` ([ ` Node ` ] [ node ] ) — [ Parent] [ ] node
67
- * ` node ` ([ ` Node ` ] [ node ] ) — [ Child] [ ] of ` parent `
68
- * ` index ` (` number ` , optional) — [ Index] [ ] in ` parent `
69
- * ` test ` (` Function ` , ` string ` , ` Object ` , ` Array ` , optional)
70
- — See [ ` unist-util-is ` ] [ is ]
106
+ ## Types
71
107
72
- ###### Returns
108
+ This package is fully typed with [ TypeScript] [ ] .
109
+ It exports no additional types (types for the test are in ` unist-util-is ` ).
110
+
111
+ ## Compatibility
73
112
74
- [ ` Array.<Node> ` ] [ node ] — [ Child] [ ] ren of ` parent ` passing ` test ` .
113
+ Projects maintained by the unified collective are compatible with all maintained
114
+ versions of Node.js.
115
+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
116
+ Our projects sometimes work with older versions, but this is not guaranteed.
75
117
76
118
## Related
77
119
78
120
* [ ` unist-util-find-after ` ] ( https://github.com/syntax-tree/unist-util-find-after )
79
- — Find a node after another node
121
+ — find a node after another node
80
122
* [ ` unist-util-find-before ` ] ( https://github.com/syntax-tree/unist-util-find-before )
81
- — Find a node before another node
123
+ — find a node before another node
82
124
* [ ` unist-util-find-all-after ` ] ( https://github.com/syntax-tree/unist-util-find-all-after )
83
- — Find all nodes after another node
125
+ — find all nodes after another node
84
126
* [ ` unist-util-find-all-between ` ] ( https://github.com/mrzmmr/unist-util-find-all-between )
85
- — Find all nodes between two nodes
127
+ — find all nodes between two nodes
86
128
* [ ` unist-util-visit ` ] ( https://github.com/syntax-tree/unist-util-visit )
87
- — Recursively walk over nodes
129
+ — walk the tree
88
130
* [ ` unist-util-visit-parents ` ] ( https://github.com/syntax-tree/unist-util-visit-parents )
89
- — Like ` visit ` , but with a stack of parents
131
+ — walk the tree with a stack of parents
90
132
* [ ` unist-util-filter ` ] ( https://github.com/syntax-tree/unist-util-filter )
91
- — Create a new tree with all nodes that pass a test
133
+ — create a new tree with all nodes that pass a test
92
134
* [ ` unist-util-map ` ] ( https://github.com/syntax-tree/unist-util-map )
93
- — Create a new tree with all nodes mapped by a given function
135
+ — create a new tree with all nodes mapped by a given function
94
136
* [ ` unist-util-flatmap ` ] ( https://gitlab.com/staltz/unist-util-flatmap )
95
- — Create a new tree by mapping (to an array) with a given function
137
+ — create a new tree by mapping (to an array) with a given function
96
138
* [ ` unist-util-remove ` ] ( https://github.com/syntax-tree/unist-util-remove )
97
- — Remove nodes from a tree that pass a test
139
+ — remove nodes from a tree that pass a test
98
140
* [ ` unist-util-select ` ] ( https://github.com/syntax-tree/unist-util-select )
99
- — Select nodes with CSS-like selectors
141
+ — select nodes with CSS-like selectors
100
142
101
143
## Contribute
102
144
103
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
104
- started.
145
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
146
+ ways to get started.
105
147
See [ ` support.md ` ] [ support ] for ways to get help.
106
148
107
149
This project has a [ Code of Conduct] [ coc ] .
@@ -142,24 +184,28 @@ abide by its terms.
142
184
143
185
[ npm ] : https://docs.npmjs.com/cli/install
144
186
187
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
188
+
189
+ [ esmsh ] : https://esm.sh
190
+
191
+ [ typescript ] : https://www.typescriptlang.org
192
+
145
193
[ license ] : license
146
194
147
195
[ author ] : https://wooorm.com
148
196
149
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
197
+ [ health ] : https://github.com/syntax-tree/.github
150
198
151
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
199
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
152
200
153
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
201
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
202
+
203
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
154
204
155
205
[ unist ] : https://github.com/syntax-tree/unist
156
206
157
207
[ node ] : https://github.com/syntax-tree/unist#node
158
208
159
209
[ parent ] : https://github.com/syntax-tree/unist#parent-1
160
210
161
- [ child ] : https://github.com/syntax-tree/unist#child
162
-
163
- [ index ] : https://github.com/syntax-tree/unist#index
164
-
165
- [ is ] : https://github.com/syntax-tree/unist-util-is
211
+ [ test ] : https://github.com/syntax-tree/unist-util-is#test
0 commit comments