Collection
Documentation / @discordeno/utils / Collection
Class: Collection<K, V>
Defined in: packages/utils/src/Collection.ts:3
Extends
Map<K,V>
Type Parameters
K
K
V
V
Constructors
Constructor
new Collection<
K,V>(entries?,options?):Collection<K,V>
Defined in: packages/utils/src/Collection.ts:12
Parameters
entries?
Map<K, V> | readonly readonly [K, V][] | null
options?
CollectionOptions<K, V>
Returns
Collection<K, V>
Overrides
Map<K, V>.constructor
Properties
[toStringTag]
readonly[toStringTag]:string
Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:137
Inherited from
Collection.[toStringTag]
maxSize
maxSize:
number|undefined
Defined in: packages/utils/src/Collection.ts:8
The maximum amount of items allowed in this collection. To disable cache, set it 0, set to undefined to make it infinite.
Default
undefined
size
readonlysize:number
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:45
Returns
the number of elements in the Map.
Inherited from
Collection.size
sweeper
sweeper:
CollectionSweeper<K,V> &object|undefined
Defined in: packages/utils/src/Collection.ts:10
Handler to remove items from the collection every so often.
[species]
readonlystatic[species]:MapConstructor
Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:319
Inherited from
Map.[species]
Methods
[iterator]()
[iterator]():
MapIterator<[K,V]>
Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:143
Returns an iterable of entries in the map.
Returns
MapIterator<[K, V]>
Inherited from
Map.[iterator]
array()
array():
V[]
Defined in: packages/utils/src/Collection.ts:70
Convert the collection to an array.
Returns
V[]
changeSweeperFilter()
changeSweeperFilter(
newFilter):void
Defined in: packages/utils/src/Collection.ts:48
Parameters
newFilter
(value, key, bot) => boolean
Returns
void
changeSweeperInterval()
changeSweeperInterval(
newInterval):void
Defined in: packages/utils/src/Collection.ts:42
Parameters
newInterval
number
Returns
void
clear()
clear():
void
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:20
Returns
void
Inherited from
Map.clear
delete()
delete(
key):boolean
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:24
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.
Inherited from
Map.delete
entries()
entries():
MapIterator<[K,V]>
Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:148
Returns an iterable of key, value pairs for every entry in the map.
Returns
MapIterator<[K, V]>
Inherited from
Map.entries
every()
every(
callback):boolean
Defined in: packages/utils/src/Collection.ts:130
Check if all of the items in the collection matches the pattern.
Parameters
callback
(value, key) => boolean
Returns
boolean
filter()
filter(
callback):Collection<K,V>
Defined in: packages/utils/src/Collection.ts:100
Find all elements in this collection that match the given pattern.
Parameters
callback
(value, key) => boolean
Returns
Collection<K, V>
find()
find(
callback):NonNullable<V> |undefined
Defined in: packages/utils/src/Collection.ts:91
Find a specific element in this collection.
Parameters
callback
(value, key) => boolean
Returns
NonNullable<V> | undefined
first()
first():
V|undefined
Defined in: packages/utils/src/Collection.ts:75
Retrieve the value of the first element in this collection.
Returns
V | undefined
forceSet()
forceSet(
key,value):this
Defined in: packages/utils/src/Collection.ts:65
Add an item to the collection, no matter what the maxSize is.
Parameters
key
K
value
V
Returns
this
forEach()
forEach(
callbackfn,thisArg?):void
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:28
Executes a provided function once per each key/value pair in the Map, in insertion order.
Parameters
callbackfn
(value, key, map) => void
thisArg?
any
Returns
void
Inherited from
Map.forEach
get()
get(
key):V|undefined
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:33
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
V | undefined
Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
Inherited from
Map.get
has()
has(
key):boolean
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:37
Parameters
key
K
Returns
boolean
boolean indicating whether an element with the specified key exists or not.
Inherited from
Map.has
keys()
keys():
MapIterator<K>
Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:153
Returns an iterable of keys in the map
Returns
MapIterator<K>
Inherited from
Map.keys
last()
last():
V|undefined
Defined in: packages/utils/src/Collection.ts:80
Retrieve the value of the last element in this collection.
Returns
V | undefined
map()
map<
T>(callback):T[]
Defined in: packages/utils/src/Collection.ts:110
Converts the collection into an array by running a callback on all items in the collection.
Type Parameters
T
T
Parameters
callback
(value, key) => T
Returns
T[]
random()
random():
V|undefined
Defined in: packages/utils/src/Collection.ts:85
Retrieve the value of a random element in this collection.
Returns
V | undefined
reduce()
reduce<
T>(callback,initialValue?):T
Defined in: packages/utils/src/Collection.ts:140
Runs a callback on all items in the collection, merging them into a single value.
Type Parameters
T
T
Parameters
callback
(accumulator, value, key) => T
initialValue?
T
Returns
T
set()
set(
key,value):this
Defined in: packages/utils/src/Collection.ts:55
Add an item to the collection. Makes sure not to go above the maxSize.
Parameters
key
K
value
V
Returns
this
Overrides
Map.set
some()
some(
callback):boolean
Defined in: packages/utils/src/Collection.ts:120
Check if one of the items in the collection matches the pattern.
Parameters
callback
(value, key) => boolean
Returns
boolean
startSweeper()
startSweeper(
options):Timeout
Defined in: packages/utils/src/Collection.ts:22
Parameters
options
CollectionSweeper<K, V>
Returns
Timeout
stopSweeper()
stopSweeper():
void
Defined in: packages/utils/src/Collection.ts:38
Returns
void
values()
values():
MapIterator<V>
Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:158
Returns an iterable of values in the map
Returns
MapIterator<V>
Inherited from
Map.values