@ztimson/utils 0.25.12 → 0.25.13
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/dist/cache.d.ts +7 -0
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -69,6 +69,13 @@ export declare class Cache<K extends string | number | symbol, T> {
|
|
|
69
69
|
* @param {K} key Key to expire
|
|
70
70
|
*/
|
|
71
71
|
expire(key: K): this;
|
|
72
|
+
/**
|
|
73
|
+
* Find the first cached item to match a filter
|
|
74
|
+
* @param {Partial<T>} filter Partial item to match
|
|
75
|
+
* @param {Boolean} expired Include expired items, defaults to false
|
|
76
|
+
* @returns {T | undefined} Cached item or undefined if nothing matched
|
|
77
|
+
*/
|
|
78
|
+
find(filter: Partial<T>, expired?: boolean): T | undefined;
|
|
72
79
|
/**
|
|
73
80
|
* Get item from the cache
|
|
74
81
|
* @param {K} key Key to lookup
|
package/dist/index.cjs
CHANGED
|
@@ -648,6 +648,15 @@ ${opts.message || this.desc}`;
|
|
|
648
648
|
} else this.delete(key);
|
|
649
649
|
return this;
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Find the first cached item to match a filter
|
|
653
|
+
* @param {Partial<T>} filter Partial item to match
|
|
654
|
+
* @param {Boolean} expired Include expired items, defaults to false
|
|
655
|
+
* @returns {T | undefined} Cached item or undefined if nothing matched
|
|
656
|
+
*/
|
|
657
|
+
find(filter, expired) {
|
|
658
|
+
return Object.values(this.store).find((row) => (expired || !row._expired) && includes(row, filter));
|
|
659
|
+
}
|
|
651
660
|
/**
|
|
652
661
|
* Get item from the cache
|
|
653
662
|
* @param {K} key Key to lookup
|