detritus-utils 0.5.0-beta.1 → 0.5.0-beta.2
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/lib/basecollection.d.ts +2 -0
- package/lib/basecollection.js +15 -0
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +1 -1
- package/package.json +1 -1
package/lib/basecollection.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export declare class BaseCollection<K, V> extends BaseCollectionMixin<K, V> {
|
|
|
47
47
|
delete(key: K): boolean;
|
|
48
48
|
forEach(func: (v: V, k: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
49
49
|
get(key: K): V | undefined;
|
|
50
|
+
getOrInsert(key: K, defaultValue: V): V;
|
|
51
|
+
getOrInsertComputed(key: K, func: (key: K) => V): V;
|
|
50
52
|
has(key: K): boolean;
|
|
51
53
|
keys(): IterableIterator<K>;
|
|
52
54
|
set(key: K, value: V): this;
|
package/lib/basecollection.js
CHANGED
|
@@ -261,6 +261,21 @@ class BaseCollection extends BaseCollectionMixin {
|
|
|
261
261
|
}
|
|
262
262
|
return value;
|
|
263
263
|
}
|
|
264
|
+
getOrInsert(key, defaultValue) {
|
|
265
|
+
if (this.has(key)) {
|
|
266
|
+
return this.get(key);
|
|
267
|
+
}
|
|
268
|
+
this.set(key, defaultValue);
|
|
269
|
+
return defaultValue;
|
|
270
|
+
}
|
|
271
|
+
getOrInsertComputed(key, func) {
|
|
272
|
+
if (this.has(key)) {
|
|
273
|
+
return this.get(key);
|
|
274
|
+
}
|
|
275
|
+
const value = func(key);
|
|
276
|
+
this.set(key, value);
|
|
277
|
+
return value;
|
|
278
|
+
}
|
|
264
279
|
has(key) {
|
|
265
280
|
return this.cache.has(key);
|
|
266
281
|
}
|
package/lib/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const Package: Readonly<{
|
|
2
2
|
URL: "https://github.com/detritusjs/utils";
|
|
3
|
-
VERSION: "0.5.0-beta.
|
|
3
|
+
VERSION: "0.5.0-beta.2";
|
|
4
4
|
}>;
|
|
5
5
|
export declare const DISCORD_SNOWFLAKE_EPOCH = 1420070400000;
|
|
6
6
|
export declare const DISCORD_TOKEN_EPOCH = 1293840000000;
|
package/lib/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DISCORD_TOKEN_EPOCH = exports.DISCORD_SNOWFLAKE_EPOCH = exports.Package = void 0;
|
|
4
4
|
exports.Package = Object.freeze({
|
|
5
5
|
URL: 'https://github.com/detritusjs/utils',
|
|
6
|
-
VERSION: '0.5.0-beta.
|
|
6
|
+
VERSION: '0.5.0-beta.2',
|
|
7
7
|
});
|
|
8
8
|
exports.DISCORD_SNOWFLAKE_EPOCH = 1420070400000;
|
|
9
9
|
exports.DISCORD_TOKEN_EPOCH = 1293840000000;
|