@tanzanite/discord-akairo
    Preparing search index...

    Class Category<K, V>

    A group of modules.

    Type Parameters

    Hierarchy

    • Collection<K, V>
      • Category
    Index

    Constructors

    • Type Parameters

      Parameters

      • id: string

        ID of the category.

      • Optionaliterable: Iterable<readonly [K, V], any, any>

        Entries to set.

      Returns Category<K, V>

    Properties

    "[toStringTag]": string
    constructor: CollectionConstructor

    The initial value of Object.prototype.constructor is the standard built-in Object constructor.

    id: string

    ID of the category.

    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    Methods

    • Returns an iterable of entries in the map.

      Returns MapIterator<[K, 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

    • Returns void

    • Creates an identical shallow copy of this collection.

      Returns Collection<K, V>

      const newColl = someColl.clone();
      
    • Combines this collection with others into a new collection. None of the source collections are modified.

      Parameters

      • ...collections: ReadonlyCollection<K, V>[]

        Collections to merge

      Returns Collection<K, V>

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

      • key: K

      Returns boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Returns a new collection containing the items where the key is present in this collection but not the other.

      Parameters

      • other: ReadonlyCollection<K, any>

        The other Collection to filter against

      Returns Collection<K, V>

      const col1 = new Collection([['a', 1], ['b', 2]]);
      const col2 = new Collection([['a', 1], ['c', 3]]);
      console.log(col1.difference(col2));
      // => Collection { 'b' => 2 }
      console.log(col2.difference(col1));
      // => Collection { 'c' => 3 }
    • Identical to Map.forEach(), but returns the collection instead of undefined.

      Parameters

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

        Function to execute for each element

      Returns this

      collection
      .each(user => console.log(user.username))
      .filter(user => user.bot)
      .each(user => console.log(user.username));
    • Identical to Map.forEach(), but returns the collection instead of undefined.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => void

        Function to execute for each element

      • thisArg: This

        Value to use as this when executing the function

      Returns this

      collection
      .each(user => console.log(user.username))
      .filter(user => user.bot)
      .each(user => console.log(user.username));
    • Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.

      Parameters

      • key: K

        The key to get if it exists, or set otherwise

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

        A function that generates the default value

      Returns V

      collection.ensure(guildId, () => defaultGuildConfig);
      
    • Returns an iterable of key, value pairs for every entry in the map.

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

      Parameters

      • collection: ReadonlyCollection<K, V>

        Collection to compare with

      Returns boolean

      Whether the collections have identical contents

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

      Type Parameters

      • NewKey extends string

      Parameters

      • fn: (value: V, key: K, collection: this) => key is NewKey

        Function used to test (should return a boolean)

      Returns this is Collection<NewKey, V>

      collection.every(user => !user.bot);
      
    • Checks if all items passes a test. Identical in behavior to Array.every().

      Type Parameters

      Parameters

      • fn: (value: V, key: K, collection: this) => value is NewValue

        Function used to test (should return a boolean)

      Returns this is Collection<K, NewValue>

      collection.every(user => !user.bot);
      
    • Checks if all items passes a test. Identical in behavior to Array.every().

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      Returns boolean

      collection.every(user => !user.bot);
      
    • Checks if all items passes a test. Identical in behavior to Array.every().

      Type Parameters

      • This
      • NewKey extends string

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => key is NewKey

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns this is Collection<NewKey, V>

      collection.every(user => !user.bot);
      
    • Checks if all items passes a test. Identical in behavior to Array.every().

      Type Parameters

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => value is NewValue

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns this is Collection<K, NewValue>

      collection.every(user => !user.bot);
      
    • Checks if all items passes a test. Identical in behavior to Array.every().

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns boolean

      collection.every(user => !user.bot);
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Type Parameters

      • NewKey extends string

      Parameters

      • fn: (value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      Returns Collection<NewKey, V>

      collection.filter(user => user.username === 'Bob');
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Type Parameters

      Parameters

      • fn: (value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      Returns Collection<K, NewValue>

      collection.filter(user => user.username === 'Bob');
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      Returns Collection<K, V>

      collection.filter(user => user.username === 'Bob');
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Type Parameters

      • This
      • NewKey extends string

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns Collection<NewKey, V>

      collection.filter(user => user.username === 'Bob');
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Type Parameters

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns Collection<K, NewValue>

      collection.filter(user => user.username === 'Bob');
      
    • Identical to Array.filter(), but returns a Collection instead of an Array.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns Collection<K, V>

      collection.filter(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      Parameters

      • fn: (value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      Returns undefined | NewValue

      collection.find(user => user.username === 'Bob');
      
    • 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.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      Returns undefined | V

      collection.find(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | NewValue

      collection.find(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | V

      collection.find(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      • NewKey extends string

      Parameters

      • fn: (value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      Returns undefined | NewKey

      collection.findKey(user => user.username === 'Bob');
      
    • 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.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      Returns undefined | K

      collection.findKey(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      • This
      • NewKey extends string

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | NewKey

      collection.findKey(user => user.username === 'Bob');
      
    • 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.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | K

      collection.findKey(user => user.username === 'Bob');
      
    • Searches for a last item where the given function returns a truthy value. This behaves like Array.findLast().

      Type Parameters

      Parameters

      • fn: (value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      Returns undefined | NewValue

    • Searches for a last item where the given function returns a truthy value. This behaves like Array.findLast().

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      Returns undefined | V

    • Searches for a last item where the given function returns a truthy value. This behaves like Array.findLast().

      Type Parameters

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => value is NewValue

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | NewValue

    • Searches for a last item where the given function returns a truthy value. This behaves like Array.findLast().

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | V

    • Searches for the key of a last item where the given function returns a truthy value. This behaves like Array.findLastIndex(), but returns the key rather than the positional index.

      Type Parameters

      • NewKey extends string

      Parameters

      • fn: (value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      Returns undefined | NewKey

    • Searches for the key of a last item where the given function returns a truthy value. This behaves like Array.findLastIndex(), but returns the key rather than the positional index.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      Returns undefined | K

    • Searches for the key of a last item where the given function returns a truthy value. This behaves like Array.findLastIndex(), but returns the key rather than the positional index.

      Type Parameters

      • This
      • NewKey extends string

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => key is NewKey

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | NewKey

    • Searches for the key of a last item where the given function returns a truthy value. This behaves like Array.findLastIndex(), but returns the key rather than the positional index.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        The function to test with (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns undefined | K

    • 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

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

      Parameters

      • amount: number

        Amount of values to obtain from the beginning

      Returns V[]

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

    • 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

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

      Parameters

      • amount: number

        Amount of keys to obtain from the beginning

      Returns K[]

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

    • Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().

      Type Parameters

      • NewValue

      Parameters

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

        Function that produces a new Collection

      Returns Collection<K, NewValue>

      collection.flatMap(guild => guild.members.cache);
      
    • Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().

      Type Parameters

      • NewValue
      • This

      Parameters

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

        Function that produces a new Collection

      • thisArg: This

        Value to use as this when executing the function

      Returns Collection<K, NewValue>

      collection.flatMap(guild => guild.members.cache);
      
    • 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
      • OptionalthisArg: any

      Returns void

    • Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

      Parameters

      • key: K

      Returns undefined | V

      Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

    • Parameters

      • key: K

      Returns boolean

      boolean indicating whether an element with the specified key exists or not.

    • Checks if all of the elements exist in the collection.

      Parameters

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

    • Checks if any of the elements exist in the collection.

      Parameters

      • ...keys: K[]

        The keys of the elements to check for

      Returns boolean

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

    • The intersection method returns a new collection containing the items where the key is present in both collections.

      Parameters

      • other: ReadonlyCollection<K, any>

        The other Collection to filter against

      Returns Collection<K, V>

      const col1 = new Collection([['a', 1], ['b', 2]]);
      const col2 = new Collection([['a', 1], ['c', 3]]);
      const intersection = col1.intersection(col2);
      console.log(col1.intersection(col2));
      // => Collection { 'a' => 1 }
    • 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

    • Returns an iterable of keys in the map

      Returns MapIterator<K>

    • 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

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

      Parameters

      • amount: number

        Amount of values to obtain from the end

      Returns V[]

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

    • 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

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

      Parameters

      • amount: number

        Amount of keys to obtain from the end

      Returns K[]

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

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

      Type Parameters

      • NewValue

      Parameters

      • fn: (value: V, key: K, collection: this) => NewValue

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

      Returns NewValue[]

      collection.map(user => user.tag);
      
    • Maps each item to another value into an array. Identical in behavior to Array.map().

      Type Parameters

      • This
      • NewValue

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => NewValue

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

      • thisArg: This

        Value to use as this when executing the function

      Returns NewValue[]

      collection.map(user => user.tag);
      
    • Maps each item to another value into a collection. Identical in behavior to Array.map().

      Type Parameters

      • NewValue

      Parameters

      • fn: (value: V, key: K, collection: this) => NewValue

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

      Returns Collection<K, NewValue>

      collection.mapValues(user => user.tag);
      
    • Maps each item to another value into a collection. Identical in behavior to Array.map().

      Type Parameters

      • This
      • NewValue

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => NewValue

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

      • thisArg: This

        Value to use as this when executing the function

      Returns Collection<K, NewValue>

      collection.mapValues(user => user.tag);
      
    • Merges two Collections together into a new Collection.

      Type Parameters

      • OtherValue
      • ResultValue

      Parameters

      • other: ReadonlyCollection<K, OtherValue>

        The other Collection to merge with

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

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

      • whenInOther: (valueOther: OtherValue, key: K) => Keep<ResultValue>

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

      • whenInBoth: (value: V, valueOther: OtherValue, key: K) => Keep<ResultValue>

        Function getting the result if the entry exists in both Collections

      Returns Collection<K, ResultValue>

      // 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 }),
      );
      // Intersects two collections in a left-biased manner.
      coll.merge(
      other,
      x => ({ keep: false }),
      y => ({ keep: false }),
      (x, _) => ({ keep: true, value: x }),
      );
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Type Parameters

      • NewKey extends string

      Parameters

      • fn: (value: V, key: K, collection: this) => key is NewKey

        Function used to test (should return a boolean)

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Type Parameters

      Parameters

      • fn: (value: V, key: K, collection: this) => value is NewValue

        Function used to test (should return a boolean)

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Type Parameters

      • This
      • NewKey extends string

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => key is NewKey

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Type Parameters

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => value is NewValue

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

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

      const [big, small] = collection.partition(guild => guild.memberCount > 250);
      
    • Obtains unique random value(s) from this collection.

      Returns undefined | V

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

    • Obtains unique random value(s) from this collection.

      Parameters

      • amount: number

        Amount of values to obtain randomly

      Returns V[]

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

    • Obtains unique random key(s) from this collection.

      Returns undefined | K

      A single key if no amount is provided or an array

    • Obtains unique random key(s) from this collection.

      Parameters

      • amount: number

        Amount of keys to obtain randomly

      Returns K[]

      A single key if no amount is provided or an array

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

      Parameters

      • fn: (accumulator: V, value: V, key: K, collection: this) => V

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

      • OptionalinitialValue: V

        Starting value for the accumulator

      Returns V

      collection.reduce((acc, guild) => acc + guild.memberCount, 0);
      
    • Applies a function to produce a single value. Identical in behavior to Array.reduce().

      Type Parameters

      • InitialValue

      Parameters

      • fn: (accumulator: InitialValue, value: V, key: K, collection: this) => InitialValue

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

      • initialValue: InitialValue

        Starting value for the accumulator

      Returns InitialValue

      collection.reduce((acc, guild) => acc + guild.memberCount, 0);
      
    • Applies a function to produce a single value. Identical in behavior to Array.reduceRight().

      Parameters

      • fn: (accumulator: V, value: V, key: K, collection: this) => V

        Function used to reduce, taking four arguments; accumulator, value, key, and collection

      • OptionalinitialValue: V

        Starting value for the accumulator

      Returns V

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

      Type Parameters

      • InitialValue

      Parameters

      • fn: (accumulator: InitialValue, value: V, key: K, collection: this) => InitialValue

        Function used to reduce, taking four arguments; accumulator, value, key, and collection

      • initialValue: InitialValue

        Starting value for the accumulator

      Returns InitialValue

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

      Returns this

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      Parameters

      • key: K
      • value: V

      Returns this

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

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      Returns boolean

      collection.some(user => user.discriminator === '0000');
      
    • Checks if there exists an item that passes a test. Identical in behavior to Array.some().

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns boolean

      collection.some(user => user.discriminator === '0000');
      
    • 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.

      Parameters

      • OptionalcompareFunction: 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 this

      collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
      
    • Removes items that satisfy the provided filter function.

      Parameters

      • fn: (value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      Returns number

      The number of removed entries

    • Removes items that satisfy the provided filter function.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, value: V, key: K, collection: this) => unknown

        Function used to test (should return a boolean)

      • thisArg: This

        Value to use as this when executing the function

      Returns number

      The number of removed entries

    • Returns a new collection containing only the items where the keys are present in either collection, but not both.

      Type Parameters

      • OtherValue

      Parameters

      • other: ReadonlyCollection<K, OtherValue>

        The other Collection to filter against

      Returns Collection<K, V | OtherValue>

      const col1 = new Collection([['a', 1], ['b', 2]]);
      const col2 = new Collection([['a', 1], ['c', 3]]);
      const symmetricDifference = col1.symmetricDifference(col2);
      console.log(col1.symmetricDifference(col2));
      // => Collection { 'b' => 2, 'c' => 3 }
    • Runs a function on the collection and returns the collection.

      Parameters

      • fn: (collection: this) => void

        Function to execute

      Returns this

      collection
      .tap(coll => console.log(coll.size))
      .filter(user => user.bot)
      .tap(coll => console.log(coll.size))
    • Runs a function on the collection and returns the collection.

      Type Parameters

      • This

      Parameters

      • fn: (this: This, collection: this) => void

        Function to execute

      • thisArg: This

        Value to use as this when executing the function

      Returns this

      collection
      .tap(coll => console.log(coll.size))
      .filter(user => user.bot)
      .tap(coll => console.log(coll.size))
    • Returns [K, V][]

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

      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.

      Parameters

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

      collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
      
    • Returns a new collection containing the items where the key is present in either of the collections.

      Type Parameters

      • OtherValue

      Parameters

      • other: ReadonlyCollection<K, OtherValue>

        The other Collection to filter against

      Returns Collection<K, V | OtherValue>

      If the collections have any items with the same key, the value from the first collection will be used.

      const col1 = new Collection([['a', 1], ['b', 2]]);
      const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
      const union = col1.union(col2);
      console.log(union);
      // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
    • Returns an iterable of values in the map

      Returns MapIterator<V>

    • Creates a Collection from a list of entries.

      Type Parameters

      • Key
      • Value

      Parameters

      • entries: Iterable<[Key, Value]>

        The list of entries

      • combine: (firstValue: Value, secondValue: Value, key: Key) => Value

        Function to combine an existing entry with a new one

      Returns Collection<Key, Value>

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