From 5abd2ee49def08012121fbd507b771be3fde6aff Mon Sep 17 00:00:00 2001 From: Nodari Chkuaselidze Date: Thu, 6 Jul 2023 20:35:01 +0400 Subject: [PATCH] pkg: add type lints. --- lib/lru.js | 21 +++++++-------------- package-lock.json | 9 ++++++++- package.json | 4 +++- tsconfig.json | 31 +++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 tsconfig.json diff --git a/lib/lru.js b/lib/lru.js index 535ee04..454e2b1 100644 --- a/lib/lru.js +++ b/lib/lru.js @@ -13,6 +13,9 @@ const assert = require('bsert'); */ class LRU { + /** @type {Map} */ + map; + /** * Create an LRU cache. * @constructor @@ -27,6 +30,7 @@ class LRU { assert(!getSize || typeof getSize === 'function', 'Bad size callback.'); assert(!CustomMap || typeof CustomMap === 'function'); + // @ts-ignore this.map = CustomMap ? new CustomMap() : new Map(); this.size = 0; this.items = 0; @@ -202,20 +206,10 @@ class LRU { return true; } - /** - * Prepend an item to the linked list (sets new head). - * @private - * @param {LRUItem} - */ - - _prependList(item) { - this._insertList(null, item); - } - /** * Append an item to the linked list (sets new tail). * @private - * @param {LRUItem} + * @param {LRUItem} item */ _appendList(item) { @@ -259,7 +253,7 @@ class LRU { /** * Remove item from the linked list. * @private - * @param {LRUItem} + * @param {LRUItem} item */ _removeList(item) { @@ -420,8 +414,7 @@ class LRUItem { /** * Create an LRU item. * @constructor - * @private - * @param {String} key + * @param {String|Number} key * @param {Object} value */ diff --git a/package-lock.json b/package-lock.json index 87948de..122dd77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "bsert": "~0.0.12" }, "devDependencies": { - "bmocha": "^2.1.8" + "bmocha": "^2.1.8", + "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 459f7da..60923d3 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,15 @@ "main": "./lib/blru.js", "scripts": { "lint": "eslint lib/ test/", + "lint-types": "tsc -p .", "test": "bmocha --reporter spec test/*-test.js" }, "dependencies": { "bsert": "~0.0.12" }, "devDependencies": { - "bmocha": "^2.1.8" + "bmocha": "^2.1.8", + "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..56c78ac --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "include": [ + "lib/**/*.js" + ], + "compilerOptions": { + "rootDir": ".", + "target": "ES2016", + "lib": [ + "ES2016" + ], + + "noEmit": true, + + "allowJs": true, + "checkJs": true, + "maxNodeModuleJsDepth": 2, + + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + + "stripInternal": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + + "typeRoots": [ + "node_modules/bts-type-deps/types" + ] + } +}