File tree 4 files changed +58
-1
lines changed
4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 1
1
.DS_Store
2
+ * .d.ts
2
3
* .log
3
4
coverage /
4
5
node_modules /
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @typedef {import('xast').Root } Root
3
+ * @typedef {import('xast').Element } Element
4
+ * @typedef {import('xast').RootChildMap } RootChildMap
5
+ * @typedef {RootChildMap[keyof RootChildMap] } Child
6
+ * @typedef {Root|Child } Node
7
+ * @typedef {Root|Element } Parent
8
+ */
9
+
10
+ /**
11
+ * @param {Node } node
12
+ * @returns {string }
13
+ */
1
14
export function toString ( node ) {
2
15
// A root or an element
16
+ // @ts -ignore Looks like a parent.
3
17
if ( 'children' in node ) return all ( node )
18
+ // @ts -ignore Looks like a literal.
4
19
return 'value' in node ? node . value : ''
5
20
}
6
21
22
+ /**
23
+ * @param {Node } node
24
+ * @returns {string }
25
+ */
7
26
function one ( node ) {
8
27
if ( node . type === 'text' ) return node . value
9
28
// Ignore things like comments, instruction, cdata.
29
+ // @ts -ignore Looks like a parent.
10
30
return node . children ? all ( node ) : ''
11
31
}
12
32
33
+ /**
34
+ * @param {Parent } node
35
+ * @returns {string }
36
+ */
13
37
function all ( node ) {
14
38
var children = node . children
15
39
var index = - 1
40
+ /** @type {Array.<string> } */
16
41
var result = [ ]
17
42
18
43
while ( ++ index < children . length ) {
Original file line number Diff line number Diff line change 27
27
"sideEffects" : false ,
28
28
"type" : " module" ,
29
29
"main" : " index.js" ,
30
+ "types" : " index.d.ts" ,
30
31
"files" : [
32
+ " index.d.ts" ,
31
33
" index.js"
32
34
],
35
+ "dependencies" : {
36
+ "@types/xast" : " ^1.0.0"
37
+ },
33
38
"devDependencies" : {
39
+ "@types/tape" : " ^4.0.0" ,
34
40
"c8" : " ^7.0.0" ,
35
41
"prettier" : " ^2.0.0" ,
36
42
"remark-cli" : " ^9.0.0" ,
37
43
"remark-preset-wooorm" : " ^8.0.0" ,
44
+ "rimraf" : " ^3.0.2" ,
38
45
"tape" : " ^5.0.0" ,
46
+ "type-coverage" : " ^2.17.5" ,
47
+ "typescript" : " ^4.2.4" ,
39
48
"unist-builder" : " ^3.0.0" ,
40
49
"xo" : " ^0.39.0"
41
50
},
42
51
"scripts" : {
52
+ "prepack" : " npm run build && npm run format" ,
53
+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
43
54
"format" : " remark . -qfo && prettier . --write --loglevel warn && xo --fix" ,
44
55
"test-api" : " node test.js" ,
45
56
"test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js" ,
46
- "test" : " npm run format && npm run test-coverage"
57
+ "test" : " npm run build && npm run format && npm run test-coverage"
47
58
},
48
59
"prettier" : {
49
60
"tabWidth" : 2 ,
64
75
"plugins" : [
65
76
" preset-wooorm"
66
77
]
78
+ },
79
+ "typeCoverage" : {
80
+ "atLeast" : 100 ,
81
+ "detail" : true ,
82
+ "strict" : true
67
83
}
68
84
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "include" : [" *.js" ],
3
+ "compilerOptions" : {
4
+ "target" : " ES2020" ,
5
+ "lib" : [" ES2020" ],
6
+ "module" : " ES2020" ,
7
+ "moduleResolution" : " node" ,
8
+ "allowJs" : true ,
9
+ "checkJs" : true ,
10
+ "declaration" : true ,
11
+ "emitDeclarationOnly" : true ,
12
+ "allowSyntheticDefaultImports" : true ,
13
+ "skipLibCheck" : true
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments