diff --git a/CHANGELOG.md b/CHANGELOG.md index c5131cc..daf1aa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # cringe lorg +## 10.2.0 + +- types: implement the `Map` interface + ## 10.1.0 - add `cache.info(key)` to get value as well as ttl and size diff --git a/src/index.ts b/src/index.ts index 58b6c4c..216af71 100644 --- a/src/index.ts +++ b/src/index.ts @@ -812,7 +812,7 @@ export namespace LRUCache { * Changing any of these will alter the defaults for subsequent method calls, * but is otherwise safe. */ -export class LRUCache { +export class LRUCache implements Map { // properties coming in from the options of these, only max and maxSize // really *need* to be protected. The rest can be modified, as they just // set defaults for various methods. @@ -1392,7 +1392,7 @@ export class LRUCache { this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i]) ) { - yield [this.#keyList[i], this.#valList[i]] + yield [this.#keyList[i], this.#valList[i]] as [K, V] } } } @@ -1460,7 +1460,7 @@ export class LRUCache { v !== undefined && !this.#isBackgroundFetch(this.#valList[i]) ) { - yield this.#valList[i] + yield this.#valList[i] as V } } } @@ -1491,6 +1491,12 @@ export class LRUCache { return this.entries() } + /** + * A String value that is used in the creation of the default string description of an object. + * Called by the built-in method Object.prototype.toString. + */ + [Symbol.toStringTag] = 'LRUCache' + /** * Find a value for which the supplied fn method returns a truthy value, * similar to Array.find(). fn is called as fn(value, key, cache).