class LimitedCollection
extends
Collection<Key, Value>export class LimitedCollection<Key, Value> extends Collection<Key, Value>
A Collection which holds a max amount of entries.
Type Parameters
Key
Value
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.
Inherited from: Collection
external cloneCollection<Key, Value> () :
Creates an identical shallow copy of this collection.
const newColl = someColl.clone();
Inherited from: Collection
staticexternal combineEntriesK
V
>(entries: Iterable<[Key, Value]>combine: (firstValue: Value, secondValue: Value, key: Key) => Value) : Collection<Key, Value> <
K
V
Creates a Collection from a list of entries.
Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
// returns Collection { "a" => 3, "b" => 2 }
Inherited from: Collection
external concat...collections: ReadonlyCollection<Key, Value>[]) : Collection<Key, Value> (
Combines this collection with others into a new collection. None of the source collections are modified.
const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
Inherited from: Collection
external differenceT
>(other: ReadonlyCollection<Key, T>) : Collection<Key, T | Value> <
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.
Inherited from: Collection
Identical to Map.forEach(), but returns the collection instead of undefined.
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.
collection.ensure(guildId, () => defaultGuildConfig);
Inherited from: Collection
external equalscollection: ReadonlyCollection<Key, Value>) : 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.
Returns: Whether the collections have identical contents
Inherited from: Collection
external everyK2 extends K
>() : this is Collection<K2, V> <
K2 extends K
Checks if all items passes a test. Identical in behavior to Array.every().
collection.every(user => !user.bot);
external filterK2 extends K
>() : Collection<K2, V> <
K2 extends K
Identical to Array.filter(), but returns a Collection instead of an Array.
collection.filter(user => user.username === 'Bob');
external findV2 extends V
>() : V2 | undefined <
V2 extends 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.
collection.find(user => user.username === 'Bob');
external findKeyK2 extends K
>() : K2 | undefined <
K2 extends 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.
collection.findKey(user => user.username === 'Bob');
external flatMapT
>(fn: (value: V, key: K, collection: this) => Collection<K, T>) : Collection<K, T> <
T
Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().
collection.flatMap(guild => guild.members.cache);
external hasAll...keys: Key[]) : boolean (
Checks if all of the elements exist in the collection.
Returns: true
if all of the elements exist, false
if at least one does not exist.
Inherited from: Collection
external hasAny...keys: Key[]) : boolean (
Checks if any of the elements exist in the collection.
Returns: true
if any of the elements exist, false
if none exist.
Inherited from: Collection
external intersectT
>(other: ReadonlyCollection<Key, T>) : Collection<Key, T> <
T
The intersect method returns a new structure containing items where the keys and values are present in both original structures.
Inherited from: Collection
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.
Inherited from: Collection
Maps each item to another value into an array. Identical in behavior to Array.map().
collection.map(user => user.tag);
external mapValuesT
>() : Collection<K, T> <
T
Maps each item to another value into a collection. Identical in behavior to Array.map().
collection.mapValues(user => user.tag);
external mergeT
R
>(other: ReadonlyCollection<Key, T>whenInSelf: (value: Value, key: Key) => Keep<R>whenInOther: (valueOther: T, key: Key) => Keep<R>whenInBoth: (value: Value, valueOther: T, key: Key) => Keep<R>) : Collection<Key, R> <
T
R
Merges two Collections together into a new Collection.
// 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 }),
);
Inherited from: Collection
external partitionK2 extends K
>() : [Collection<K2, V>, Collection<Exclude<K, K2>, V>] <
K2 extends K
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
const [big, small] = collection.partition(guild => guild.memberCount > 250);
external reduceT? = Value
>(fn: (accumulator: T, value: Value, key: Key, collection: this) => TinitialValue?: T) : T <
T? = Value
Applies a function to produce a single value. Identical in behavior to Array.reduce().
collection.reduce((acc, guild) => acc + guild.memberCount, 0);
Inherited from: Collection
Identical to Array.reverse() but returns a Collection instead of an Array.
Inherited from: Collection
Checks if there exists an item that passes a test. Identical in behavior to Array.some().
collection.some(user => user.discriminator === '0000');
external sortcompareFunction?: Comparator<Key, Value>) : this (
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.
collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
Inherited from: Collection
external sortedcompareFunction?: Comparator<Key, Value>) : Collection<Key, Value> (
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.
collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
Inherited from: Collection
external subtractT
>(other: ReadonlyCollection<Key, T>) : Collection<Key, Value> <
T
The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.
Inherited from: Collection
external tapfn: (collection: this) => void) : this (
Runs a function on the collection and returns the collection.
collection
.tap(coll => console.log(coll.size))
.filter(user => user.bot)
.tap(coll => console.log(coll.size))
Inherited from: Collection