Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LifetimeCollection<K, V>

Type parameters

  • K

  • V

Hierarchy

  • Collection<K, V>
    • LifetimeCollection

Index

Constructors

constructor

  • new LifetimeCollection<K, V>(options?: LifetimeCollectionOptions): LifetimeCollection<K, V>

Properties

Readonly [toStringTag]

[toStringTag]: string

constructor

constructor: CollectionConstructor

Optional max

max: number

Optional maxAge

maxAge: number

Optional Readonly options

options: LifetimeCollectionOptions

Readonly size

size: number

Readonly timeouts

timeouts: Map<K, Timeout>

Static Readonly [species]

[species]: MapConstructor

Static Readonly default

default: typeof Collection

Methods

[iterator]

  • [iterator](): IterableIterator<[K, V]>
  • Returns an iterable of entries in the map.

    Returns IterableIterator<[K, V]>

clear

  • clear(): void

clone

  • clone(): Collection<K, V>
  • Creates an identical shallow copy of this collection.

    example

    const newColl = someColl.clone();

    Returns Collection<K, V>

concat

  • concat(...collections: Collection<K, V>[]): Collection<K, V>
  • Combines this collection with others into a new collection. None of the source collections are modified.

    example

    const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);

    Parameters

    • Rest ...collections: Collection<K, V>[]

      Collections to merge

    Returns Collection<K, V>

delete

  • delete(key: K): boolean

difference

  • difference(other: Collection<K, V>): Collection<K, V>
  • The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.

    Parameters

    • other: Collection<K, V>

      The other Collection to filter against

    Returns Collection<K, V>

each

  • Identical to Map.forEach(), but returns the collection instead of undefined.

    example

    collection .each(user => console.log(user.username)) .filter(user => user.bot) .each(user => console.log(user.username));

    Parameters

    Returns LifetimeCollection<K, V>

  • Type parameters

    • T

    Parameters

    Returns LifetimeCollection<K, V>

entries

  • entries(): IterableIterator<[K, V]>
  • Returns an iterable of key, value pairs for every entry in the map.

    Returns IterableIterator<[K, V]>

equals

  • equals(collection: Collection<K, V>): boolean
  • Checks if this collection shares identical items with another. This is different to checking for equality using equal-signs, because the collections may be different objects, but contain the same data.

    Parameters

    • collection: Collection<K, V>

      Collection to compare with

    Returns boolean

    Whether the collections have identical contents

every

  • every<K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2): this is Collection<K2, V>
  • every<V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2): this is Collection<K, V2>
  • every(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): boolean
  • every<This, K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2, thisArg: This): this is Collection<K2, V>
  • every<This, V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2, thisArg: This): this is Collection<K, V2>
  • every<This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: This): boolean
  • Checks if all items passes a test. Identical in behavior to Array.every().

    example

    collection.every(user => !user.bot);

    Type parameters

    • K2

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2

      Function used to test (should return a boolean)

    Returns this is Collection<K2, V>

  • Type parameters

    • V2

    Parameters

    Returns this is Collection<K, V2>

  • Parameters

    Returns boolean

  • Type parameters

    • This

    • K2

    Parameters

    Returns this is Collection<K2, V>

  • Type parameters

    • This

    • V2

    Parameters

    Returns this is Collection<K, V2>

  • Type parameters

    • This

    Parameters

    Returns boolean

filter

  • filter<K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2): Collection<K2, V>
  • filter<V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2): Collection<K, V2>
  • filter(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): Collection<K, V>
  • filter<This, K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2, thisArg: This): Collection<K2, V>
  • filter<This, V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2, thisArg: This): Collection<K, V2>
  • filter<This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: This): Collection<K, V>
  • Identical to Array.filter(), but returns a Collection instead of an Array.

    example

    collection.filter(user => user.username === 'Bob');

    Type parameters

    • K2

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2

      The function to test with (should return boolean)

    Returns Collection<K2, V>

  • Type parameters

    • V2

    Parameters

    Returns Collection<K, V2>

  • Parameters

    Returns Collection<K, V>

  • Type parameters

    • This

    • K2

    Parameters

    Returns Collection<K2, V>

  • Type parameters

    • This

    • V2

    Parameters

    Returns Collection<K, V2>

  • Type parameters

    • This

    Parameters

    Returns Collection<K, V>

