Skip to content

Commit f1d2001

Browse files
committed
Add JSDoc based types
1 parent 67aaaae commit f1d2001

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
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.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Check whether a `node` is labelable:
3+
* See: <https://html.spec.whatwg.org/#category-label>.
4+
*
5+
* @param {unknown} node
6+
* @returns {boolean}
7+
*/
8+
export function labelable(node: unknown): boolean;

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
// Check whether a `node` is labelable:
2-
// See: <https://html.spec.whatwg.org/#category-label>.
1+
/**
2+
* Check whether a `node` is labelable:
3+
* See: <https://html.spec.whatwg.org/#category-label>.
4+
*
5+
* @param {unknown} node
6+
* @returns {boolean}
7+
*/
38
export function labelable(node) {
4-
var name = node && node.type === 'element' && node.tagName
9+
/** @type {string} */
10+
var name =
11+
// @ts-ignore Looks like an object.
12+
node && typeof node === 'object' && node.type === 'element' && node.tagName
513

614
return Boolean(
715
name === 'button' ||
@@ -12,6 +20,7 @@ export function labelable(node) {
1220
name === 'select' ||
1321
name === 'textarea' ||
1422
(name === 'input' &&
23+
// @ts-ignore Looks like an object.
1524
(node.properties && node.properties.type) !== 'hidden')
1625
)
1726
}

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,30 @@
2525
"sideEffects": false,
2626
"type": "module",
2727
"main": "index.js",
28+
"types": "index.d.ts",
2829
"files": [
30+
"index.d.ts",
2931
"index.js"
3032
],
3133
"devDependencies": {
34+
"@types/tape": "^4.0.0",
3235
"c8": "^7.0.0",
3336
"prettier": "^2.0.0",
3437
"remark-cli": "^9.0.0",
3538
"remark-preset-wooorm": "^8.0.0",
39+
"rimraf": "^3.0.0",
3640
"tape": "^5.0.0",
41+
"type-coverage": "^2.0.0",
42+
"typescript": "^4.0.0",
3743
"xo": "^0.39.0"
3844
},
3945
"scripts": {
46+
"prepack": "npm run build && npm run format",
47+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4048
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4149
"test-api": "node test.js",
4250
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
43-
"test": "npm run format && npm run test-coverage"
51+
"test": "npm run build && npm run format && npm run test-coverage"
4452
},
4553
"prettier": {
4654
"tabWidth": 2,
@@ -61,5 +69,10 @@
6169
"plugins": [
6270
"preset-wooorm"
6371
]
72+
},
73+
"typeCoverage": {
74+
"atLeast": 100,
75+
"detail": true,
76+
"strict": true
6477
}
6578
}

test.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

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)