diff --git a/.gitignore b/.gitignore index 704a7d4..3595bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.d.ts +*.d.ts.map *.log .DS_Store dest/ diff --git a/crawl.js b/crawl.js index 604cf99..0808b6b 100644 --- a/crawl.js +++ b/crawl.js @@ -2,6 +2,7 @@ import fs from 'node:fs/promises' import {iso6393} from 'iso-639-3' import {fetch} from 'undici' +/** @type {Record} */ const iso6393ToName = {} let index = -1 @@ -20,5 +21,9 @@ await fs.writeFile(new URL('src/fixtures.js', import.meta.url), body) await fs.writeFile( new URL('src/to-name.js', import.meta.url), - 'export const toName = ' + JSON.stringify(iso6393ToName, undefined, 2) + '\n' + [ + '/** @type {Record} */', + 'export const toName = ' + JSON.stringify(iso6393ToName, undefined, 2), + '' + ].join('\n') ) diff --git a/package.json b/package.json index 79e4500..7de2b7b 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,8 @@ "stylelint": "^14.0.0", "stylelint-config-prettier": "^9.0.0", "stylelint-config-standard": "^28.0.0", + "type-coverage": "^2.27.1", + "typescript": "^5.3.3", "undici": "^6.0.0", "xo": "^0.56.0" }, @@ -48,13 +50,14 @@ }, "repository": "wooorm/franc", "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage", "crawl": "node --conditions development crawl.js", "format": "remark --frail --output --quiet -- . && prettier . --log-level warn --write && xo --fix && stylelint src/index.css --fix", "generate:script": "esbuild src/index.js --bundle --minify --outfile=dest/index.nomodule.js --target=es6 && esbuild src/index.js --bundle --format=esm --minify --outfile=dest/index.module.js --target=es2020", "generate:structure": "rehype -u rehype-preset-minify -u rehype-prevent-favicon-request src -o dest", "generate:style": "postcss src/index.css > dest/index.css", "generate": "npm run generate:script && npm run generate:style && npm run generate:structure", - "test": "npm run crawl && npm run format && npm run generate" + "test": "npm run crawl && npm run build && npm run format && npm run generate" }, "stylelint": { "extends": [ @@ -63,6 +66,12 @@ ] }, "type": "module", + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, "xo": { "prettier": true, "ignore": [ diff --git a/src/index.js b/src/index.js index 3185524..4c48b12 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ /* eslint-env browser */ + import debounce from 'debounce' import {francAll} from 'franc' import {toName} from './to-name.js' @@ -38,7 +39,7 @@ function oninputchange() { const c2 = document.createElement('td') c0.append(link) c1.textContent = toName[code] - c2.textContent = score + c2.textContent = String(score) $node.append(c0) $node.append(c1) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c6d6d04 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "checkJs": true, + "customConditions": ["development"], + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "exactOptionalPropertyTypes": true, + "jsx": "preserve", + "lib": ["dom", "es2022"], + "module": "node16", + "strict": true, + "target": "es2022" + }, + "exclude": ["coverage/", "dest/", "node_modules/"], + "include": ["**/*.js"] +}