Skip to content

LimitedCollection

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

Param

The function that produces an element of the new array.

Param

The value to use as this when executing the map function.

Example

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

Type parameters

Type parameter
K
V

Constructors

new LimitedCollection(options)

1
new LimitedCollection<K, V>(options: Partial<LimitedCollectionOptions<K, V>>): LimitedCollection<K, V>

Parameters

ParameterType
optionsPartial<LimitedCollectionOptions<K, V>>

Returns

LimitedCollection<K, V>

Source

seyfert/src/collection.ts:229

Properties

PropertyModifierType
defaultreadonlyLimitedCollectionOptions<any, any>

Accessors

closer

1
get closer(): undefined | LimitedCollectionData<V>

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

Example

1
const collection = new LimitedCollection<number, string>();
2
collection.set(1, 'one', 1000);
3
collection.set(2, 'two', 2000);
4
collection.set(3, 'three', 500);
5
const closestElement = collection.closer;
6
console.log(closestElement); // Output: { value: 'three', expire: 500, expireOn: [current timestamp + 500] }

Returns

undefined | LimitedCollectionData<V>

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

Source

seyfert/src/collection.ts:352


size

1
get size(): number

Returns the number of elements in the limited collection.

Example

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

Returns

number

The number of elements in the collection.

Source

seyfert/src/collection.ts:378

Methods

clear()

1
clear(): void

Returns

void

Source

seyfert/src/collection.ts:418


delete()

1
delete(key: K): boolean

Removes an element from the limited collection.

Parameters

ParameterTypeDescription
keyKThe key of the element to remove.

Returns

boolean

true if the element was removed, false otherwise.

Example

1
const collection = new LimitedCollection<number, string>();
2
collection.set(1, 'one');
3
console.log(collection.delete(1)); // Output: true
4
console.log(collection.delete(2)); // Output: false

Source

seyfert/src/collection.ts:332


entries()

1
entries(): IterableIterator<[K, LimitedCollectionData<V>]>

Returns

IterableIterator<[K, LimitedCollectionData<V>]>

Source

seyfert/src/collection.ts:414


get()

1
get(key: K): undefined | V

Returns the value of an element in the limited collection.

Parameters

ParameterTypeDescription
keyKThe key of the element.

Returns

undefined | V

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

Example

1
const collection = new LimitedCollection<number, string>();
2
collection.set(1, 'one');
3
const value = collection.get(1);
4
console.log(value); // Output: 'one'

Source

seyfert/src/collection.ts:296


has()

1
has(key: K): boolean

Checks if an element exists in the limited collection.

Parameters

ParameterTypeDescription
keyKThe key of the element.

Returns

boolean

true if the element exists, false otherwise.

Example

1
const collection = new LimitedCollection<number, string>();
2
collection.set(1, 'one');
3
console.log(collection.has(1)); // Output: true
4
console.log(collection.has(2)); // Output: false

Source

seyfert/src/collection.ts:318


keys()

1
keys(): () => IterableIterator<K>

Returns

Function

Returns an iterable of keys in the map

Returns

IterableIterator<K>

Source

seyfert/src/collection.ts:406


raw()

1
raw(key: K): undefined | LimitedCollectionData<V>

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

Parameters

ParameterTypeDescription
keyKThe key of the element.

Returns

undefined | LimitedCollectionData<V>

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

Example

1
const collection = new LimitedCollection<number, string>();
2
collection.set(1, 'one');
3
const rawData = collection.raw(1);
4
console.log(rawData); // Output: { value: 'one', expire: -1, expireOn: -1 }

Source

seyfert/src/collection.ts:282


set()

1
set(
2
key: K,
3
value: V,
4
customExpire: number): void

Adds an element to the limited collection.

Parameters

ParameterTypeDescription
keyKThe key of the element.
valueVThe value of the element.
customExpirenumberThe custom expiration time for the element.

Returns

void

Example

1
const collection = new LimitedCollection<number, string>({ limit: 3 });
2
collection.set(1, 'one');
3
collection.set(2, 'two');
4
collection.set(3, 'three');
5
console.log(collection.size); // Output: 3
6
collection.set(4, 'four');
7
console.log(collection.size); // Output: 3
8
console.log(collection.get(1)); // Output: undefined

Source

seyfert/src/collection.ts:248


values()

1
values(): () => IterableIterator<LimitedCollectionData<V>>

Returns

Function

Returns an iterable of values in the map

Returns

IterableIterator<LimitedCollectionData<V>>

Source

seyfert/src/collection.ts:410