Skip to content

Commit efa32c7

Browse files
Surjit Kumar SahooSurjit Kumar Sahoo
authored andcommitted
Add types to cache library
1 parent 89747d3 commit efa32c7

6 files changed

Lines changed: 781 additions & 653 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"editor.tabSize": 2,
66
"editor.insertSpaces": true,
77
"editor.codeActionsOnSave": {
8-
"source.fixAll": true
8+
"source.fixAll": "explicit"
99
},
1010
"eslint.alwaysShowStatus": true,
1111
"files.autoSave": "onFocusChange",

libs/cache/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

libs/cache/package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
{
2-
"name": "cache",
3-
"version": "1.0.0",
2+
"name": "@surjit/cache",
3+
"version": "0.0.2",
44
"description": "A simple cache library",
55
"author": "Surjit Kumar Sahoo",
66
"license": "MIT",
7-
"main": "src/index.js",
7+
"main": "dist/index.js",
8+
"types": "dist/index.d.ts",
89
"type": "module",
10+
"files": [
11+
"dist"
12+
],
913
"scripts": {
10-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
14+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
15+
"build:types": "rimraf dist && tsc --declaration --outDir dist"
1116
},
1217
"engines": {
1318
"node": ">=14.5.0"
1419
},
1520
"devDependencies": {
1621
"@types/jest": "^29.2.4",
1722
"cross-env": "^7.0.3",
18-
"jest": "^29.3.1"
23+
"jest": "^29.3.1",
24+
"rimraf": "^5.0.7",
25+
"typescript": "^5.4.5"
1926
}
2027
}

libs/cache/src/memoryCache/memCache.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class Cache {
2020
#logger = console;
2121

2222
/**
23-
* @param {object=} config - Optional Config options
23+
* @param {object} [config] - Optional Config options
2424
* @param {object} config.logger - A logger instance which must have .log method in it
2525
* @param {boolean} config.debug - Enable debug mode
2626
*/
@@ -93,6 +93,10 @@ export class Cache {
9393
return value;
9494
}
9595

96+
/**
97+
*
98+
* @param {string} key
99+
*/
96100
#del(key) {
97101
this.#size -= 1;
98102
delete this.#cache[key];
@@ -135,6 +139,11 @@ export class Cache {
135139
}
136140
}
137141

142+
/**
143+
* Get Cached data
144+
* @param {string} key
145+
* @returns {any}
146+
*/
138147
get(key) {
139148
const data = this.#cache[key];
140149
if (data) {
@@ -152,6 +161,9 @@ export class Cache {
152161
return null;
153162
}
154163

164+
/**
165+
* Count the cache size
166+
*/
155167
get size() {
156168
return this.#size;
157169
}

libs/cache/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": false,
4+
"moduleResolution": "Node",
5+
"target": "ESNext",
6+
"allowJs": true,
7+
"checkJs": true,
8+
"esModuleInterop": true
9+
},
10+
"include": ["./src/**/*"],
11+
"exclude": ["./src/**/*.test.js"]
12+
}

0 commit comments

Comments
 (0)