Skip to content

Commit 735d32c

Browse files
committed
Add JSDoc based types
1 parent f2d9f78 commit 735d32c

File tree

4 files changed

+42
-1
lines changed

4 files changed

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

build.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import https from 'https'
33
import concat from 'concat-stream'
44
import unified from 'unified'
55
import html from 'rehype-parse'
6+
// @ts-ignore
67
import q from 'hast-util-select'
8+
// @ts-ignore
79
import toString from 'hast-util-to-string'
810
import {bail} from 'bail'
911
import {htmlVoidElements} from './index.js'
@@ -12,14 +14,21 @@ var proc = unified().use(html)
1214

1315
https.get('https://html.spec.whatwg.org/multipage/syntax.html', onconnection)
1416

17+
/**
18+
* @param {import('http').IncomingMessage} response
19+
*/
1520
function onconnection(response) {
1621
response.pipe(concat(onconcat)).on('error', bail)
1722
}
1823

24+
/**
25+
* @param {Buffer} buf
26+
*/
1927
function onconcat(buf) {
2028
var dl = q.select('#elements-2 ~ dl dd', proc.parse(buf))
2129
var nodes = q.selectAll('code', dl)
2230
var index = -1
31+
/** @type {string} */
2332
var value
2433

2534
while (++index < nodes.length) {

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
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
"devDependencies": {
35+
"@types/concat-stream": "^1.0.0",
36+
"@types/node": "^14.0.0",
37+
"@types/tape": "^4.0.0",
3338
"bail": "^2.0.0",
3439
"c8": "^7.0.0",
3540
"concat-stream": "^2.0.0",
@@ -39,16 +44,21 @@
3944
"rehype-parse": "^7.0.0",
4045
"remark-cli": "^9.0.0",
4146
"remark-preset-wooorm": "^8.0.0",
47+
"rimraf": "^3.0.0",
4248
"tape": "^5.0.0",
49+
"type-coverage": "^2.0.0",
50+
"typescript": "^4.0.0",
4351
"unified": "^9.0.0",
4452
"xo": "^0.38.0"
4553
},
4654
"scripts": {
55+
"prepack": "npm run build && npm run format",
56+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4757
"generate": "node build",
4858
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4959
"test-api": "node test.js",
5060
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
51-
"test": "npm run format && npm run test-coverage"
61+
"test": "npm run build && npm run format && npm run test-coverage"
5262
},
5363
"prettier": {
5464
"tabWidth": 2,
@@ -70,5 +80,10 @@
7080
"plugins": [
7181
"preset-wooorm"
7282
]
83+
},
84+
"typeCoverage": {
85+
"atLeast": 100,
86+
"detail": true,
87+
"strict": true
7388
}
7489
}

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"files": ["index.js"],
3+
"include": ["*.js"],
4+
"compilerOptions": {
5+
"target": "ES2020",
6+
"lib": ["ES2020"],
7+
"module": "ES2020",
8+
"moduleResolution": "node",
9+
"allowJs": true,
10+
"checkJs": true,
11+
"declaration": true,
12+
"emitDeclarationOnly": true,
13+
"allowSyntheticDefaultImports": true,
14+
"skipLibCheck": true
15+
}
16+
}

0 commit comments

Comments
 (0)