8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- Create mutable index mapping property values or computed keys back to
12
- [ ** unist ** ] [ unist ] nodes.
11
+ [ ** unist ** ] [ unist ] utility to create a mutable index mapping property values or
12
+ computed keys back to nodes.
13
13
14
- ## Installation
14
+ ## Install
15
15
16
16
[ npm] [ ] :
17
17
18
- ``` bash
18
+ ``` sh
19
19
npm install unist-util-index
20
20
```
21
21
22
22
## Usage
23
23
24
- ``` javascript
24
+ ``` js
25
25
var fs = require (' fs' )
26
26
var remark = require (' remark' )
27
27
var toString = require (' mdast-util-to-string' )
@@ -33,50 +33,42 @@ var tree = remark.parse(fs.readFileSync('readme.md'))
33
33
// Index on heading depth:
34
34
var index = new Index (tree, ' heading' , ' depth' )
35
35
36
- console .log (index .get (1 ).map (toString))
37
36
console .log (index .get (2 ).map (toString))
38
37
39
38
// Index on definition identifier:
40
39
index = new Index (tree, ' definition' , ' identifier' )
41
40
42
41
console .log (index .get (' unist' ).map (node => node .url ))
43
- console .log (index .get (' travis' ).map (node => node .url ))
44
42
```
45
43
46
44
Yields:
47
45
48
46
``` js
49
- [ ' unist-util-index Build Status Coverage Status' ]
50
- [ ' Installation' ,
51
- ' Usage' ,
52
- ' API' ,
53
- ' Related' ,
54
- ' Contribute' ,
55
- ' License' ]
47
+ [ ' Install' , ' Usage' , ' API' , ' Related' , ' Contribute' , ' License' ]
56
48
[ ' https://github.com/syntax-tree/unist' ]
57
- [ ' https://travis-ci.org/syntax-tree/unist-util-index' ]
58
49
```
59
50
60
51
## API
61
52
62
- ### ` Index([tree, [filter, ] ]prop|keyFn) `
53
+ ### ` Index([tree[, test], ]prop|keyFn) `
63
54
64
55
Create an index data structure that maps keys (calculated by ` keyFn ` function
65
56
or the values at ` prop ` in each node) to a list of nodes.
66
57
67
58
If ` tree ` is given, the index is initialised with all nodes, optionally
68
- filtered by ` filter ` .
59
+ filtered by ` test ` .
69
60
70
61
###### Signatures
71
62
72
63
* ` Index(prop|keyFn) `
73
64
* ` Index(tree, prop|keyFn) `
74
- * ` Index(tree, filter , prop|keyFn) `
65
+ * ` Index(tree, test , prop|keyFn) `
75
66
76
67
###### Parameters
77
68
78
- * ` tree ` ([ ` Node ` ] [ node ] )
79
- * ` filter ` (` * ` ) — [ ` is ` ] [ is ] -compatible test
69
+ * ` tree ` ([ ` Node? ` ] [ node ] ) — [ Tree] [ ] to index
70
+ * ` test ` ([ ` Test ` ] [ is ] , optional) — [ ` is ` ] [ is ] -compatible test (such as a
71
+ [ type] [ ] )
80
72
* ` prop ` (` string ` ) — Property to look up in each node to find keys
81
73
* ` keyFn ` ([ ` Function ` ] [ keyfn ] ) — Function called with each node to calculate
82
74
keys
@@ -87,7 +79,7 @@ filtered by `filter`.
87
79
88
80
#### ` function keyFn(node) `
89
81
90
- Function called with every added [ node] [ ] to return the value to index on.
82
+ Function called with every added [ node] [ ] to return the key to index on.
91
83
92
84
#### ` Index#get(key) `
93
85
@@ -117,11 +109,13 @@ Remove [`node`][node] from the index (if present).
117
109
118
110
## Contribute
119
111
120
- See [ ` contributing.md ` in ` syntax-tree/unist ` ] [ contributing ] for ways to get
112
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
121
113
started.
114
+ See [ ` support.md ` ] [ support ] for ways to get help.
122
115
123
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
124
- repository, organisation, or community you agree to abide by its terms.
116
+ This project has a [ Code of Conduct] [ coc ] .
117
+ By interacting with this repository, organisation, or community you agree to
118
+ abide by its terms.
125
119
126
120
## License
127
121
@@ -159,14 +153,20 @@ repository, organisation, or community you agree to abide by its terms.
159
153
160
154
[ license ] : license
161
155
162
- [ contributing ] : https://github.com/syntax-tree/unist/blob/master/contributing.md
156
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
157
+
158
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
163
159
164
- [ coc ] : https://github.com/syntax-tree/unist /blob/master/code-of-conduct.md
160
+ [ coc ] : https://github.com/syntax-tree/.github /blob/master/code-of-conduct.md
165
161
166
162
[ unist ] : https://github.com/syntax-tree/unist
167
163
168
164
[ node ] : https://github.com/syntax-tree/unist#node
169
165
166
+ [ tree ] : https://github.com/syntax-tree/unist#tree
167
+
168
+ [ type ] : https://github.com/syntax-tree/unist#type
169
+
170
170
[ is ] : https://github.com/syntax-tree/unist-util-is
171
171
172
172
[ keyfn ] : #function-keyfnnode
0 commit comments