Appearance
Collection
Package: @erinjs/collection
Extended Map with utility methods for key-value collections. Similar to discord.js Collection.
Properties
None
Methods
clone()
Creates an identical shallow copy of this collection.
Returns: Collection<K, V>
Parameters:
None
concat()
Combines this collection with others into a new collection.
Returns: Collection<K, V>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
collections | ReadonlyCollection<K, V>[] | No |
every()
Tests whether all elements pass the test implemented by the provided function.
Returns: boolean
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
filter()
Creates a new collection with all elements that pass the test implemented by the provided function.
Returns: Collection<K, V>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
find()
Searches for a single item where the given function returns a truthy value.
Returns: V | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
findKey()
Returns the key of the first item where the given function returns a truthy value.
Returns: K | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
first()
Obtains the first value(s) in this collection.
Returns: V | undefined
Parameters:
None
first()
Returns: V[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | No |
first()
Returns: V | V[] | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | Yes |
last()
Obtains the last value(s) in this collection.
Returns: V | undefined
Parameters:
None
last()
Returns: V[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | No |
last()
Returns: V | V[] | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | Yes |
map()
Creates a new array with the results of calling the provided function on every element.
Returns: T[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => T | No |
partition()
Partitions the collection into two collections: one that passes the predicate and one that fails.
Returns: [Collection<K, V>, Collection<K, V>]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
random()
Returns a random value from this collection.
Returns: V | undefined
Parameters:
None
random()
Returns: V[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | No |
random()
Returns: V | V[] | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
amount | number | Yes |
reduce()
Applies a function against an accumulator and each element to reduce the collection to a single value.
Returns: T
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (accumulator: T, value: V, key: K) => T | No | |
initialValue | T | No |
some()
Tests whether at least one element passes the test implemented by the provided function.
Returns: boolean
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (value: V, key: K) => boolean | No |
sort()
Sorts the collection in place and returns it.
Returns: this
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
compareFn | (a: V, b: V, aKey: K, bKey: K) => number | Yes |
tap()
Invokes the given function and returns this collection (for chaining).
Returns: this
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
fn | (collection: this) => void | No |
toJSON()
Returns an array of the values in this collection.
Returns: V[]
Parameters:
None
toString()
Returns a string representation of the collection (array of values).
Returns: string
Parameters:
None