find

  • find<V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2): undefined | V2
  • find(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): undefined | V
  • find<This, V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2, thisArg: This): undefined | V2
  • find<This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: This): undefined | V
  • Searches for a single item where the given function returns a truthy value. This behaves like Array.find(). All collections used in Discord.js are mapped using their id property, and if you want to find by id you should use the get method. See MDN for details.

    example

    collection.find(user => user.username === 'Bob');

    Type parameters

    • V2

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2

      The function to test with (should return boolean)

    Returns undefined | V2

  • Parameters

    Returns undefined | V

  • Type parameters

    • This

    • V2

    Parameters

    Returns undefined | V2

  • Type parameters

    • This

    Parameters

    Returns undefined | V

findKey

  • findKey<K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2): undefined | K2
  • findKey(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): undefined | K
  • findKey<This, K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2, thisArg: This): undefined | K2
  • findKey<This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: This): undefined | K
  • Searches for the key of a single item where the given function returns a truthy value. This behaves like Array.findIndex(), but returns the key rather than the positional index.

    example

    collection.findKey(user => user.username === 'Bob');

    Type parameters

    • K2

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2

      The function to test with (should return boolean)

    Returns undefined | K2

  • Parameters

    Returns undefined | K

  • Type parameters

    • This

    • K2

    Parameters

    Returns undefined | K2

  • Type parameters

    • This

    Parameters

    Returns undefined | K

first

  • first(): undefined | V
  • first(amount: number): V[]
  • Obtains the first value(s) in this collection.

    Returns undefined | V

    A single value if no amount is provided or an array of values, starting from the end if amount is negative

  • Parameters

    • amount: number

    Returns V[]

firstKey

  • firstKey(): undefined | K
  • firstKey(amount: number): K[]
  • Obtains the first key(s) in this collection.

    Returns undefined | K

    A single key if no amount is provided or an array of keys, starting from the end if amount is negative

  • Parameters

    • amount: number

    Returns K[]

flatMap

  • flatMap<T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => Collection<K, T>): Collection<K, T>
  • flatMap<T, This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => Collection<K, T>, thisArg: This): Collection<K, T>
  • Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().

    example

    collection.flatMap(guild => guild.members.cache);

    Type parameters

    • T

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => Collection<K, T>

      Function that produces a new Collection

    Returns Collection<K, T>

  • Type parameters

    • T

    • This

    Parameters

    Returns Collection<K, T>

forEach

  • forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void
  • Parameters

    • callbackfn: (value: V, key: K, map: Map<K, V>) => void
        • (value: V, key: K, map: Map<K, V>): void
        • Parameters

          • value: V
          • key: K
          • map: Map<K, V>

          Returns void

    • Optional thisArg: any

    Returns void

get

  • get(key: K): undefined | V
  • Identical to Map.get(). Gets an element with the specified key, and returns its value, or undefined if the element does not exist.

    Parameters

    • key: K

      The key to get from this collection

    Returns undefined | V

has

  • has(key: K): boolean
  • Identical to Map.has(). Checks if an element exists in the collection.

    Parameters

    • key: K

      The key of the element to check for

    Returns boolean

    true if the element exists, false if it does not exist.

hasAll

  • hasAll(...keys: K[]): boolean
  • Checks if all of the elements exist in the collection.

    Parameters

    • Rest ...keys: K[]

      The keys of the elements to check for

    Returns boolean

    true if all of the elements exist, false if at least one does not exist.

hasAny

  • hasAny(...keys: K[]): boolean
  • Checks if any of the elements exist in the collection.

    Parameters

    • Rest ...keys: K[]

      The keys of the elements to check for

    Returns boolean

    true if any of the elements exist, false if none exist.

intersect

  • intersect(other: Collection<K, V>): Collection<K, V>
  • The intersect method returns a new structure containing items where the keys are present in both original structures.

    Parameters

    • other: Collection<K, V>

      The other Collection to filter against

    Returns Collection<K, V>

keys

  • keys(): IterableIterator<K>
  • Returns an iterable of keys in the map

    Returns IterableIterator<K>

last

  • last(): undefined | V
  • last(amount: number): V[]
  • Obtains the last value(s) in this collection.

    Returns undefined | V

    A single value if no amount is provided or an array of values, starting from the start if amount is negative

  • Parameters

    • amount: number

    Returns V[]

lastKey

  • lastKey(): undefined | K
  • lastKey(amount: number): K[]
  • Obtains the last key(s) in this collection.

    Returns undefined | K

    A single key if no amount is provided or an array of keys, starting from the start if amount is negative

  • Parameters

    • amount: number

    Returns K[]

