File tree 8 files changed +50
-42
lines changed
8 files changed +50
-42
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
- // Get the text content of a node.
2
- // Prefer the node’s plain-text fields, otherwise serialize its children,
3
- // and if the given value is an array, serialize the nodes in it.
1
+ /**
2
+ * Get the text content of a node.
3
+ * Prefer the node’s plain-text fields, otherwise serialize its children,
4
+ * and if the given value is an array, serialize the nodes in it.
5
+ *
6
+ * @param {unknown } node
7
+ * @returns {string }
8
+ */
4
9
export function toString ( node ) {
5
10
return (
6
11
( node &&
12
+ typeof node === 'object' &&
13
+ // @ts -ignore looks like a literal.
7
14
( node . value ||
15
+ // @ts -ignore looks like an image.
8
16
node . alt ||
17
+ // @ts -ignore looks like an image/link.
9
18
node . title ||
19
+ // @ts -ignore looks like a parent.
10
20
( 'children' in node && all ( node . children ) ) ||
11
- ( 'length' in node && all ( node ) ) ) ) ||
21
+ ( Array . isArray ( node ) && all ( node ) ) ) ) ||
12
22
''
13
23
)
14
24
}
15
25
26
+ /**
27
+ * @param {Array.<unknown> } values
28
+ * @returns {string }
29
+ */
16
30
function all ( values ) {
31
+ /** @type {Array.<string> } */
17
32
var result = [ ]
18
33
var index = - 1
19
34
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" : " types/ index.d.ts" ,
30
+ "types" : " index.d.ts" ,
31
31
"files" : [
32
- " types/ index.d.ts" ,
32
+ " index.d.ts" ,
33
33
" index.js"
34
34
],
35
35
"devDependencies" : {
36
+ "@types/tape" : " ^4.0.0" ,
36
37
"c8" : " ^7.0.0" ,
37
38
"prettier" : " ^2.0.0" ,
38
39
"remark-cli" : " ^9.0.0" ,
39
40
"remark-preset-wooorm" : " ^8.0.0" ,
41
+ "rimraf" : " ^3.0.0" ,
40
42
"tape" : " ^5.0.0" ,
43
+ "type-coverage" : " ^2.0.0" ,
44
+ "typescript" : " ^4.0.0" ,
41
45
"xo" : " ^0.39.0"
42
46
},
43
47
"scripts" : {
48
+ "prepack" : " npm run build && npm run format" ,
49
+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
44
50
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
45
51
"test-api" : " node test.js" ,
46
52
"test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js" ,
47
- "test" : " npm run format && npm run test-coverage"
53
+ "test" : " npm run build && npm run format && npm run test-coverage"
48
54
},
49
55
"prettier" : {
50
56
"tabWidth" : 2 ,
59
65
"rules" : {
60
66
"no-var" : " off" ,
61
67
"prefer-arrow-callback" : " off"
62
- },
63
- "ignore" : [
64
- " types"
65
- ]
68
+ }
66
69
},
67
70
"remarkConfig" : {
68
71
"plugins" : [
69
72
" preset-wooorm"
70
73
]
74
+ },
75
+ "typeCoverage" : {
76
+ "atLeast" : 100 ,
77
+ "detail" : true ,
78
+ "strict" : true
71
79
}
72
80
}
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
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments