Skip to content

Commit c13aa6b

Browse files
committed
Add JSDoc based types
1 parent adf0721 commit c13aa6b

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
@@ -4,7 +4,9 @@ import {bail} from 'bail'
44
import concat from 'concat-stream'
55
import unified from 'unified'
66
import parse from 'rehype-parse'
7+
// @ts-ignore
78
import select from 'hast-util-select'
9+
// @ts-ignore
810
import toString from 'hast-util-to-string'
911
import {svgTagNames} from './index.js'
1012

@@ -22,13 +24,20 @@ while (++index < urls.length) {
2224
https.get(urls[index], onconnection)
2325
}
2426

27+
/**
28+
* @param {import('http').IncomingMessage} response
29+
*/
2530
function onconnection(response) {
2631
response.pipe(concat(onconcat)).on('error', bail)
2732
}
2833

34+
/**
35+
* @param {Buffer} buf
36+
*/
2937
function onconcat(buf) {
3038
var nodes = select.selectAll('.element-name', proc.parse(buf))
3139
var index = -1
40+
/** @type {string} */
3241
var value
3342

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

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
"sideEffects": false,
2525
"type": "module",
2626
"main": "index.js",
27+
"types": "index.d.ts",
2728
"files": [
29+
"index.d.ts",
2830
"index.js"
2931
],
3032
"devDependencies": {
33+
"@types/concat-stream": "^1.0.0",
34+
"@types/node": "^14.0.0",
35+
"@types/tape": "^4.0.0",
3136
"bail": "^2.0.0",
3237
"c8": "^7.0.0",
3338
"concat-stream": "^2.0.0",
@@ -37,16 +42,21 @@
3742
"rehype-parse": "^7.0.0",
3843
"remark-cli": "^9.0.0",
3944
"remark-preset-wooorm": "^8.0.0",
45+
"rimraf": "^3.0.0",
4046
"tape": "^5.0.0",
47+
"type-coverage": "^2.0.0",
48+
"typescript": "^4.0.0",
4149
"unified": "^9.0.0",
4250
"xo": "^0.38.0"
4351
},
4452
"scripts": {
53+
"prepack": "npm run build && npm run format",
54+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4555
"generate": "node build",
4656
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4757
"test-api": "node test.js",
4858
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
49-
"test": "npm run format && npm run test-coverage"
59+
"test": "npm run build && npm run format && npm run test-coverage"
5060
},
5161
"prettier": {
5262
"tabWidth": 2,
@@ -68,5 +78,10 @@
6878
"plugins": [
6979
"preset-wooorm"
7080
]
81+
},
82+
"typeCoverage": {
83+
"atLeast": 100,
84+
"detail": true,
85+
"strict": true
7186
}
7287
}

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)