map

  • map<T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T): T[]
  • map<This, T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T, thisArg: This): T[]
  • Maps each item to another value into an array. Identical in behavior to Array.map().

    example

    collection.map(user => user.tag);

    Type parameters

    • T

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T

      Function that produces an element of the new array, taking three arguments

    Returns T[]

  • Type parameters

    • This

    • T

    Parameters

    Returns T[]

mapValues

  • mapValues<T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T): Collection<K, T>
  • mapValues<This, T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T, thisArg: This): Collection<K, T>
  • Maps each item to another value into a collection. Identical in behavior to Array.map().

    example

    collection.mapValues(user => user.tag);

    Type parameters

    • T

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => T

      Function that produces an element of the new collection, taking three arguments

    Returns Collection<K, T>

  • Type parameters

    • This

    • T

    Parameters

    Returns Collection<K, T>

partition

  • partition<K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]
  • partition<V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]
  • partition(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): [Collection<K, V>, Collection<K, V>]
  • partition<This, K2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2, thisArg: This): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]
  • partition<This, V2>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => value is V2, thisArg: This): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]
  • partition<This>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: This): [Collection<K, V>, Collection<K, V>]
  • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

    example

    const [big, small] = collection.partition(guild => guild.memberCount > 250);

    Type parameters

    • K2

    Parameters

    • fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => key is K2

      Function used to test (should return a boolean)

    Returns [Collection<K2, V>, Collection<Exclude<K, K2>, V>]

  • Type parameters

    • V2

    Parameters

    Returns [Collection<K, V2>, Collection<K, Exclude<V, V2>>]

  • Parameters

    Returns [Collection<K, V>, Collection<K, V>]

  • Type parameters

    • This

    • K2

    Parameters

    Returns [Collection<K2, V>, Collection<Exclude<K, K2>, V>]

  • Type parameters

    • This

    • V2

    Parameters

    Returns [Collection<K, V2>, Collection<K, Exclude<V, V2>>]

  • Type parameters

    • This

    Parameters

    Returns [Collection<K, V>, Collection<K, V>]

random

  • random(): V
  • random(amount: number): V[]
  • Obtains unique random value(s) from this collection.

    Returns V

    A single value if no amount is provided or an array of values

  • Parameters

    • amount: number

    Returns V[]

randomKey

  • randomKey(): K
  • randomKey(amount: number): K[]
  • Obtains unique random key(s) from this collection.

    Returns K

    A single key if no amount is provided or an array

  • Parameters

    • amount: number

    Returns K[]

reduce

  • reduce<T>(fn: (accumulator: T, value: V, key: K, collection: LifetimeCollection<K, V>) => T, initialValue?: T): T
  • Applies a function to produce a single value. Identical in behavior to Array.reduce().

    example

    collection.reduce((acc, guild) => acc + guild.memberCount, 0);

    Type parameters

    • T

    Parameters

    • fn: (accumulator: T, value: V, key: K, collection: LifetimeCollection<K, V>) => T

      Function used to reduce, taking four arguments; accumulator, currentValue, currentKey, and collection

    • Optional initialValue: T

    Returns T

set

some

  • some(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean): boolean
  • some<T>(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg: T): boolean
  • Checks if there exists an item that passes a test. Identical in behavior to Array.some().

    example

    collection.some(user => user.discriminator === '0000');

    Parameters

    Returns boolean

  • Type parameters

    • T

    Parameters

    Returns boolean

sort

  • The sort method sorts the items of a collection in place and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.

    example

    collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);

    Parameters

    • Optional compareFunction: Comparator<K, V>

    Returns LifetimeCollection<K, V>

sorted

  • sorted(compareFunction?: Comparator<K, V>): Collection<K, V>
  • The sorted method sorts the items of a collection and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.

    example

    collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);

    Parameters

    • Optional compareFunction: Comparator<K, V>

    Returns Collection<K, V>

sweep

  • sweep(fn: (value: V, key: K, collection: LifetimeCollection<K, V>) => boolean, thisArg?: unknown): number

tap

  • Runs a function on the collection and returns the collection.

    example

    collection .tap(coll => console.log(coll.size)) .filter(user => user.bot) .tap(coll => console.log(coll.size))

    Parameters

    Returns LifetimeCollection<K, V>

  • Type parameters

    • T

    Parameters

    Returns LifetimeCollection<K, V>

toJSON

  • toJSON(): V[]
  • Returns V[]

values

  • values(): IterableIterator<V>
  • Returns an iterable of values in the map

    Returns IterableIterator<V>

Generated using TypeDoc