File tree Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Expand file tree Collapse file tree 4 files changed +56
-2
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('unist').Node } Node
3
+ * @typedef {import('unist').Parent } Parent
4
+ *
5
+ * @typedef {import('unist-util-is').Type } Type
6
+ * @typedef {import('unist-util-is').Props } Props
7
+ * @typedef {import('unist-util-is').TestFunctionAnything } TestFunctionAnything
8
+ */
9
+
1
10
import { convert } from 'unist-util-is'
2
11
12
+ /** @type {Array.<Node> } */
13
+ var empty
14
+
15
+ /**
16
+ * @param {Node } node
17
+ * @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything> } [test]
18
+ * @returns {number }
19
+ */
3
20
export function size ( node , test ) {
4
21
var is = convert ( test )
22
+
5
23
return fastSize ( node )
6
24
25
+ /**
26
+ * @param {Node } node
27
+ */
7
28
function fastSize ( node ) {
8
- var children = node && node . children
29
+ /** @type {Array.<Node> } */
30
+ // @ts -ignore Looks like a parent.
31
+ var children = ( node && node . children ) || empty
9
32
var count = 0
10
33
var index = - 1
11
34
12
35
if ( children && children . length > 0 ) {
13
36
while ( ++ index < children . length ) {
37
+ // @ts -ignore Looks like a parent.
14
38
if ( is ( children [ index ] , index , node ) ) count ++
15
39
count += fastSize ( children [ index ] )
16
40
}
Original file line number Diff line number Diff line change 25
25
"sideEffects" : false ,
26
26
"type" : " module" ,
27
27
"main" : " index.js" ,
28
+ "types" : " index.d.ts" ,
28
29
"files" : [
30
+ " index.d.ts" ,
29
31
" index.js"
30
32
],
31
33
"dependencies" : {
34
+ "@types/unist" : " ^2.0.0" ,
32
35
"unist-util-is" : " ^5.0.0"
33
36
},
34
37
"devDependencies" : {
38
+ "@types/tape" : " ^4.0.0" ,
35
39
"c8" : " ^7.0.0" ,
36
40
"hastscript" : " ^6.0.0" ,
37
41
"prettier" : " ^2.0.0" ,
38
42
"remark-cli" : " ^9.0.0" ,
39
43
"remark-preset-wooorm" : " ^8.0.0" ,
44
+ "rimraf" : " ^3.0.0" ,
40
45
"tape" : " ^5.0.0" ,
46
+ "type-coverage" : " ^2.0.0" ,
47
+ "typescript" : " ^4.0.0" ,
41
48
"xo" : " ^0.38.0"
42
49
},
43
50
"scripts" : {
51
+ "prepack" : " npm run build && npm run format" ,
52
+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
44
53
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
45
54
"test-api" : " node test.js" ,
46
55
"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"
56
+ "test" : " npm run build && npm run format && npm run test-coverage"
48
57
},
49
58
"prettier" : {
50
59
"tabWidth" : 2 ,
65
74
"plugins" : [
66
75
" preset-wooorm"
67
76
]
77
+ },
78
+ "typeCoverage" : {
79
+ "atLeast" : 100 ,
80
+ "detail" : true ,
81
+ "strict" : true
68
82
}
69
83
}
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