@@ -13,6 +13,45 @@ Create mutable index mapping property values or computed keys back to [Unist] no
13
13
[ david ] : https://david-dm.org/eush77/unist-util-index
14
14
[ david-badge ] : https://david-dm.org/eush77/unist-util-index.png
15
15
16
+ ## Example
17
+
18
+ Headings by depth:
19
+
20
+ ``` js
21
+ var Index = require (' unist-util-index' ),
22
+ remark = require (' remark' ),
23
+ toString = require (' mdast-util-to-string' );
24
+
25
+ var ast = remark .parse (fs .readFileSync (' README.md' , ' utf8' ));
26
+ var index = Index (ast, ' heading' , ' depth' );
27
+
28
+ index .get (1 ).map (toString)
29
+ // => [ 'unist-util-index' ]
30
+
31
+ index .get (2 ).map (toString)
32
+ // => [ 'Example', 'API', 'Install', 'License' ]
33
+ ```
34
+
35
+ Definitions by identifier:
36
+
37
+ ``` js
38
+ var index = Index (ast, ' definition' , ' identifier' );
39
+
40
+ index .get (' unist' )
41
+ // => [ { type: 'definition',
42
+ identifier: ' unist' ,
43
+ title: null ,
44
+ link: ' https://github.com/wooorm/unist' ,
45
+ position: Position { start: [Object ], end: [Object ], indent: [] } } ]
46
+
47
+ index .get (' travis' )
48
+ // => [ { type: 'definition',
49
+ identifier: ' travis' ,
50
+ title: null ,
51
+ link: ' https://travis-ci.org/eush77/unist-util-index' ,
52
+ position: Position { start: [Object ], end: [Object ], indent: [] } } ]
53
+ ```
54
+
16
55
## API
17
56
18
57
### ` index = Index([ast, [filter]], key) `
0 commit comments