quick-lru
Advanced tools
Comparing version 6.0.2 to 6.1.0
@@ -27,3 +27,3 @@ export interface Options<KeyType, ValueType> { | ||
export default class QuickLRU<KeyType, ValueType> implements Iterable<[KeyType, ValueType]> { | ||
export default class QuickLRU<KeyType, ValueType> extends Map implements Iterable<[KeyType, ValueType]> { | ||
/** | ||
@@ -30,0 +30,0 @@ The stored item count. |
18
index.js
@@ -1,3 +0,5 @@ | ||
export default class QuickLRU { | ||
export default class QuickLRU extends Map { | ||
constructor(options = {}) { | ||
super(); | ||
if (!(options.maxSize && options.maxSize > 0)) { | ||
@@ -265,2 +267,16 @@ throw new TypeError('`maxSize` must be a number greater than 0'); | ||
} | ||
entries() { | ||
return this.entriesAscending(); | ||
} | ||
forEach(callbackFunction, thisArgument = this) { | ||
for (const [key, value] of this.entriesAscending()) { | ||
callbackFunction.call(thisArgument, value, key, this); | ||
} | ||
} | ||
[Symbol.toStringTag]() { | ||
return JSON.stringify([...this.entriesAscending()]); | ||
} | ||
} |
{ | ||
"name": "quick-lru", | ||
"version": "6.0.2", | ||
"version": "6.1.0", | ||
"description": "Simple “Least Recently Used” (LRU) cache", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -37,2 +37,4 @@ # quick-lru [![Coverage Status](https://codecov.io/gh/sindresorhus/quick-lru/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/quick-lru/branch/main) | ||
It's a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) subclass. | ||
### options | ||
@@ -126,2 +128,14 @@ | ||
#### .entries() | ||
Iterable for all entries, starting with the newest (ascending in recency). | ||
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.** | ||
#### .forEach(callbackFunction, thisArgument) | ||
Loop over entries calling the `callbackFunction` for each entry (ascending in recency). | ||
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.** | ||
#### .size | ||
@@ -128,0 +142,0 @@ |
15222
326
158