seyfert
    Preparing search index...

    Class LimitedCollection<K, V>

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

    The function that produces an element of the new array.

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

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

    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']

    Type Parameters

    • K
    • V
    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    default: LimitedCollectionOptions<any, any> = ...

    Accessors

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

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

      Returns undefined | LimitedCollectionData<V>

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

      Returns the number of elements in the limited collection.

      Returns number

      The number of elements in the collection.

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

    Methods

    • Removes an element from the limited collection.

      Parameters

      • key: K

        The key of the element to remove.

      Returns boolean

      true if the element was removed, false otherwise.

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

    • Returns the value of an element in the limited collection.

      Parameters

      • key: K

        The key of the element.

      Returns undefined | V

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

      const collection = new LimitedCollection<number, string>();
      collection.set(1, 'one');
      const value = collection.get(1);
      console.log(value); // Output: 'one'
    • Checks if an element exists in the limited collection.

      Parameters

      • key: K

        The key of the element.

      Returns boolean

      true if the element exists, false otherwise.

      const collection = new LimitedCollection<number, string>();
      collection.set(1, 'one');
      console.log(collection.has(1)); // Output: true
      console.log(collection.has(2)); // Output: false
    • Returns the raw data of an element in the limited collection.

      Parameters

      • key: K

        The key of the element.

      Returns undefined | LimitedCollectionData<V>

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

      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 }
    • Adds an element to the limited collection.

      Parameters

      • key: K

        The key of the element.

      • value: V

        The value of the element.

      • customExpire: number = ...

        The custom expiration time for the element.

      Returns void

      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
    • Returns MapIterator<LimitedCollectionData<V>>