Skip to content

Commit 171e618

Browse files
committed
Add JSDoc based types
1 parent ab10317 commit 171e618

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
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

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
* @typedef {Object} PointLike
3+
* @property {number} [line]
4+
* @property {number} [column]
5+
* @property {number} [offset]
6+
*
7+
* @typedef {Object} PositionLike
8+
* @property {PointLike} [start]
9+
* @property {PointLike} [end]
10+
*
11+
* @typedef {Object} NodeLike
12+
* @property {PositionLike} [position]
13+
*/
14+
15+
/**
16+
* Check if `node` is *generated*.
17+
*
18+
* @param {NodeLike} [node]
19+
* @returns {boolean}
20+
*/
121
export function generated(node) {
222
return (
323
!node ||

package.json

+14-1
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.38.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.js

-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ test('generated', function (t) {
1010
start: {
1111
line: 1,
1212
column: 1,
13-
indent: [],
1413
offset: 0
1514
},
1615
end: {
1716
line: 1,
1817
column: 2,
19-
indent: [],
2018
offset: 1
2119
}
2220
}

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)