Skip to content

Commit 5239bd5

Browse files
committed
Add JSDoc based types
1 parent f41ce95 commit 5239bd5

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

.gitignore

+1
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

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @typedef {import('hast').Element & {tagName: 'article'|'aside'|'nav'|'section'}} Sectioning
3+
* @typedef {import('hast-util-is-element').AssertPredicate<Sectioning>} AssertSectioning
4+
*/
5+
16
import {convertElement} from 'hast-util-is-element'
27

8+
/**
9+
* Check if a node is a sectioning element.
10+
* @type {AssertSectioning}
11+
*/
12+
// @ts-ignore Sure, the assertion matches.
313
export const sectioning = convertElement(['article', 'aside', 'nav', 'section'])

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,30 @@
2626
"sideEffects": false,
2727
"type": "module",
2828
"main": "index.js",
29+
"types": "index.d.ts",
2930
"files": [
31+
"index.d.ts",
3032
"index.js"
3133
],
3234
"dependencies": {
35+
"@types/hast": "^2.0.0",
3336
"hast-util-is-element": "^2.0.0"
3437
},
3538
"devDependencies": {
39+
"@types/tape": "^4.0.0",
3640
"c8": "^7.0.0",
3741
"prettier": "^2.0.0",
3842
"remark-cli": "^9.0.0",
3943
"remark-preset-wooorm": "^8.0.0",
44+
"rimraf": "^3.0.0",
4045
"tape": "^5.0.0",
46+
"type-coverage": "^2.0.0",
47+
"typescript": "^4.0.0",
4148
"xo": "^0.39.0"
4249
},
4350
"scripts": {
51+
"prepack": "npm run build && npm run format",
52+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4453
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4554
"test-api": "node test.js",
4655
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
@@ -65,5 +74,10 @@
6574
"plugins": [
6675
"preset-wooorm"
6776
]
77+
},
78+
"typeCoverage": {
79+
"atLeast": 100,
80+
"detail": true,
81+
"strict": true
6882
}
6983
}

tsconfig.json

+15
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)