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 ** ] [ unist ] utility to find nodes before another node.
12
12
13
- ## Installation
13
+ ## Install
14
14
15
15
[ npm] [ ] :
16
16
17
- ``` bash
17
+ ``` sh
18
18
npm install unist-util-find-all-before
19
19
```
20
20
21
21
## Usage
22
22
23
23
``` js
24
- var remark = require (' remark ' )
24
+ var u = require (' unist-builder ' )
25
25
var findAllBefore = require (' unist-util-find-all-before' )
26
26
27
- var tree = remark ().parse (' Some _emphasis_, **importance**, and `code`.' )
28
- var paragraph = tree .children [0 ]
29
- var code = paragraph .children [paragraph .children .length - 1 ]
27
+ var tree = u (' tree' , [
28
+ u (' leaf' , ' leaf 1' ),
29
+ u (' node' , [u (' leaf' , ' leaf 2' ), u (' leaf' , ' leaf 3' )]),
30
+ u (' leaf' , ' leaf 4' ),
31
+ u (' node' , [u (' leaf' , ' leaf 5' )]),
32
+ u (' leaf' , ' leaf 6' ),
33
+ u (' void' ),
34
+ u (' leaf' , ' leaf 7' )
35
+ ])
30
36
31
- console .log (findAllBefore (paragraph, code, ' text' ))
37
+ var leaf6 = tree .children [4 ]
38
+
39
+ console .log (findAllBefore (tree, leaf6, ' leaf' ))
32
40
```
33
41
34
42
Yields:
35
43
36
44
``` js
37
- [ { type: ' text' , value: ' , and ' },
38
- { type: ' text' , value: ' , ' },
39
- { type: ' text' , value: ' Some ' } ]
45
+ [
46
+ { type: ' leaf' , value: ' leaf 4' },
47
+ { type: ' leaf' , value: ' leaf 1' }
48
+ ]
40
49
```
41
50
42
51
## API
@@ -48,15 +57,15 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
48
57
49
58
###### Parameters
50
59
51
- * ` parent ` ([ ` Node ` ] [ node ] ) — Context node
52
- * ` node ` ([ ` Node ` ] [ node ] ) — Node in ` parent `
53
- * ` index ` (` number ` , optional) — Position of a ` node ` in ` parent `
54
- * ` test ` (` Function ` , ` string ` , or ` Node ` , optional)
60
+ * ` parent ` ([ ` Node ` ] [ node ] ) — [ Parent ] [ ] node
61
+ * ` node ` ([ ` Node ` ] [ node ] ) — [ Child ] [ ] of ` parent `
62
+ * ` index ` (` number ` , optional) — [ Index ] [ ] in ` parent `
63
+ * ` test ` (` Function ` , ` string ` , ` Object ` , ` Array ` , optional)
55
64
— See [ ` unist-util-is ` ] [ is ]
56
65
57
66
###### Returns
58
67
59
- [ ` Array.<Node> ` ] [ node ] — Child nodes of ` parent ` passing ` test ` .
68
+ [ ` Array.<Node> ` ] [ node ] — [ Child] [ ] ren of ` parent ` passing ` test ` .
60
69
61
70
## Related
62
71
@@ -73,11 +82,13 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
73
82
74
83
## Contribute
75
84
76
- See [ ` contributing.md ` in ` syntax-tree/unist ` ] [ contributing ] for ways to get
85
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
77
86
started.
87
+ See [ ` support.md ` ] [ support ] for ways to get help.
78
88
79
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
80
- repository, organisation, or community you agree to abide by its terms.
89
+ This project has a [ Code of Conduct] [ coc ] .
90
+ By interacting with this repository, organisation, or community you agree to
91
+ abide by its terms.
81
92
82
93
## License
83
94
@@ -117,12 +128,20 @@ repository, organisation, or community you agree to abide by its terms.
117
128
118
129
[ author ] : https://wooorm.com
119
130
131
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
132
+
133
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
134
+
135
+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
136
+
120
137
[ unist ] : https://github.com/syntax-tree/unist
121
138
122
139
[ node ] : https://github.com/syntax-tree/unist#node
123
140
124
- [ is ] : https://github.com/syntax-tree/unist-util-is
141
+ [ parent ] : https://github.com/syntax-tree/unist#parent-1
142
+
143
+ [ child ] : https://github.com/syntax-tree/unist#child
125
144
126
- [ contributing ] : https://github.com/syntax-tree/unist/blob/master/contributing.md
145
+ [ index ] : https://github.com/syntax-tree/unist#index
127
146
128
- [ coc ] : https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md
147
+ [ is ] : https://github.com/syntax-tree/unist-util-is
0 commit comments