qznt 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +13 -2
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ import { Cache, Storage } from "qznt";
|
|
|
55
55
|
// Cache with a 1-minute global TTL
|
|
56
56
|
const userCache = new Cache<UserData>(60000);
|
|
57
57
|
userCache.set("user_1", data);
|
|
58
|
+
userCache.delete("user_1");
|
|
58
59
|
|
|
59
60
|
// Persistent storage (Browser or NodeJS based)
|
|
60
61
|
const settings = new Storage("app_settings");
|
package/dist/index.cjs
CHANGED
|
@@ -128,6 +128,14 @@ var Cache = class {
|
|
|
128
128
|
}
|
|
129
129
|
return data.value;
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Removes a single entry from the cache.
|
|
133
|
+
* @param key The key to remove
|
|
134
|
+
* @returns Whether an entry existed and was removed
|
|
135
|
+
*/
|
|
136
|
+
delete(key) {
|
|
137
|
+
return this.cache.delete(key);
|
|
138
|
+
}
|
|
131
139
|
cleanup() {
|
|
132
140
|
if (this.cache.size === 0) return;
|
|
133
141
|
const now = Date.now();
|
|
@@ -163,7 +171,10 @@ var Loop = class extends TypedEmitterBase {
|
|
|
163
171
|
const result = await this.fn(this);
|
|
164
172
|
this.emit("tick", result);
|
|
165
173
|
} catch (err) {
|
|
166
|
-
|
|
174
|
+
try {
|
|
175
|
+
this.emit("error", err);
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
167
178
|
}
|
|
168
179
|
if (this._state === "running") {
|
|
169
180
|
this.startTime = Date.now();
|
|
@@ -470,7 +481,7 @@ function rndString(len, mode, options = {}) {
|
|
|
470
481
|
return result.join("");
|
|
471
482
|
}
|
|
472
483
|
|
|
473
|
-
// src/
|
|
484
|
+
// src/array.ts
|
|
474
485
|
function chunk(array, size) {
|
|
475
486
|
if (size <= 0) throw new Error("chunk: Size must be a positive integer.");
|
|
476
487
|
const result = [];
|
package/dist/index.d.cts
CHANGED
|
@@ -9,6 +9,12 @@ declare class Cache<T> {
|
|
|
9
9
|
constructor(cleanupMs?: number);
|
|
10
10
|
set(key: string | number, value: T, ttlMs?: number): void;
|
|
11
11
|
get(key: string | number): T | null;
|
|
12
|
+
/**
|
|
13
|
+
* Removes a single entry from the cache.
|
|
14
|
+
* @param key The key to remove
|
|
15
|
+
* @returns Whether an entry existed and was removed
|
|
16
|
+
*/
|
|
17
|
+
delete(key: string | number): boolean;
|
|
12
18
|
private cleanup;
|
|
13
19
|
clear(): void;
|
|
14
20
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ declare class Cache<T> {
|
|
|
9
9
|
constructor(cleanupMs?: number);
|
|
10
10
|
set(key: string | number, value: T, ttlMs?: number): void;
|
|
11
11
|
get(key: string | number): T | null;
|
|
12
|
+
/**
|
|
13
|
+
* Removes a single entry from the cache.
|
|
14
|
+
* @param key The key to remove
|
|
15
|
+
* @returns Whether an entry existed and was removed
|
|
16
|
+
*/
|
|
17
|
+
delete(key: string | number): boolean;
|
|
12
18
|
private cleanup;
|
|
13
19
|
clear(): void;
|
|
14
20
|
}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,14 @@ var Cache = class {
|
|
|
28
28
|
}
|
|
29
29
|
return data.value;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Removes a single entry from the cache.
|
|
33
|
+
* @param key The key to remove
|
|
34
|
+
* @returns Whether an entry existed and was removed
|
|
35
|
+
*/
|
|
36
|
+
delete(key) {
|
|
37
|
+
return this.cache.delete(key);
|
|
38
|
+
}
|
|
31
39
|
cleanup() {
|
|
32
40
|
if (this.cache.size === 0) return;
|
|
33
41
|
const now = Date.now();
|
|
@@ -63,7 +71,10 @@ var Loop = class extends TypedEmitterBase {
|
|
|
63
71
|
const result = await this.fn(this);
|
|
64
72
|
this.emit("tick", result);
|
|
65
73
|
} catch (err) {
|
|
66
|
-
|
|
74
|
+
try {
|
|
75
|
+
this.emit("error", err);
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
if (this._state === "running") {
|
|
69
80
|
this.startTime = Date.now();
|
|
@@ -370,7 +381,7 @@ function rndString(len, mode, options = {}) {
|
|
|
370
381
|
return result.join("");
|
|
371
382
|
}
|
|
372
383
|
|
|
373
|
-
// src/
|
|
384
|
+
// src/array.ts
|
|
374
385
|
function chunk(array, size) {
|
|
375
386
|
if (size <= 0) throw new Error("chunk: Size must be a positive integer.");
|
|
376
387
|
const result = [];
|