File tree Expand file tree Collapse file tree 5 files changed +83
-3
lines changed Expand file tree Collapse file tree 5 files changed +83
-3
lines changed Original file line number Diff line number Diff line change 1515 "author" : " azu <azuciao@gmail.com>" ,
1616 "contributors" : [
1717 " azu <azuciao@gmail.com>" ,
18- " Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
18+ " Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" ,
19+ " Christian Murphy <christian.murphy.42@gmail.com>"
1920 ],
2021 "files" : [
21- " index.js"
22+ " index.js" ,
23+ " types/index.d.ts"
2224 ],
25+ "types" : " types/index.d.ts" ,
2326 "dependencies" : {
27+ "@types/mdast" : " ^3.0.3" ,
2428 "object-assign" : " ^4.0.1"
2529 },
2630 "devDependencies" : {
31+ "dtslint" : " ^0.9.9" ,
2732 "nyc" : " ^14.0.0" ,
2833 "prettier" : " ^1.0.0" ,
2934 "remark-cli" : " ^6.0.0" ,
3035 "remark-preset-wooorm" : " ^5.0.0" ,
3136 "tape" : " ^4.10.1" ,
3237 "unist-builder" : " ^1.0.3" ,
38+ "unist-util-is" : " ^4.0.0" ,
3339 "xo" : " ^0.24.0"
3440 },
3541 "scripts" : {
3642 "format" : " remark . -qfo && prettier --write \" **/*.js\" && xo --fix" ,
3743 "test-api" : " node test" ,
3844 "test-coverage" : " nyc --reporter lcov tape test.js" ,
39- "test" : " npm run format && npm run test-coverage"
45+ "test-types" : " dtslint types" ,
46+ "test" : " npm run format && npm run test-coverage && npm run test-types"
4047 },
4148 "nyc" : {
4249 "check-coverage" : true ,
Original file line number Diff line number Diff line change 1+ // TypeScript Version: 3.5
2+
3+ import { Node } from 'unist'
4+
5+ declare namespace unistUtilMap {
6+ type MapFunction = ( node : Node , index : number | null , parent : Node | null ) => Node
7+ }
8+
9+ /**
10+ * unist utility to create a new tree by mapping all nodes with the given function.
11+ *
12+ * @param tree Tree to map
13+ * @param callback Function that returns a new node
14+ * @returns Node to be used in the new tree.
15+ * Its children are not used: if the original node has children, those are mapped.
16+ */
17+ declare function unistUtilMap ( tree : Node , callback : unistUtilMap . MapFunction ) : Node
18+
19+ export = unistUtilMap
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "lib" : [" es2015" ],
4+ "strict" : true ,
5+ "baseUrl" : " ." ,
6+ "paths" : {
7+ "unist-util-map" : [" index.d.ts" ]
8+ }
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " dtslint/dtslint.json" ,
3+ "rules" : {
4+ "whitespace" : false ,
5+ "semicolon" : false
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ import * as map from 'unist-util-map'
2+ import * as is from 'unist-util-is'
3+ import { Node } from 'unist'
4+ import { Heading , Paragraph } from 'mdast'
5+
6+ // $ExpectType Node
7+ map ( { type : 'root' } , ( node : Node ) => ( { type : node . type + 'test' } ) )
8+ // $ExpectType Node
9+ map ( { type : 'root' } , ( node : Node , index : number | null ) => ( {
10+ type : node . type + 'test'
11+ } ) )
12+ // $ExpectType Node
13+ map (
14+ { type : 'root' } ,
15+ ( node : Node , index : number | null , parent : Node | null ) => ( {
16+ type : node . type + 'test'
17+ } )
18+ )
19+ // $ExpectType Node
20+ map ( { type : 'root' } , ( node : Node ) => {
21+ if ( is < Heading > ( node , 'heading' ) ) {
22+ const depth = node . depth < 5 ? node . depth + 1 : 6
23+ return {
24+ ...node ,
25+ depth
26+ }
27+ }
28+
29+ if ( is < Paragraph > ( node , 'paragraph' ) ) {
30+ return {
31+ type : 'strong' ,
32+ children : node . children
33+ }
34+ }
35+
36+ return node
37+ } )
You can’t perform that action at this time.
0 commit comments