Skip to content

Commit f981a5f

Browse files
committed
Add JSDoc based types
1 parent 7046208 commit f981a5f

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
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,5 +1,15 @@
1+
/**
2+
* @typedef {import('hast').Element & {tagName: 'audio'|'canvas'|'embed'|'iframe'|'img'|'math'|'object'|'picture'|'svg'|'video'}} Embedded
3+
* @typedef {import('hast-util-is-element').AssertPredicate<Embedded>} AssertEmbedded
4+
*/
5+
16
import {convertElement} from 'hast-util-is-element'
27

8+
/**
9+
* Check if a node is an embedded element.
10+
* @type {AssertEmbedded}
11+
*/
12+
// @ts-ignore Sure, the assertion matches.
313
export const embedded = convertElement([
414
'audio',
515
'canvas',

package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,33 @@
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": {
3335
"hast-util-is-element": "^2.0.0"
3436
},
3537
"devDependencies": {
38+
"@types/tape": "^4.0.0",
3639
"c8": "^7.0.0",
3740
"prettier": "^2.0.0",
3841
"remark-cli": "^9.0.0",
3942
"remark-preset-wooorm": "^8.0.0",
43+
"rimraf": "^3.0.0",
4044
"tape": "^5.0.0",
45+
"type-coverage": "^2.0.0",
46+
"typescript": "^4.0.0",
4147
"xo": "^0.39.0"
4248
},
4349
"scripts": {
50+
"prepack": "npm run build && npm run format",
51+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4452
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4553
"test-api": "node test.js",
4654
"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"
55+
"test": "npm run build && npm run format && npm run test-coverage"
4856
},
4957
"prettier": {
5058
"tabWidth": 2,
@@ -65,5 +73,10 @@
6573
"plugins": [
6674
"preset-wooorm"
6775
]
76+
},
77+
"typeCoverage": {
78+
"atLeast": 100,
79+
"detail": true,
80+
"strict": true
6881
}
6982
}

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)