Skip to content

Commit 56a473d

Browse files
authored
Add JSDoc based types
Closes GH-1.
1 parent 93ff202 commit 56a473d

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
2+
*.d.ts
23
*.log
4+
*.tgz
35
.nyc_output/
46
coverage/
57
node_modules/

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@ exports.name = name
66

77
var id = require('./regex')
88

9+
/**
10+
* Checks if the given character code can start an identifier.
11+
*
12+
* @param {number} code
13+
*/
914
// To do: support astrals.
1015
function start(code) {
1116
return id.start.test(String.fromCharCode(code))
1217
}
1318

19+
/**
20+
* Checks if the given character code can continue an identifier.
21+
*
22+
* @param {number} code
23+
*/
1424
// To do: support astrals.
1525
function cont(code) {
1626
var character = String.fromCharCode(code)
1727
return id.start.test(character) || id.cont.test(character)
1828
}
1929

30+
/**
31+
* Checks if the given string is a valid identifier name.
32+
*
33+
* @param {string} name
34+
*/
2035
function name(name) {
2136
var index = -1
2237

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,31 @@
2424
],
2525
"files": [
2626
"index.js",
27-
"regex.js"
27+
"regex.js",
28+
"*.d.ts"
2829
],
29-
"dependencies": {},
3030
"devDependencies": {
31+
"@types/tape": "^4.0.0",
3132
"@unicode/unicode-13.0.0": "^1.0.0",
3233
"nyc": "^15.0.0",
3334
"prettier": "^2.0.0",
3435
"regenerate": "^1.0.0",
3536
"remark-cli": "^9.0.0",
3637
"remark-preset-wooorm": "^8.0.0",
38+
"rimraf": "^3.0.0",
3739
"tape": "^5.0.0",
40+
"type-coverage": "^2.0.0",
41+
"typescript": "^4.0.0",
3842
"xo": "^0.36.0"
3943
},
4044
"scripts": {
4145
"generate": "node build",
4246
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4347
"test-api": "node test",
4448
"test-coverage": "nyc --reporter lcov tape test.js",
45-
"test": "npm run generate && npm run format && npm run test-coverage"
49+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
50+
"test": "npm run generate && npm run format && npm run test-coverage && npm run build",
51+
"prepack": "npm run build && npm run format"
4652
},
4753
"prettier": {
4854
"tabWidth": 2,
@@ -73,5 +79,10 @@
7379
"plugins": [
7480
"preset-wooorm"
7581
]
82+
},
83+
"typeCoverage": {
84+
"atLeast": 100,
85+
"detail": true,
86+
"strict": true
7687
}
7788
}

tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"files": ["index.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+
"skipLibCheck": true
13+
}
14+
}

0 commit comments

Comments
 (0)