Type Parameters

  • K

  • V

Hierarchy

  • Collection<K, V>
    • Collection

Constructors

  • Type Parameters

    • K

    • V

    Parameters

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

    Returns Collection<K, V>

Methods

  • Type Parameters

    • T

    Parameters

    Returns Collection<K, T>

  • Type Parameters

    • T

    • This

    Parameters

    Returns Collection<K, T>

  • Type Parameters

    • T

    Parameters

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

          Returns T

    • Optional thisArg: unknown

    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>

  • Returns object

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

    Returns

    Parameters

    • key: K

      The key to get from this collection

    Returns undefined | V

  • Identical to Map.set(). Sets a new element in the collection with the specified key and value.

    Returns

    Parameters

    • key: K

      The key of the element to add

    • value: V

      The value of the element to add

    Returns Collection<K, V>

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

    Returns

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

    Parameters

    • key: K

      The key of the element to check for

    Returns boolean

  • Identical to Map.delete(). Deletes an element from the collection.

    Returns

    true if the element was removed, false if the element does not exist.

    Parameters

    • key: K

      The key to delete from the collection

    Returns boolean

  • Identical to Map.clear(). Removes all elements from the collection.

    Returns

    Returns void

  • Creates an ordered array of the values of this collection, and caches it internally. The array will only be reconstructed if an item is added to or removed from the collection, or if you change the length of the array itself. If you don't want this caching behavior, use [...collection.values()] or Array.from(collection.values()) instead.

    Returns

    Returns V[]

  • Creates an ordered array of the keys of this collection, and caches it internally. The array will only be reconstructed if an item is added to or removed from the collection, or if you change the length of the array itself. If you don't want this caching behavior, use [...collection.keys()] or Array.from(collection.keys()) instead.

    Returns

    Returns K[]

  • Obtains the first value(s) in this collection.

    Returns

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

    Returns undefined | V

  • Parameters

    • amount: number

    Returns V[]

  • Obtains the first key(s) in this collection.

    Returns

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

    Returns undefined | K

  • Parameters

    • amount: number

    Returns K[]

  • Obtains the last value(s) in this collection. This relies on array, and thus the caching mechanism applies here as well.

    Returns

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

    Returns undefined | V

  • Parameters

    • amount: number

    Returns V[]

  • Obtains the last key(s) in this collection. This relies on keyArray, and thus the caching mechanism applies here as well.

    Returns

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

    Returns undefined | K

  • Parameters

    • amount: number

    Returns K[]

  • Obtains unique random value(s) from this collection. This relies on array, and thus the caching mechanism applies here as well.

    Returns

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

    Returns V

  • Parameters

    • amount: number

    Returns V[]

  • Obtains unique random key(s) from this collection. This relies on keyArray, and thus the caching mechanism applies here as well.

    Returns

    A single key if no amount is provided or an array

    Returns K

  • Parameters

    • amount: number

    Returns K[]

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

    Returns

    Example

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

    Parameters

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

      The function to test with (should return boolean)

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

          Returns boolean

    Returns undefined | V

  • 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

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

          Returns boolean

    • thisArg: T

    Returns undefined | V

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

    Returns

    Example

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

    Parameters

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

      The function to test with (should return boolean)

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

          Returns boolean

    Returns undefined | K

  • 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

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

          Returns boolean

    • thisArg: T

    Returns undefined | K

  • Removes items that satisfy the provided filter function.

    Returns

    The number of removed entries

    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

  • 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

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

          Returns boolean

    • thisArg: T

    Returns number

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

    Returns

    Example

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

    Parameters

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

      The function to test with (should return boolean)

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

          Returns boolean

    Returns Collection<K, V>

  • 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

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

          Returns boolean

    • thisArg: T

    Returns 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.

    Returns

    Example

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

    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 [Collection<K, V>, Collection<K, V>]

  • 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

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

          Returns boolean

    • thisArg: T

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

  • Maps each item to another value into an array. Identical in behavior to Array.map().

    Returns

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

  • Checks if there exists an item that passes a test. Identical in behavior to Array.some().

    Returns

    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

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

          Returns boolean

    • thisArg: T

    Returns boolean

  • Checks if all items passes a test. Identical in behavior to Array.every().

    Returns

    Example

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

    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

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

          Returns boolean

    • thisArg: T

    Returns boolean

  • Applies a function to produce a single value. Identical in behavior to Array.reduce().

    Returns

    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 Map.forEach(), but returns the collection instead of undefined.

    Returns

    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

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

          Returns void

    • thisArg: T

    Returns Collection<K, V>

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

    Returns

    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)
        • (this: T, collection: Collection<K, V>): void
        • Parameters

          Returns void

    • thisArg: T

    Returns Collection<K, V>

  • Creates an identical shallow copy of this collection.

    Returns

    Example

    const newColl = someColl.clone();
    

    Returns Collection<K, V>

  • Combines this collection with others into a new collection. None of the source collections are modified.

    Returns

    Example

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

    Parameters

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

      Collections to merge

    Returns Collection<K, V>

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

    Returns

    Whether the collections have identical contents

    Parameters

    • collection: Collection<K, V>

      Collection to compare with

    Returns boolean

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

    Returns

    Example

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

    Parameters

    • Optional compareFunction: ((firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number)

      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.

        • (firstValue: V, secondValue: V, firstKey: K, secondKey: K): number
        • Parameters

          • firstValue: V
          • secondValue: V
          • firstKey: K
          • secondKey: K

          Returns number

    Returns Collection<K, V>

  • The intersect method returns a new structure containing items where the keys are present in both original structures.

    Returns

    Parameters

    • other: Collection<K, V>

      The other Collection to filter against

    Returns 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.

    Returns

    Parameters

    • other: Collection<K, V>

      The other Collection to filter against

    Returns 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.

    Returns

    Example

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

    Parameters

    • Optional compareFunction: ((firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number)

      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.

        • (firstValue: V, secondValue: V, firstKey: K, secondKey: K): number
        • Parameters

          • firstValue: V
          • secondValue: V
          • firstKey: K
          • secondKey: K

          Returns number

    Returns Collection<K, V>

  • Executes a provided function once per each key/value pair in the Map, in insertion order.

    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

  • Returns an iterable of key, value pairs for every entry in the map.

    Returns IterableIterator<[K, V]>

  • Returns an iterable of keys in the map

    Returns IterableIterator<K>

  • Returns an iterable of values in the map

    Returns IterableIterator<V>

  • Returns an iterable of entries in the map.

    Returns IterableIterator<[K, V]>

Properties

constructor: typeof Collection
size: number

Returns

the number of elements in the Map.

[toStringTag]: string
default: typeof Collection
[species]: MapConstructor

Generated using TypeDoc