Skip to content

Commit e8410d2

Browse files
committed
Add JSDoc based types
1 parent bf50bce commit e8410d2

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
coverage/
22
node_modules/
33
.DS_Store
4+
*.d.ts
45
*.log
56
yarn.lock

index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* @typedef Options
3+
* Configuration.
4+
* @property {boolean} [allowLiterals=false]
5+
* Suggest straight (`'`) instead of smart (`’`) apostrophes.
6+
* Use `retext-quotes` if you want to properly check that though.
7+
* @property {boolean} [straight=false]
8+
* Include literal phrases.
9+
* The default is to ignore them.
10+
*/
11+
112
import {visit} from 'unist-util-visit'
213
import {toString} from 'nlcst-to-string'
314
import {isLiteral} from 'nlcst-is-literal'
@@ -10,7 +21,11 @@ const own = {}.hasOwnProperty
1021

1122
const data = initialize()
1223

13-
// Check contractions use.
24+
/**
25+
* Plugin to check contractions use.
26+
*
27+
* @type {import('unified').Plugin<[Options?]>}
28+
*/
1429
export default function retextContractions(options = {}) {
1530
const ignore = options.allowLiterals
1631
const straight = options.straight
@@ -32,7 +47,7 @@ export default function retextContractions(options = {}) {
3247
// Perfect.
3348
actual === expected ||
3449
// Ignore literal misspelt words: `like this: “hasnt”`.
35-
(!ignore && isLiteral(parent, index))
50+
(parent && index !== null && !ignore && isLiteral(parent, index))
3651
) {
3752
return
3853
}
@@ -66,8 +81,11 @@ export default function retextContractions(options = {}) {
6681
}
6782
}
6883

84+
/** @returns {Record<string, string>} */
6985
function initialize() {
86+
/** @type {Record<string, string>} */
7087
const result = {}
88+
/** @type {string} */
7189
let key
7290

7391
for (key in list) {

list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {Record<string, string>} */
12
export const list = {
23
aint: "ain't",
34
arent: "aren't",

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,38 @@
2626
"sideEffects": false,
2727
"type": "module",
2828
"main": "index.js",
29+
"types": "index.d.ts",
2930
"files": [
31+
"index.d.ts",
3032
"index.js",
33+
"list.d.ts",
3134
"list.js"
3235
],
3336
"dependencies": {
3437
"nlcst-is-literal": "^2.0.0",
3538
"nlcst-to-string": "^3.0.0",
39+
"unified": "^10.0.0",
3640
"unist-util-visit": "^3.0.0"
3741
},
3842
"devDependencies": {
43+
"@types/tape": "^4.0.0",
3944
"c8": "^7.0.0",
4045
"prettier": "^2.0.0",
4146
"remark-cli": "^9.0.0",
4247
"remark-preset-wooorm": "^8.0.0",
4348
"retext": "^8.0.0",
49+
"rimraf": "^3.0.0",
4450
"tape": "^5.0.0",
51+
"type-coverage": "^2.0.0",
52+
"typescript": "^4.0.0",
4553
"xo": "^0.39.0"
4654
},
4755
"scripts": {
56+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4857
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4958
"test-api": "node --conditions development test.js",
5059
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
51-
"test": "npm run format && npm run test-coverage"
60+
"test": "npm run build && npm run format && npm run test-coverage"
5261
},
5362
"prettier": {
5463
"tabWidth": 2,
@@ -75,5 +84,11 @@
7584
}
7685
]
7786
]
87+
},
88+
"typeCoverage": {
89+
"atLeast": 100,
90+
"detail": true,
91+
"strict": true,
92+
"ignoreCatch": true
7893
}
7994
}

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
"strict": true
15+
}
16+
}

0 commit comments

Comments
 (0)