Skip to content

Commit 3827a63

Browse files
committed
Add usage to readme.md
1 parent 92dc390 commit 3827a63

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

readme.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ npm install unist-util-index
1313

1414
## Usage
1515

16+
```javascript
17+
var fs = require('fs')
18+
var remark = require('remark')
19+
var toString = require('mdast-util-to-string')
20+
var Index = require('unist-util-index')
21+
22+
// Read this readme:
23+
var tree = remark.parse(fs.readFileSync('readme.md'))
24+
25+
// Index on heading depth:
26+
var index = new Index(tree, 'heading', 'depth')
27+
28+
console.log(index.get(1).map(toString))
29+
console.log(index.get(2).map(toString))
30+
31+
index = new Index(tree, 'definition', 'identifier')
32+
33+
console.log(index.get('unist').map(node => node.url))
34+
console.log(index.get('travis').map(node => node.url))
35+
```
36+
37+
Yields:
38+
39+
```js
40+
[ 'unist-util-index Build Status Coverage Status' ]
41+
[ 'Installation',
42+
'Usage',
43+
'API',
44+
'Related',
45+
'Contribute',
46+
'License' ]
47+
[ 'https://github.com/syntax-tree/unist' ]
48+
[ 'https://travis-ci.org/syntax-tree/unist-util-index' ]
49+
```
50+
1651
## API
1752

1853
### `Index([tree[, filter]], prop|keyFn)`

0 commit comments

Comments
 (0)