Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection<K, V>

A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has an ID, for significantly improved performance and ease-of-use.

Type Parameters

  • K

  • V

Hierarchy

Index

Constructors

  • new Collection<K, V>(entries?: null | readonly (readonly [K, V])[]): Collection<K, V>
  • new Collection<K, V>(iterable?: null | Iterable<readonly [K, V]>): Collection<K, V>
  • Type Parameters

    • K

    • V

    Parameters

    • Optional entries: null | readonly (readonly [K, V])[]

    Returns Collection<K, V>

  • Type Parameters

    • K

    • V

    Parameters

    • Optional iterable: null | Iterable<readonly [K, V]>

    Returns Collection<K, V>

Properties

[toStringTag]: string
constructor: CollectionConstructor
size: number
[species]: MapConstructor
default: typeof Collection
defaultSort: any

Methods

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

    Returns IterableIterator<[K, V]>

  • at(index: number): undefined | V
  • Identical to Array.at(). Returns the item at a given index, allowing for positive and negative integers. Negative integers count back from the last item in the collection.

    Parameters

    • index: number

      The index of the element to obtain

    Returns undefined | V

  • clear(): void
  • Returns void

  • Creates an identical shallow copy of this collection.

    example

    const newColl = someColl.clone();

    Returns Collection<K, V>

  • concat(...collections: ReadonlyCollection<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: ReadonlyCollection<K, V>[]

      Collections to merge

    Returns Collection<K, V>

  • delete(key: K): boolean
  • Parameters

    • key: K

    Returns boolean

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

    Type Parameters

    • T

    Parameters

    • other: ReadonlyCollection<K, T>

      The other Collection to filter against

    Returns Collection<K, V | T>

  • 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

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

      Function to execute for each element

        • (value: V, key: K, collection: Collection<K, V>): void
        • Parameters

          Returns void

    Returns Collection<K, V>

  • Type Parameters

    • T

    Parameters

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

          Returns void

    • thisArg: T

    Returns Collection<K, V>

  • ensure(key: K, defaultValueGenerator: ((key: K, collection: Collection<K, V>) => V)): V
  • Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.

    example

    collection.ensure(guildId, () => defaultGuildConfig);

    Parameters

    • key: K

      The key to get if it exists, or set otherwise

    • defaultValueGenerator: ((key: K, collection: Collection<K, V>) => V)

      A function that generates the default value

    Returns V

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

    Returns IterableIterator<[K, V]>

  • equals(collection: ReadonlyCollection<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: ReadonlyCollection<K, V>

      Collection to compare with

    Returns boolean

    Whether the collections have identical contents

  • every<K2>(fn: ((value: V, key: K, collection: Collection<K, V>) => key is K2)): this is Collection<K2, V>
  • every<V2>(fn: ((value: V, key: K, collection: Collection<K, V>) => value is V2)): this is Collection<K, V2>
  • every(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): boolean
  • every<This, K2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2), thisArg: This): this is Collection<K2, V>
  • every<This, V2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2), thisArg: This): this is Collection<K, V2>
  • every<This>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => key is K2)

      Function used to test (should return a boolean)

        • (value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          Returns key is K2

    Returns this is Collection<K2, V>

  • Type Parameters

    • V2

    Parameters

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

          Returns value is V2

    Returns this is Collection<K, V2>

  • Parameters

    • fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)
        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns boolean

  • Type Parameters

    • This

    • K2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns key is K2

    • thisArg: This

    Returns this is Collection<K2, V>

  • Type Parameters

    • This

    • V2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): value is V2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns value is V2

    • thisArg: This

    Returns this is Collection<K, V2>

  • Type Parameters

    • This

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => boolean)
        • (this: This, value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns boolean

    • thisArg: This

    Returns boolean

  • filter<K2>(fn: ((value: V, key: K, collection: Collection<K, V>) => key is K2)): Collection<K2, V>
  • filter<V2>(fn: ((value: V, key: K, collection: Collection<K, V>) => value is V2)): Collection<K, V2>
  • filter(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): Collection<K, V>
  • filter<This, K2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2), thisArg: This): Collection<K2, V>
  • filter<This, V2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2), thisArg: This): Collection<K, V2>
  • filter<This>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => key is K2)

      The function to test with (should return boolean)

        • (value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          Returns key is K2

    Returns Collection<K2, V>

  • Type Parameters

    • V2

    Parameters

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

          Returns value is V2

    Returns Collection<K, V2>

  • Parameters

    • fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)
        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns Collection<K, V>

  • Type Parameters

    • This

    • K2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns key is K2

    • thisArg: This

    Returns Collection<K2, V>

  • Type Parameters

    • This

    • V2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): value is V2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns value is V2

    • thisArg: This

    Returns Collection<K, V2>

  • Type Parameters

    • This

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => boolean)
        • (this: This, value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns boolean

    • thisArg: This

    Returns Collection<K, V>

  • find<V2>(fn: ((value: V, key: K, collection: Collection<K, V>) => value is V2)): undefined | V2
  • find(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): undefined | V
  • find<This, V2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2), thisArg: This): undefined | V2
  • find<This>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => value is V2)

      The function to test with (should return boolean)

        • (value: V, key: K, collection: Collection<K, V>): value is V2
        • Parameters

          Returns value is V2

    Returns undefined | V2

  • Parameters

    • fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)
        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns undefined | V

  • Type Parameters

    • This

    • V2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): value is V2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns value is V2

    • thisArg: This

    Returns undefined | V2

  • Type Parameters

    • This

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => boolean)
        • (this: This, value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns boolean

    • thisArg: This

    Returns undefined | V

  • findKey<K2>(fn: ((value: V, key: K, collection: Collection<K, V>) => key is K2)): undefined | K2
  • findKey(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): undefined | K
  • findKey<This, K2>(fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2), thisArg: This): undefined | K2
  • findKey<This>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => key is K2)

      The function to test with (should return boolean)

        • (value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          Returns key is K2

    Returns undefined | K2

  • Parameters

    • fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)
        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns undefined | K

  • Type Parameters

    • This

    • K2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns key is K2

    • thisArg: This

    Returns undefined | K2

  • Type Parameters

    • This

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => boolean)
        • (this: This, value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns boolean

    • thisArg: This

    Returns undefined | K

  • 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(): 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[]

  • 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

    Returns Collection<K, T>

  • Type Parameters

    • T

    • This

    Parameters

    Returns Collection<K, T>

  • 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(key: K): undefined | V
  • Parameters

    • key: K

    Returns undefined | V

  • has(key: K): boolean
  • Parameters

    • key: K

    Returns boolean

  • 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(...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<T>(other: ReadonlyCollection<K, T>): Collection<K, T>
  • The intersect method returns a new structure containing items where the keys and values are present in both original structures.

    Type Parameters

    • T

    Parameters

    • other: ReadonlyCollection<K, T>

      The other Collection to filter against

    Returns Collection<K, T>

  • keyAt(index: number): undefined | K
  • Identical to Array.at(). Returns the key at a given index, allowing for positive and negative integers. Negative integers count back from the last item in the collection.

    Parameters

    • index: number

      The index of the key to obtain

    Returns undefined | K

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

    Returns IterableIterator<K>

  • 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(): 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<T>(fn: ((value: V, key: K, collection: Collection<K, V>) => T)): T[]
  • map<This, T>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => T)

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

        • (value: V, key: K, collection: Collection<K, V>): T
        • Parameters

          Returns T

    Returns T[]

  • Type Parameters

    • This

    • T

    Parameters

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

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns T

    • thisArg: This

    Returns T[]

  • mapValues<T>(fn: ((value: V, key: K, collection: Collection<K, V>) => T)): Collection<K, T>
  • mapValues<This, T>(fn: ((this: This, value: V, key: K, collection: Collection<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: Collection<K, V>) => T)

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

        • (value: V, key: K, collection: Collection<K, V>): T
        • Parameters

          Returns T

    Returns Collection<K, T>

  • Type Parameters

    • This

    • T

    Parameters

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

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns T

    • thisArg: This

    Returns Collection<K, T>

  • merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: ((value: V, key: K) => Keep<R>), whenInOther: ((valueOther: T, key: K) => Keep<R>), whenInBoth: ((value: V, valueOther: T, key: K) => Keep<R>)): Collection<K, R>
  • Merges two Collections together into a new Collection.

    example

    // Sums up the entries in two collections. coll.merge( other, x => ({ keep: true, value: x }), y => ({ keep: true, value: y }), (x, y) => ({ keep: true, value: x + y }), );

    example

    // Intersects two collections in a left-biased manner. coll.merge( other, x => ({ keep: false }), y => ({ keep: false }), (x, _) => ({ keep: true, value: x }), );

    Type Parameters

    • T

    • R

    Parameters

    • other: ReadonlyCollection<K, T>

      The other Collection to merge with

    • whenInSelf: ((value: V, key: K) => Keep<R>)

      Function getting the result if the entry only exists in this Collection

        • (value: V, key: K): Keep<R>
        • Parameters

          • value: V
          • key: K

          Returns Keep<R>

    • whenInOther: ((valueOther: T, key: K) => Keep<R>)

      Function getting the result if the entry only exists in the other Collection

        • (valueOther: T, key: K): Keep<R>
        • Parameters

          • valueOther: T
          • key: K

          Returns Keep<R>

    • whenInBoth: ((value: V, valueOther: T, key: K) => Keep<R>)

      Function getting the result if the entry exists in both Collections

        • (value: V, valueOther: T, key: K): Keep<R>
        • Parameters

          • value: V
          • valueOther: T
          • key: K

          Returns Keep<R>

    Returns Collection<K, R>

  • 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: Collection<K, V>) => key is K2)

      Function used to test (should return a boolean)

        • (value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          Returns key is K2

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

  • Type Parameters

    • V2

    Parameters

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

          Returns value is V2

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

  • Parameters

    • fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)
        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

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

  • Type Parameters

    • This

    • K2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => key is K2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): key is K2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns key is K2

    • thisArg: This

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

  • Type Parameters

    • This

    • V2

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => value is V2)
        • (this: This, value: V, key: K, collection: Collection<K, V>): value is V2
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns value is V2

    • thisArg: This

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

  • Type Parameters

    • This

    Parameters

    • fn: ((this: This, value: V, key: K, collection: Collection<K, V>) => boolean)
        • (this: This, value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          • this: This
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns boolean

    • thisArg: This

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

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

    Returns undefined | V

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

  • Parameters

    • amount: number

    Returns V[]

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

    Returns undefined | K

    A single key if no amount is provided or an array

  • Parameters

    • amount: number

    Returns K[]

  • reduce<T>(fn: ((accumulator: T, value: V, key: K, collection: Collection<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: Collection<K, V>) => T)

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

        • (accumulator: T, value: V, key: K, collection: Collection<K, V>): T
        • Parameters

          • accumulator: T
          • value: V
          • key: K
          • collection: Collection<K, V>

          Returns T

    • Optional initialValue: T

      Starting value for the accumulator

    Returns T

  • Identical to Array.reverse() but returns a Collection instead of an Array.

    Returns Collection<K, V>

  • Parameters

    • key: K
    • value: V

    Returns Collection<K, V>

  • some(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): boolean
  • some<T>(fn: ((this: T, value: V, key: K, collection: Collection<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

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

      Function used to test (should return a boolean)

        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns boolean

  • Type Parameters

    • T

    Parameters

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

          Returns boolean

    • thisArg: T

    Returns boolean

  • sort(compareFunction?: Comparator<K, V>): Collection<K, V>
  • 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>

      Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.

    Returns Collection<K, V>

  • 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>

      Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.

    Returns Collection<K, V>

  • sweep(fn: ((value: V, key: K, collection: Collection<K, V>) => boolean)): number
  • sweep<T>(fn: ((this: T, value: V, key: K, collection: Collection<K, V>) => boolean), thisArg: T): number
  • Removes items that satisfy the provided filter function.

    Parameters

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

      Function used to test (should return a boolean)

        • (value: V, key: K, collection: Collection<K, V>): boolean
        • Parameters

          Returns boolean

    Returns number

    The number of removed entries

  • Type Parameters

    • T

    Parameters

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

          Returns boolean

    • thisArg: T

    Returns number

  • 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

    • fn: ((collection: Collection<K, V>) => void)

      Function to execute

    Returns Collection<K, V>

  • Type Parameters

    • T

    Parameters

    • fn: ((this: T, collection: Collection<K, V>) => void)
        • Parameters

          Returns void

    • thisArg: T

    Returns Collection<K, V>

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

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

    Returns IterableIterator<V>

  • combineEntries<K, V>(entries: Iterable<[K, V]>, combine: ((firstValue: V, secondValue: V, key: K) => V)): Collection<K, V>
  • Creates a Collection from a list of entries.

    example

    Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); // returns Collection { "a" => 3, "b" => 2 }

    Type Parameters

    • K

    • V

    Parameters

    • entries: Iterable<[K, V]>

      The list of entries

    • combine: ((firstValue: V, secondValue: V, key: K) => V)

      Function to combine an existing entry with a new one

        • (firstValue: V, secondValue: V, key: K): V
        • Parameters

          • firstValue: V
          • secondValue: V
          • key: K

          Returns V

    Returns Collection<K, V>

Generated using TypeDoc version 0.22.16, the 9/16/2022 at 1:09:15 AM