File tree Expand file tree Collapse file tree 5 files changed +58
-0
lines changed Expand file tree Collapse file tree 5 files changed +58
-0
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('mdast').Heading } Heading
4
+ */
5
+
1
6
import { visit } from 'unist-util-visit'
2
7
3
8
var max = 6
4
9
10
+ /**
11
+ * Make sure that there is only one top-level heading in the document by
12
+ * adjusting headings depths accordingly.
13
+ *
14
+ * @template {Node} T
15
+ * @param {T } tree
16
+ * @returns {T }
17
+ */
5
18
export function normalizeHeadings ( tree ) {
19
+ /** @type {boolean } */
6
20
var multiple
21
+ /** @type {Heading } */
7
22
var first
23
+ /** @type {Heading } */
8
24
var title
9
25
10
26
visit ( tree , 'heading' , infer )
@@ -21,6 +37,9 @@ export function normalizeHeadings(tree) {
21
37
22
38
return tree
23
39
40
+ /**
41
+ * @param {Heading } node
42
+ */
24
43
function infer ( node ) {
25
44
if ( ! first ) {
26
45
first = node
@@ -35,6 +54,9 @@ export function normalizeHeadings(tree) {
35
54
}
36
55
}
37
56
57
+ /**
58
+ * @param {Heading } node
59
+ */
38
60
function increase ( node ) {
39
61
if ( node !== title && node . depth < max ) {
40
62
node . depth ++
Original file line number Diff line number Diff line change 31
31
"sideEffects" : false ,
32
32
"type" : " module" ,
33
33
"main" : " index.js" ,
34
+ "types" : " index.d.ts" ,
34
35
"files" : [
36
+ " index.d.ts" ,
35
37
" index.js"
36
38
],
37
39
"dependencies" : {
40
+ "@types/mdast" : " ^3.0.0" ,
41
+ "@types/unist" : " ^2.0.0" ,
38
42
"unist-util-visit" : " ^3.0.0"
39
43
},
40
44
"devDependencies" : {
45
+ "@types/tape" : " ^4.0.0" ,
41
46
"c8" : " ^7.0.0" ,
42
47
"prettier" : " ^2.0.0" ,
43
48
"remark" : " ^13.0.0" ,
44
49
"remark-cli" : " ^9.0.0" ,
45
50
"remark-preset-wooorm" : " ^8.0.0" ,
51
+ "rimraf" : " ^3.0.0" ,
46
52
"tape" : " ^5.0.0" ,
53
+ "type-coverage" : " ^2.0.0" ,
54
+ "typescript" : " ^4.0.0" ,
47
55
"unist-util-remove-position" : " ^4.0.0" ,
48
56
"xo" : " ^0.39.0"
49
57
},
50
58
"scripts" : {
59
+ "prepack" : " npm run build && npm run format" ,
60
+ "build" : " rimraf \" {test/**,}*.d.ts\" && tsc && type-coverage" ,
51
61
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
52
62
"test-api" : " node test/index.js" ,
53
63
"test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js" ,
72
82
"plugins" : [
73
83
" preset-wooorm"
74
84
]
85
+ },
86
+ "typeCoverage" : {
87
+ "atLeast" : 100 ,
88
+ "detail" : true ,
89
+ "strict" : true
75
90
}
76
91
}
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ test('Level 7', function (t) {
19
19
t . end ( )
20
20
} )
21
21
22
+ /**
23
+ * @param {import('tape').Test } t
24
+ * @param {string } test
25
+ * @param {string } message
26
+ */
22
27
function check ( t , test , message ) {
23
28
var input = fs . readFileSync ( path . join ( 'test' , 'fixture' , test + '.in' ) )
24
29
var output = fs . readFileSync ( path . join ( 'test' , 'fixture' , test + '.out' ) )
Original file line number Diff line number Diff line change
1
+ {
2
+ "include" : [" *.js" , " test/**.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