LimitedCollection

Creates a new array with the results of calling a provided function on every element in the collection.

Signature

export declare class LimitedCollection<K, V>
JSDoc
Parameters
fn
The function that produces an element of the new array.
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.

Examples
const collection = new Collection<number, string>();
collection.set(1, 'one');
collection.set(2, 'two');
collection.set(3, 'three');
const mappedArray = collection.map((value, key) => `${key}: ${value}`);
console.log(mappedArray); // Output: ['1: one', '2: two', '3: three']

Properties

private readonly data;
closerGetter
get closer(): {    value: V;    expire: number;    expireOn: number;} | undefined;

Returns the element in the limited collection that is closest to expiration.

Returns

The element that is closest to expiration, or `undefined` if the collection is empty.

Examples
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] }
sizeGetter
get size(): number;

Returns the number of elements in the limited collection.

Returns

The number of elements in the collection.

Examples
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one');
collection.set(2, 'two');
console.log(collection.size); // Output: 2

Methods

set(key: K, value: V, customExpire?: number): void;

Adds an element to the limited collection.

Parameters
key
The key of the element.
value
The value of the element.
customExpire
The custom expiration time for the element.
Examples
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
raw(key: K): {    value: V;    expire: number;    expireOn: number;} | undefined;

Returns the raw data of an element in the limited collection.

Parameters
key
The key of the element.
Returns

The raw data of the element, or `undefined` if the element does not exist.

Examples
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one');
const rawData = collection.raw(1);
console.log(rawData); // Output: { value: 'one', expire: -1, expireOn: -1 }
get(key: K): V | undefined;

Returns the value of an element in the limited collection.

Parameters
key
The key of the element.
Returns

The value of the element, or `undefined` if the element does not exist.

Examples
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one');
const value = collection.get(1);
console.log(value); // Output: 'one'
has(key: K): boolean;

Checks if an element exists in the limited collection.

Parameters
key
The key of the element.
Returns

`true` if the element exists, `false` otherwise.

Examples
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one');
console.log(collection.has(1)); // Output: true
console.log(collection.has(2)); // Output: false
delete(key: K): boolean;

Removes an element from the limited collection.

Parameters
key
The key of the element to remove.
Returns

`true` if the element was removed, `false` otherwise.

Examples
const collection = new LimitedCollection<number, string>();
collection.set(1, 'one');
console.log(collection.delete(1)); // Output: true
console.log(collection.delete(2)); // Output: false
keys(): MapIterator<K>;
values(): IterableIterator<V>;
entries(): IterableIterator<[    K,    V]>;