5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
6
[ ![ Size] [ size-badge ]] [ size ]
7
7
8
- [ ** Unist ** ] [ unist ] utility to find a node before another node.
8
+ [ ** unist ** ] [ unist ] utility to find a node before another node.
9
9
10
- ## Installation
10
+ ## Install
11
11
12
12
[ npm] [ ] :
13
13
14
- ``` bash
14
+ ``` sh
15
15
npm install unist-util-find-before
16
16
```
17
17
18
18
## Usage
19
19
20
20
``` js
21
- var remark = require (' remark ' )
21
+ var u = require (' unist-builder ' )
22
22
var findBefore = require (' unist-util-find-before' )
23
23
24
- var tree = remark ().parse (' Some _emphasis_, **importance**, and `code`.' )
25
- var paragraph = tree .children [0 ]
26
- var code = paragraph .children [paragraph .children .length - 1 ]
24
+ var tree = u (' tree' , [
25
+ u (' leaf' , ' leaf 1' ),
26
+ u (' node' , [u (' leaf' , ' leaf 2' ), u (' leaf' , ' leaf 3' )]),
27
+ u (' leaf' , ' leaf 4' ),
28
+ u (' node' , [u (' leaf' , ' leaf 5' )]),
29
+ u (' leaf' , ' leaf 6' ),
30
+ u (' void' ),
31
+ u (' leaf' , ' leaf 7' )
32
+ ])
27
33
28
- console .log (findBefore (paragraph, code, ' emphasis' ))
34
+ var empty = tree .children [5 ]
35
+
36
+ console .log (findBefore (tree, empty, ' node' ))
29
37
```
30
38
31
39
Yields:
32
40
33
41
``` js
34
- { type: ' emphasis' ,
35
- children: [ { type: ' text' , value: ' emphasis' } ] }
42
+ { type: ' node' , children: [ { type: ' leaf' , value: ' leaf 5' } ] }
36
43
```
37
44
38
45
## API
39
46
40
47
### ` findBefore(parent, node|index[, test]) `
41
48
42
- Find the first child before ` index ` (or ` node ` ) in ` parent ` , that passes ` test `
43
- (when given) .
49
+ Find the first [ child] [ ] before ` index ` (or ` node ` ) in ` parent ` , that passes
50
+ ` test ` .
44
51
45
52
###### Parameters
46
53
47
- * ` parent ` ([ ` Node ` ] [ node ] ) — Context node
48
- * ` node ` ([ ` Node ` ] [ node ] ) — Node in ` parent `
49
- * ` index ` (` number ` , optional) — Position of a ` node ` in ` parent `
50
- * ` test ` (` Function ` , ` string ` , or ` Node ` , optional)
54
+ * ` parent ` ([ ` Node ` ] [ node ] ) — [ Parent ] [ ] node
55
+ * ` node ` ([ ` Node ` ] [ node ] ) — [ Child ] [ ] of ` parent `
56
+ * ` index ` (` number ` , optional) — [ Index ] [ ] in ` parent `
57
+ * ` test ` (` Function ` , ` string ` , ` Object ` , ` Array ` , optional)
51
58
— See [ ` unist-util-is ` ] [ is ]
52
59
53
60
###### Returns
54
61
55
- [ ` Node? ` ] [ node ] — Child node of ` parent ` passing ` test ` .
62
+ [ ` Node? ` ] [ node ] — [ Child] [ ] of ` parent ` passing ` test ` .
56
63
57
64
## Related
58
65
@@ -69,11 +76,13 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
69
76
70
77
## Contribute
71
78
72
- See [ ` contributing.md ` in ` syntax-tree/unist ` ] [ contributing ] for ways to get
79
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
73
80
started.
81
+ See [ ` support.md ` ] [ support ] for ways to get help.
74
82
75
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
76
- repository, organisation, or community you agree to abide by its terms.
83
+ This project has a [ Code of Conduct] [ coc ] .
84
+ By interacting with this repository, organisation, or community you agree to
85
+ abide by its terms.
77
86
78
87
## License
79
88
@@ -107,8 +116,16 @@ repository, organisation, or community you agree to abide by its terms.
107
116
108
117
[ node ] : https://github.com/syntax-tree/unist#node
109
118
119
+ [ parent ] : https://github.com/syntax-tree/unist#parent-1
120
+
121
+ [ child ] : https://github.com/syntax-tree/unist#child
122
+
123
+ [ index ] : https://github.com/syntax-tree/unist#index
124
+
110
125
[ is ] : https://github.com/syntax-tree/unist-util-is
111
126
112
- [ contributing ] : https://github.com/syntax-tree/unist/blob/master/contributing.md
127
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
128
+
129
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
113
130
114
- [ coc ] : https://github.com/syntax-tree/unist /blob/master/code-of-conduct.md
131
+ [ coc ] : https://github.com/syntax-tree/.github /blob/master/code-of-conduct.md
0 commit comments