import { default } from "https://deno.land/x/collection@v1.0.1/src/Collection.ts";
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.
Methods
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.
Identical to Map.clear(). Removes all elements from the collection.
Creates an identical shallow copy of this collection.
Combines this collection with others into a new collection. None of the source collections are modified.
Identical to Map.delete(). Deletes an element from the collection.
The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
Identical to Map.forEach(), but returns the collection instead of undefined.
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.
Checks if all items passes a test. Identical in behavior to Array.every().
Identical to Array.filter(), but returns a Collection instead of an Array.
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.
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.
Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().
Identical to Map.get().
Gets an element with the specified key, and returns its value, or undefined
if the element does not exist.
The intersect method returns a new structure containing items where the keys are present in both original structures.
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.
Obtains the last value(s) in this collection. This relies on Collection#array, and thus the caching mechanism applies here as well.
Obtains the last key(s) in this collection. This relies on Collection#keyArray, and thus the caching mechanism applies here as well.
Maps each item to another value into an array. Identical in behavior to Array.map().
Maps each item to another value into a collection. Identical in behavior to Array.map().
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
Obtains unique random value(s) from this collection. This relies on Collection#array, and thus the caching mechanism applies here as well.
Obtains unique random key(s) from this collection. This relies on Collection#keyArray, and thus the caching mechanism applies here as well.
Applies a function to produce a single value. Identical in behavior to Array.reduce().
Identical to Map.set(). Sets a new element in the collection with the specified key and value.
Checks if there exists an item that passes a test. Identical in behavior to Array.some().
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.
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.
Removes items that satisfy the provided filter function.
Runs a function on the collection and returns the collection.