From f17a208015d8e04327f12dd667903c6e5bd30648 Mon Sep 17 00:00:00 2001 From: Nodari Chkuaselidze Date: Thu, 6 Jul 2023 14:55:18 +0400 Subject: [PATCH] pkg: add type lints using tsc. --- lib/base32.js | 6 +++--- lib/bs32.js | 4 +++- package-lock.json | 9 ++++++++- package.json | 4 +++- tsconfig.json | 31 +++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 tsconfig.json diff --git a/lib/base32.js b/lib/base32.js index bc3f2c8..164c603 100644 --- a/lib/base32.js +++ b/lib/base32.js @@ -227,7 +227,7 @@ function _decode(str, table, unpad) { if (left > 0) throw new Error('Invalid base32 string.'); - if (str.length !== i + (-mode & 7) * unpad) + if (str.length !== i + (-mode & 7) * Number(unpad)) throw new Error('Invalid base32 string.'); for (; i < str.length; i++) { @@ -244,7 +244,7 @@ function _decode(str, table, unpad) { * Test a base32 string. * @param {String} str * @param {Boolean} [unpad=false] - * @returns {Buffer} + * @returns {Boolean} */ function test(str, unpad = false) { @@ -260,7 +260,7 @@ function test(str, unpad = false) { * Test a base32 hex string. * @param {String} str * @param {Boolean} [unpad=false] - * @returns {Buffer} + * @returns {Boolean} */ function testHex(str, unpad = false) { diff --git a/lib/bs32.js b/lib/bs32.js index 899b42c..9d7bb10 100644 --- a/lib/bs32.js +++ b/lib/bs32.js @@ -1,3 +1,5 @@ 'use strict'; -module.exports = require('./base32'); +const base32 = require('./base32'); + +module.exports = base32; diff --git a/package-lock.json b/package-lock.json index 7054c0f..a97f99e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "bsert": "~0.0.10" }, "devDependencies": { - "bmocha": "^2.1.0" + "bmocha": "^2.1.0", + "bts-type-deps": "^0.0.3" }, "engines": { "node": ">=8.0.0" @@ -38,6 +39,12 @@ "engines": { "node": ">=8.0.0" } + }, + "node_modules/bts-type-deps": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/bts-type-deps/-/bts-type-deps-0.0.3.tgz", + "integrity": "sha512-OQHGWhX5amae6Vj6ShlGaQu0sNCICgJ5YspNZPRzfR5RobrD+wjm5vkZK/J3EH5b/ymxqSWo9VkiFNpCxjaG2Q==", + "dev": true } } } diff --git a/package.json b/package.json index ad2ac2d..1f94aa6 100644 --- a/package.json +++ b/package.json @@ -15,13 +15,15 @@ "main": "./lib/bs32.js", "scripts": { "lint": "eslint lib/ test/", + "lint-types": "tsc -p .", "test": "bmocha --reporter spec test/*-test.js" }, "dependencies": { "bsert": "~0.0.10" }, "devDependencies": { - "bmocha": "^2.1.0" + "bmocha": "^2.1.0", + "bts-type-deps": "^0.0.3" }, "engines": { "node": ">=8.0.0" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..da7a94b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "include": [ + "lib/**/*.js" + ], + "compilerOptions": { + "rootDir": ".", + "target": "ES2020", + "lib": [ + "ES2020" + ], + + "noEmit": true, + + "allowJs": true, + "checkJs": true, + "maxNodeModuleJsDepth": 10, + + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + + "stripInternal": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + + "typeRoots": [ + "node_modules/bts-type-deps/types" + ] + } +}