88[ ![ Backers] [ backers-badge ]] [ collective ]
99[ ![ Chat] [ chat-badge ]] [ chat ]
1010
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.
1313
14- ## Installation
14+ ## Install
1515
1616[ npm] [ ] :
1717
18- ``` bash
18+ ``` sh
1919npm install unist-util-index
2020```
2121
2222## Usage
2323
24- ``` javascript
24+ ``` js
2525var fs = require (' fs' )
2626var remark = require (' remark' )
2727var toString = require (' mdast-util-to-string' )
@@ -33,50 +33,42 @@ var tree = remark.parse(fs.readFileSync('readme.md'))
3333// Index on heading depth:
3434var index = new Index (tree, ' heading' , ' depth' )
3535
36- console .log (index .get (1 ).map (toString))
3736console .log (index .get (2 ).map (toString))
3837
3938// Index on definition identifier:
4039index = new Index (tree, ' definition' , ' identifier' )
4140
4241console .log (index .get (' unist' ).map (node => node .url ))
43- console .log (index .get (' travis' ).map (node => node .url ))
4442```
4543
4644Yields:
4745
4846``` 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' ]
5648[ ' https://github.com/syntax-tree/unist' ]
57- [ ' https://travis-ci.org/syntax-tree/unist-util-index' ]
5849```
5950
6051## API
6152
62- ### ` Index([tree, [filter, ] ]prop|keyFn) `
53+ ### ` Index([tree[, test], ]prop|keyFn) `
6354
6455Create an index data structure that maps keys (calculated by ` keyFn ` function
6556or the values at ` prop ` in each node) to a list of nodes.
6657
6758If ` tree ` is given, the index is initialised with all nodes, optionally
68- filtered by ` filter ` .
59+ filtered by ` test ` .
6960
7061###### Signatures
7162
7263* ` Index(prop|keyFn) `
7364* ` Index(tree, prop|keyFn) `
74- * ` Index(tree, filter , prop|keyFn) `
65+ * ` Index(tree, test , prop|keyFn) `
7566
7667###### Parameters
7768
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] [ ] )
8072* ` prop ` (` string ` ) — Property to look up in each node to find keys
8173* ` keyFn ` ([ ` Function ` ] [ keyfn ] ) — Function called with each node to calculate
8274 keys
@@ -87,7 +79,7 @@ filtered by `filter`.
8779
8880#### ` function keyFn(node) `
8981
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.
9183
9284#### ` Index#get(key) `
9385
@@ -117,11 +109,13 @@ Remove [`node`][node] from the index (if present).
117109
118110## Contribute
119111
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
121113started.
114+ See [ ` support.md ` ] [ support ] for ways to get help.
122115
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.
125119
126120## License
127121
@@ -159,14 +153,20 @@ repository, organisation, or community you agree to abide by its terms.
159153
160154[ license ] : license
161155
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
163159
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
165161
166162[ unist ] : https://github.com/syntax-tree/unist
167163
168164[ node ] : https://github.com/syntax-tree/unist#node
169165
166+ [ tree ] : https://github.com/syntax-tree/unist#tree
167+
168+ [ type ] : https://github.com/syntax-tree/unist#type
169+
170170[ is ] : https://github.com/syntax-tree/unist-util-is
171171
172172[ keyfn ] : #function-keyfnnode
0 commit comments