Skip to content

Commit 5066003

Browse files
committed
Add JSDoc based types
1 parent a033804 commit 5066003

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
/**
2+
* @typedef {import('unist').Node} Node
3+
*
4+
* @typedef {Object} NormalizeOptions
5+
* @property {boolean} [allowDashes=false]
6+
* @property {boolean} [allowApostrophes=false]
7+
*/
8+
19
import {toString} from 'nlcst-to-string'
210

11+
/**
12+
* @param {string|Node|Array.<Node>} node
13+
* @param {NormalizeOptions} [options={}]
14+
*/
315
export function normalize(node, options) {
416
var value = (typeof node === 'string' ? node : toString(node))
517
.toLowerCase()

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,34 @@
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
"dependencies": {
33+
"@types/unist": "^2.0.0",
3134
"nlcst-to-string": "^3.0.0"
3235
},
3336
"devDependencies": {
37+
"@types/tape": "^4.0.0",
3438
"c8": "^7.0.0",
3539
"prettier": "^2.0.0",
3640
"remark-cli": "^9.0.0",
3741
"remark-preset-wooorm": "^8.0.0",
42+
"rimraf": "^3.0.0",
3843
"tape": "^5.0.0",
44+
"type-coverage": "^2.0.0",
45+
"typescript": "^4.0.0",
3946
"xo": "^0.39.0"
4047
},
4148
"scripts": {
49+
"prepack": "npm run build && npm run format",
50+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4251
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4352
"test-api": "node test.js",
4453
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
45-
"test": "npm run format && npm run test-coverage"
54+
"test": "npm run build && npm run format && npm run test-coverage"
4655
},
4756
"prettier": {
4857
"tabWidth": 2,
@@ -63,5 +72,10 @@
6372
"plugins": [
6473
"preset-wooorm"
6574
]
75+
},
76+
"typeCoverage": {
77+
"atLeast": 100,
78+
"detail": true,
79+
"strict": true
6680
}
6781
}

test.js

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

44
test('Basic', function (t) {
55
t.throws(function () {
6+
// @ts-ignore runtime.
67
normalize(true)
78
}, 'should fail when given a boolean')
89

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)