55[ ![ Downloads] [ downloads-badge ]] [ downloads ]
66[ ![ Size] [ size-badge ]] [ size ]
77
8- [ ** Unist ** ] [ unist ] utility to find a node before another node.
8+ [ ** unist ** ] [ unist ] utility to find a node before another node.
99
10- ## Installation
10+ ## Install
1111
1212[ npm] [ ] :
1313
14- ``` bash
14+ ``` sh
1515npm install unist-util-find-before
1616```
1717
1818## Usage
1919
2020``` js
21- var remark = require (' remark ' )
21+ var u = require (' unist-builder ' )
2222var findBefore = require (' unist-util-find-before' )
2323
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+ ])
2733
28- console .log (findBefore (paragraph, code, ' emphasis' ))
34+ var empty = tree .children [5 ]
35+
36+ console .log (findBefore (tree, empty, ' node' ))
2937```
3038
3139Yields:
3240
3341``` js
34- { type: ' emphasis' ,
35- children: [ { type: ' text' , value: ' emphasis' } ] }
42+ { type: ' node' , children: [ { type: ' leaf' , value: ' leaf 5' } ] }
3643```
3744
3845## API
3946
4047### ` findBefore(parent, node|index[, test]) `
4148
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 ` .
4451
4552###### Parameters
4653
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)
5158 — See [ ` unist-util-is ` ] [ is ]
5259
5360###### Returns
5461
55- [ ` Node? ` ] [ node ] — Child node of ` parent ` passing ` test ` .
62+ [ ` Node? ` ] [ node ] — [ Child] [ ] of ` parent ` passing ` test ` .
5663
5764## Related
5865
@@ -69,11 +76,13 @@ Find the first child before `index` (or `node`) in `parent`, that passes `test`
6976
7077## Contribute
7178
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
7380started.
81+ See [ ` support.md ` ] [ support ] for ways to get help.
7482
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.
7786
7887## License
7988
@@ -107,8 +116,16 @@ repository, organisation, or community you agree to abide by its terms.
107116
108117[ node ] : https://github.com/syntax-tree/unist#node
109118
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+
110125[ is ] : https://github.com/syntax-tree/unist-util-is
111126
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
113130
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