Returns the element in the limited collection that is closest to expiration.
The element that is closest to expiration, or undefined
if the collection is empty.
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one', 1000);
collection.set(2, 'two', 2000);
collection.set(3, 'three', 500);
const closestElement = collection.closer;
console.log(closestElement); // Output: { value: 'three', expire: 500, expireOn: [current timestamp + 500] }
Removes an element from the limited collection.
The key of the element to remove.
true
if the element was removed, false
otherwise.
Checks if an element exists in the limited collection.
The key of the element.
true
if the element exists, false
otherwise.
Adds an element to the limited collection.
const collection = new LimitedCollection<number, string>({ limit: 3 });
collection.set(1, 'one');
collection.set(2, 'two');
collection.set(3, 'three');
console.log(collection.size); // Output: 3
collection.set(4, 'four');
console.log(collection.size); // Output: 3
console.log(collection.get(1)); // Output: undefined
Creates a new array with the results of calling a provided function on every element in the collection.
Param: fn
The function that produces an element of the new array.
Param: thisArg
The value to use as
this
when executing the map function.Returns
A new array with the results of calling the provided function on every element in the collection.
Example