Skip to content

Commit 9c59954

Browse files
committed
Add JSDoc based types
1 parent d263503 commit 9c59954

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
*.d.ts
23
*.log
34
coverage/
45
node_modules/

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
// Rank of a heading: H1 -> 1, H2 -> 2, etc.
1+
/**
2+
* @typedef {import('hast').Element} HastElement
3+
*/
4+
5+
/**
6+
* Rank of a heading: H1 -> 1, H2 -> 2, etc.
7+
*
8+
* @param {HastElement} node
9+
* @returns {number|null}
10+
*/
211
export function headingRank(node) {
312
var name =
413
(node && node.type === 'element' && node.tagName.toLowerCase()) || ''

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,34 @@
2828
"sideEffects": false,
2929
"type": "module",
3030
"main": "index.js",
31+
"types": "index.d.ts",
3132
"files": [
33+
"index.d.ts",
3234
"index.js"
3335
],
36+
"dependencies": {
37+
"@types/hast": "^2.0.0"
38+
},
3439
"devDependencies": {
40+
"@types/tape": "^4.0.0",
3541
"c8": "^7.0.0",
3642
"hastscript": "^7.0.0",
3743
"prettier": "^2.0.0",
3844
"remark-cli": "^9.0.0",
3945
"remark-preset-wooorm": "^8.0.0",
46+
"rimraf": "^3.0.0",
4047
"tape": "^5.0.0",
48+
"type-coverage": "^2.0.0",
49+
"typescript": "^4.0.0",
4150
"xo": "^0.39.0"
4251
},
4352
"scripts": {
53+
"prepack": "npm run build && npm run format",
54+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4455
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4556
"test-api": "node test.js",
4657
"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"
58+
"test": "npm run build && npm run format && npm run test-coverage"
4859
},
4960
"prettier": {
5061
"tabWidth": 2,
@@ -65,5 +76,10 @@
6576
"plugins": [
6677
"preset-wooorm"
6778
]
79+
},
80+
"typeCoverage": {
81+
"atLeast": 100,
82+
"detail": true,
83+
"strict": true
6884
}
6985
}

test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import {h} from 'hastscript'
33
import {headingRank} from './index.js'
44

55
test('headingRank', function (t) {
6+
// @ts-ignore runtime.
67
t.equal(headingRank(), null, 'should return null for non-nodes')
78

89
t.equal(
10+
// @ts-ignore runtime.
911
headingRank({type: 'text', value: '!'}),
1012
null,
1113
'should return null for non-elements'

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)