Skip to content

Commit be74b56

Browse files
committed
Add JSDoc based types
1 parent ac53c5b commit be74b56

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-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/

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @typedef {import('unist').Node} Node
3+
*/
4+
15
import {hasProperty} from 'hast-util-has-property'
26

37
// Always interactive nodes.
@@ -12,13 +16,19 @@ var alwaysInteractive = new Set([
1216
'textarea'
1317
])
1418

19+
/**
20+
* @param {Node} node
21+
* @returns {boolean}
22+
*/
1523
export function interactive(node) {
24+
/** @type {string} */
1625
var name
1726

1827
if (!node || typeof node !== 'object' || node.type !== 'element') {
1928
return false
2029
}
2130

31+
// @ts-ignore looks like an element.
2232
name = node.tagName
2333

2434
return (
@@ -27,6 +37,7 @@ export function interactive(node) {
2737
(name === 'video' && hasProperty(node, 'controls')) ||
2838
(name === 'object' && hasProperty(node, 'useMap')) ||
2939
(name === 'img' && hasProperty(node, 'useMap')) ||
40+
// @ts-ignore looks like an element.
3041
(name === 'input' && (node.properties || {}).type !== 'hidden') ||
3142
hasProperty(node, 'tabIndex') ||
3243
alwaysInteractive.has(name)

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,34 @@
2727
"sideEffects": false,
2828
"type": "module",
2929
"main": "index.js",
30+
"types": "index.d.ts",
3031
"files": [
32+
"index.d.ts",
3133
"index.js"
3234
],
3335
"dependencies": {
36+
"@types/unist": "^2.0.0",
3437
"hast-util-has-property": "^2.0.0"
3538
},
3639
"devDependencies": {
40+
"@types/tape": "^4.0.0",
3741
"c8": "^7.0.0",
3842
"prettier": "^2.0.0",
3943
"remark-cli": "^9.0.0",
4044
"remark-preset-wooorm": "^8.0.0",
45+
"rimraf": "^3.0.0",
4146
"tape": "^5.0.0",
47+
"type-coverage": "^2.0.0",
48+
"typescript": "^4.0.0",
4249
"xo": "^0.39.0"
4350
},
4451
"scripts": {
52+
"prepack": "npm run build && npm run format",
53+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4554
"format": "remark . -qfo && prettier . --write --loglevel warn && xo --fix",
4655
"test-api": "node test.js",
4756
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
48-
"test": "npm run format && npm run test-coverage"
57+
"test": "npm run build && npm run format && npm run test-coverage"
4958
},
5059
"prettier": {
5160
"tabWidth": 2,
@@ -66,5 +75,10 @@
6675
"plugins": [
6776
"preset-wooorm"
6877
]
78+
},
79+
"typeCoverage": {
80+
"atLeast": 100,
81+
"detail": true,
82+
"strict": true
6983
}
7084
}

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import test from 'tape'
22
import {interactive} from './index.js'
33

44
test('interactive', function (t) {
5+
// @ts-ignore runtime.
56
t.equal(interactive(), false, 'should return `false` without node')
67
t.equal(interactive(null), false, 'should return `false` with `null`')
78

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)