@discordjs/collection 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +45 -2
- package/dist/index.d.ts +177 -123
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -7
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -7
- package/package.json +20 -21
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<br />
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
|
5
|
+
</p>
|
|
6
|
+
<br />
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/v/@discordjs/collection.svg?maxAge=3600" alt="npm version" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/dt/@discordjs/collection.svg?maxAge=3600" alt="npm downloads" /></a>
|
|
11
|
+
<a href="https://github.com/discordjs/collection/actions"><img src="https://github.com/discordjs/collection/workflows/Tests/badge.svg" alt="Build status" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
</div>
|
|
2
14
|
|
|
3
|
-
|
|
15
|
+
## About
|
|
16
|
+
|
|
17
|
+
`@discordjs/collection` is a powerful utility data structure used in discord.js.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
**Node.js 16.0.0 or newer is required.**
|
|
22
|
+
|
|
23
|
+
```sh-session
|
|
24
|
+
npm install @discordjs/collection
|
|
25
|
+
yarn add @discordjs/collection
|
|
26
|
+
pnpm add @discordjs/collection
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Links
|
|
30
|
+
|
|
31
|
+
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
|
32
|
+
- [Documentation](https://discord.js.org/#/docs/collection)
|
|
33
|
+
- [discord.js Discord server](https://discord.gg/djs)
|
|
34
|
+
- [GitHub](https://github.com/discordjs/collection)
|
|
35
|
+
- [npm](https://www.npmjs.com/package/@discordjs/collection)
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
|
40
|
+
[documentation](https://discord.js.org/#/docs/collection).
|
|
41
|
+
See [the contribution guide](https://github.com/discordjs/collection/blob/main/.github/CONTRIBUTING.md) if you'd like to submit a PR.
|
|
42
|
+
|
|
43
|
+
## Help
|
|
44
|
+
|
|
45
|
+
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
|
|
46
|
+
nudge in the right direction, please don't hesitate to join our official [discord.js Server](https://discord.gg/djs).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
1
4
|
interface CollectionConstructor {
|
|
2
5
|
new (): Collection<unknown, unknown>;
|
|
3
6
|
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;
|
|
@@ -5,118 +8,136 @@ interface CollectionConstructor {
|
|
|
5
8
|
readonly prototype: Collection<unknown, unknown>;
|
|
6
9
|
readonly [Symbol.species]: CollectionConstructor;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
interface Collection<K, V> extends Map<K, V> {
|
|
17
|
+
constructor: CollectionConstructor;
|
|
18
|
+
}
|
|
8
19
|
/**
|
|
9
20
|
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
|
10
21
|
* an ID, for significantly improved performance and ease-of-use.
|
|
11
|
-
* @extends {Map}
|
|
12
|
-
* @property {number} size - The amount of elements in this collection.
|
|
13
22
|
*/
|
|
14
23
|
declare class Collection<K, V> extends Map<K, V> {
|
|
15
24
|
static readonly default: typeof Collection;
|
|
16
|
-
['constructor']: CollectionConstructor;
|
|
17
|
-
/**
|
|
18
|
-
* Identical to [Map.get()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get).
|
|
19
|
-
* Gets an element with the specified key, and returns its value, or `undefined` if the element does not exist.
|
|
20
|
-
* @param {*} key - The key to get from this collection
|
|
21
|
-
* @returns {* | undefined}
|
|
22
|
-
*/
|
|
23
|
-
get(key: K): V | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Identical to [Map.set()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set).
|
|
26
|
-
* Sets a new element in the collection with the specified key and value.
|
|
27
|
-
* @param {*} key - The key of the element to add
|
|
28
|
-
* @param {*} value - The value of the element to add
|
|
29
|
-
* @returns {Collection}
|
|
30
|
-
*/
|
|
31
|
-
set(key: K, value: V): this;
|
|
32
|
-
/**
|
|
33
|
-
* Identical to [Map.has()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has).
|
|
34
|
-
* Checks if an element exists in the collection.
|
|
35
|
-
* @param {*} key - The key of the element to check for
|
|
36
|
-
* @returns {boolean} `true` if the element exists, `false` if it does not exist.
|
|
37
|
-
*/
|
|
38
|
-
has(key: K): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Identical to [Map.delete()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).
|
|
41
|
-
* Deletes an element from the collection.
|
|
42
|
-
* @param {*} key - The key to delete from the collection
|
|
43
|
-
* @returns {boolean} `true` if the element was removed, `false` if the element does not exist.
|
|
44
|
-
*/
|
|
45
|
-
delete(key: K): boolean;
|
|
46
25
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
26
|
+
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
|
27
|
+
*
|
|
28
|
+
* @param key The key to get if it exists, or set otherwise
|
|
29
|
+
* @param defaultValueGenerator A function that generates the default value
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* collection.ensure(guildId, () => defaultGuildConfig);
|
|
50
33
|
*/
|
|
51
|
-
|
|
34
|
+
ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V;
|
|
52
35
|
/**
|
|
53
36
|
* Checks if all of the elements exist in the collection.
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
37
|
+
*
|
|
38
|
+
* @param keys - The keys of the elements to check for
|
|
39
|
+
*
|
|
40
|
+
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
|
56
41
|
*/
|
|
57
42
|
hasAll(...keys: K[]): boolean;
|
|
58
43
|
/**
|
|
59
44
|
* Checks if any of the elements exist in the collection.
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
45
|
+
*
|
|
46
|
+
* @param keys - The keys of the elements to check for
|
|
47
|
+
*
|
|
48
|
+
* @returns `true` if any of the elements exist, `false` if none exist.
|
|
62
49
|
*/
|
|
63
50
|
hasAny(...keys: K[]): boolean;
|
|
64
51
|
/**
|
|
65
52
|
* Obtains the first value(s) in this collection.
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
53
|
+
*
|
|
54
|
+
* @param amount Amount of values to obtain from the beginning
|
|
55
|
+
*
|
|
56
|
+
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
|
|
69
57
|
*/
|
|
70
58
|
first(): V | undefined;
|
|
71
59
|
first(amount: number): V[];
|
|
72
60
|
/**
|
|
73
61
|
* Obtains the first key(s) in this collection.
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
62
|
+
*
|
|
63
|
+
* @param amount Amount of keys to obtain from the beginning
|
|
64
|
+
*
|
|
65
|
+
* @returns A single key if no amount is provided or an array of keys, starting from the end if
|
|
76
66
|
* amount is negative
|
|
77
67
|
*/
|
|
78
68
|
firstKey(): K | undefined;
|
|
79
69
|
firstKey(amount: number): K[];
|
|
80
70
|
/**
|
|
81
71
|
* Obtains the last value(s) in this collection.
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
72
|
+
*
|
|
73
|
+
* @param amount Amount of values to obtain from the end
|
|
74
|
+
*
|
|
75
|
+
* @returns A single value if no amount is provided or an array of values, starting from the start if
|
|
84
76
|
* amount is negative
|
|
85
77
|
*/
|
|
86
78
|
last(): V | undefined;
|
|
87
79
|
last(amount: number): V[];
|
|
88
80
|
/**
|
|
89
81
|
* Obtains the last key(s) in this collection.
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
82
|
+
*
|
|
83
|
+
* @param amount Amount of keys to obtain from the end
|
|
84
|
+
*
|
|
85
|
+
* @returns A single key if no amount is provided or an array of keys, starting from the start if
|
|
92
86
|
* amount is negative
|
|
93
87
|
*/
|
|
94
88
|
lastKey(): K | undefined;
|
|
95
89
|
lastKey(amount: number): K[];
|
|
90
|
+
/**
|
|
91
|
+
* Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).
|
|
92
|
+
* Returns the item at a given index, allowing for positive and negative integers.
|
|
93
|
+
* Negative integers count back from the last item in the collection.
|
|
94
|
+
*
|
|
95
|
+
* @param index The index of the element to obtain
|
|
96
|
+
*/
|
|
97
|
+
at(index: number): V | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).
|
|
100
|
+
* Returns the key at a given index, allowing for positive and negative integers.
|
|
101
|
+
* Negative integers count back from the last item in the collection.
|
|
102
|
+
*
|
|
103
|
+
* @param index The index of the key to obtain
|
|
104
|
+
*/
|
|
105
|
+
keyAt(index: number): K | undefined;
|
|
96
106
|
/**
|
|
97
107
|
* Obtains unique random value(s) from this collection.
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
108
|
+
*
|
|
109
|
+
* @param amount Amount of values to obtain randomly
|
|
110
|
+
*
|
|
111
|
+
* @returns A single value if no amount is provided or an array of values
|
|
100
112
|
*/
|
|
101
|
-
random(): V;
|
|
113
|
+
random(): V | undefined;
|
|
102
114
|
random(amount: number): V[];
|
|
103
115
|
/**
|
|
104
116
|
* Obtains unique random key(s) from this collection.
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
117
|
+
*
|
|
118
|
+
* @param amount Amount of keys to obtain randomly
|
|
119
|
+
*
|
|
120
|
+
* @returns A single key if no amount is provided or an array
|
|
107
121
|
*/
|
|
108
|
-
randomKey(): K;
|
|
122
|
+
randomKey(): K | undefined;
|
|
109
123
|
randomKey(amount: number): K[];
|
|
124
|
+
/**
|
|
125
|
+
* Identical to [Array.reverse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
|
|
126
|
+
* but returns a Collection instead of an Array.
|
|
127
|
+
*/
|
|
128
|
+
reverse(): this;
|
|
110
129
|
/**
|
|
111
130
|
* Searches for a single item where the given function returns a truthy value. This behaves like
|
|
112
131
|
* [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
|
|
113
132
|
* <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you
|
|
114
133
|
* should use the `get` method. See
|
|
115
134
|
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>
|
|
116
|
-
*
|
|
117
|
-
* @param
|
|
118
|
-
* @
|
|
119
|
-
*
|
|
135
|
+
*
|
|
136
|
+
* @param fn The function to test with (should return boolean)
|
|
137
|
+
* @param thisArg Value to use as `this` when executing function
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* collection.find(user => user.username === 'Bob');
|
|
120
141
|
*/
|
|
121
142
|
find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
|
|
122
143
|
find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
|
|
@@ -126,10 +147,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
126
147
|
* Searches for the key of a single item where the given function returns a truthy value. This behaves like
|
|
127
148
|
* [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),
|
|
128
149
|
* but returns the key rather than the positional index.
|
|
129
|
-
*
|
|
130
|
-
* @param
|
|
131
|
-
* @
|
|
132
|
-
*
|
|
150
|
+
*
|
|
151
|
+
* @param fn The function to test with (should return boolean)
|
|
152
|
+
* @param thisArg Value to use as `this` when executing function
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* collection.findKey(user => user.username === 'Bob');
|
|
133
156
|
*/
|
|
134
157
|
findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
|
|
135
158
|
findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
|
|
@@ -137,9 +160,11 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
137
160
|
findKey<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): K | undefined;
|
|
138
161
|
/**
|
|
139
162
|
* Removes items that satisfy the provided filter function.
|
|
140
|
-
*
|
|
141
|
-
* @param
|
|
142
|
-
* @
|
|
163
|
+
*
|
|
164
|
+
* @param fn Function used to test (should return a boolean)
|
|
165
|
+
* @param thisArg Value to use as `this` when executing function
|
|
166
|
+
*
|
|
167
|
+
* @returns The number of removed entries
|
|
143
168
|
*/
|
|
144
169
|
sweep(fn: (value: V, key: K, collection: this) => boolean): number;
|
|
145
170
|
sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;
|
|
@@ -147,10 +172,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
147
172
|
* Identical to
|
|
148
173
|
* [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
|
|
149
174
|
* but returns a Collection instead of an Array.
|
|
150
|
-
*
|
|
151
|
-
* @param
|
|
152
|
-
* @
|
|
153
|
-
*
|
|
175
|
+
*
|
|
176
|
+
* @param fn The function to test with (should return boolean)
|
|
177
|
+
* @param thisArg Value to use as `this` when executing function
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* collection.filter(user => user.username === 'Bob');
|
|
154
181
|
*/
|
|
155
182
|
filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;
|
|
156
183
|
filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;
|
|
@@ -161,10 +188,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
161
188
|
/**
|
|
162
189
|
* Partitions the collection into two collections where the first collection
|
|
163
190
|
* contains the items that passed and the second contains the items that failed.
|
|
164
|
-
*
|
|
165
|
-
* @param
|
|
166
|
-
* @
|
|
167
|
-
*
|
|
191
|
+
*
|
|
192
|
+
* @param fn Function used to test (should return a boolean)
|
|
193
|
+
* @param thisArg Value to use as `this` when executing function
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
|
168
197
|
*/
|
|
169
198
|
partition<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];
|
|
170
199
|
partition<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];
|
|
@@ -175,50 +204,60 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
175
204
|
/**
|
|
176
205
|
* Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
|
|
177
206
|
* [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).
|
|
178
|
-
*
|
|
179
|
-
* @param
|
|
180
|
-
* @
|
|
181
|
-
*
|
|
207
|
+
*
|
|
208
|
+
* @param fn Function that produces a new Collection
|
|
209
|
+
* @param thisArg Value to use as `this` when executing function
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* collection.flatMap(guild => guild.members.cache);
|
|
182
213
|
*/
|
|
183
214
|
flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
|
|
184
215
|
flatMap<T, This>(fn: (this: This, value: V, key: K, collection: this) => Collection<K, T>, thisArg: This): Collection<K, T>;
|
|
185
216
|
/**
|
|
186
217
|
* Maps each item to another value into an array. Identical in behavior to
|
|
187
218
|
* [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
|
|
188
|
-
*
|
|
189
|
-
* @param
|
|
190
|
-
* @
|
|
191
|
-
*
|
|
219
|
+
*
|
|
220
|
+
* @param fn Function that produces an element of the new array, taking three arguments
|
|
221
|
+
* @param thisArg Value to use as `this` when executing function
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* collection.map(user => user.tag);
|
|
192
225
|
*/
|
|
193
226
|
map<T>(fn: (value: V, key: K, collection: this) => T): T[];
|
|
194
227
|
map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
|
|
195
228
|
/**
|
|
196
229
|
* Maps each item to another value into a collection. Identical in behavior to
|
|
197
230
|
* [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
|
|
198
|
-
*
|
|
199
|
-
* @param
|
|
200
|
-
* @
|
|
201
|
-
*
|
|
231
|
+
*
|
|
232
|
+
* @param fn Function that produces an element of the new collection, taking three arguments
|
|
233
|
+
* @param thisArg Value to use as `this` when executing function
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* collection.mapValues(user => user.tag);
|
|
202
237
|
*/
|
|
203
238
|
mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
|
|
204
239
|
mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
|
|
205
240
|
/**
|
|
206
241
|
* Checks if there exists an item that passes a test. Identical in behavior to
|
|
207
242
|
* [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
|
|
208
|
-
*
|
|
209
|
-
* @param
|
|
210
|
-
* @
|
|
211
|
-
*
|
|
243
|
+
*
|
|
244
|
+
* @param fn Function used to test (should return a boolean)
|
|
245
|
+
* @param thisArg Value to use as `this` when executing function
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* collection.some(user => user.discriminator === '0000');
|
|
212
249
|
*/
|
|
213
250
|
some(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
|
214
251
|
some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
|
|
215
252
|
/**
|
|
216
253
|
* Checks if all items passes a test. Identical in behavior to
|
|
217
254
|
* [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).
|
|
218
|
-
*
|
|
219
|
-
* @param
|
|
220
|
-
* @
|
|
221
|
-
*
|
|
255
|
+
*
|
|
256
|
+
* @param fn Function used to test (should return a boolean)
|
|
257
|
+
* @param thisArg Value to use as `this` when executing function
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* collection.every(user => !user.bot);
|
|
222
261
|
*/
|
|
223
262
|
every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;
|
|
224
263
|
every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;
|
|
@@ -229,20 +268,23 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
229
268
|
/**
|
|
230
269
|
* Applies a function to produce a single value. Identical in behavior to
|
|
231
270
|
* [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
|
|
232
|
-
*
|
|
271
|
+
*
|
|
272
|
+
* @param fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
|
233
273
|
* and `collection`
|
|
234
|
-
* @param
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
274
|
+
* @param initialValue Starting value for the accumulator
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
|
237
278
|
*/
|
|
238
279
|
reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
|
239
280
|
/**
|
|
240
281
|
* Identical to
|
|
241
282
|
* [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),
|
|
242
283
|
* but returns the collection instead of undefined.
|
|
243
|
-
*
|
|
244
|
-
* @param
|
|
245
|
-
* @
|
|
284
|
+
*
|
|
285
|
+
* @param fn Function to execute for each element
|
|
286
|
+
* @param thisArg Value to use as `this` when executing function
|
|
287
|
+
*
|
|
246
288
|
* @example
|
|
247
289
|
* collection
|
|
248
290
|
* .each(user => console.log(user.username))
|
|
@@ -253,9 +295,10 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
253
295
|
each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
|
|
254
296
|
/**
|
|
255
297
|
* Runs a function on the collection and returns the collection.
|
|
256
|
-
*
|
|
257
|
-
* @param
|
|
258
|
-
* @
|
|
298
|
+
*
|
|
299
|
+
* @param fn Function to execute
|
|
300
|
+
* @param thisArg Value to use as `this` when executing function
|
|
301
|
+
*
|
|
259
302
|
* @example
|
|
260
303
|
* collection
|
|
261
304
|
* .tap(coll => console.log(coll.size))
|
|
@@ -266,62 +309,73 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
266
309
|
tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
|
|
267
310
|
/**
|
|
268
311
|
* Creates an identical shallow copy of this collection.
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* const newColl = someColl.clone();
|
|
271
315
|
*/
|
|
272
316
|
clone(): Collection<K, V>;
|
|
273
317
|
/**
|
|
274
318
|
* Combines this collection with others into a new collection. None of the source collections are modified.
|
|
275
|
-
*
|
|
276
|
-
* @
|
|
277
|
-
*
|
|
319
|
+
*
|
|
320
|
+
* @param collections Collections to merge
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
|
278
324
|
*/
|
|
279
325
|
concat(...collections: Collection<K, V>[]): Collection<K, V>;
|
|
280
326
|
/**
|
|
281
327
|
* Checks if this collection shares identical items with another.
|
|
282
328
|
* This is different to checking for equality using equal-signs, because
|
|
283
329
|
* the collections may be different objects, but contain the same data.
|
|
284
|
-
*
|
|
285
|
-
* @
|
|
330
|
+
*
|
|
331
|
+
* @param collection Collection to compare with
|
|
332
|
+
*
|
|
333
|
+
* @returns Whether the collections have identical contents
|
|
286
334
|
*/
|
|
287
335
|
equals(collection: Collection<K, V>): boolean;
|
|
288
336
|
/**
|
|
289
337
|
* The sort method sorts the items of a collection in place and returns it.
|
|
290
338
|
* The sort is not necessarily stable in Node 10 or older.
|
|
291
339
|
* The default sort order is according to string Unicode code points.
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* according to the string conversion of each element.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
340
|
+
*
|
|
341
|
+
* @param compareFunction Specifies a function that defines the sort order.
|
|
342
|
+
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
297
346
|
*/
|
|
298
347
|
sort(compareFunction?: Comparator<K, V>): this;
|
|
299
348
|
/**
|
|
300
349
|
* The intersect method returns a new structure containing items where the keys are present in both original structures.
|
|
301
|
-
*
|
|
302
|
-
* @
|
|
350
|
+
*
|
|
351
|
+
* @param other The other Collection to filter against
|
|
303
352
|
*/
|
|
304
353
|
intersect(other: Collection<K, V>): Collection<K, V>;
|
|
305
354
|
/**
|
|
306
355
|
* The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
|
|
307
|
-
*
|
|
308
|
-
* @
|
|
356
|
+
*
|
|
357
|
+
* @param other The other Collection to filter against
|
|
309
358
|
*/
|
|
310
359
|
difference(other: Collection<K, V>): Collection<K, V>;
|
|
311
360
|
/**
|
|
312
361
|
* The sorted method sorts the items of a collection and returns it.
|
|
313
362
|
* The sort is not necessarily stable in Node 10 or older.
|
|
314
363
|
* The default sort order is according to string Unicode code points.
|
|
315
|
-
*
|
|
364
|
+
*
|
|
365
|
+
* @param compareFunction Specifies a function that defines the sort order.
|
|
316
366
|
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
|
317
367
|
* according to the string conversion of each element.
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
320
371
|
*/
|
|
321
372
|
sorted(compareFunction?: Comparator<K, V>): Collection<K, V>;
|
|
322
373
|
toJSON(): V[];
|
|
323
374
|
private static defaultSort;
|
|
324
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* @internal
|
|
378
|
+
*/
|
|
325
379
|
declare type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;
|
|
326
380
|
|
|
327
381
|
export { Collection, CollectionConstructor, Comparator, Collection as default };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var b=(l,e,i)=>e in l?s(l,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[e]=i;var V=l=>s(l,"__esModule",{value:!0}),h=(l,e)=>s(l,"name",{value:e,configurable:!0});var d=(l,e)=>{for(var i in e)s(l,i,{get:e[i],enumerable:!0})},y=(l,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of K(e))!p.call(l,n)&&(i||n!=="default")&&s(l,n,{get:()=>e[n],enumerable:!(t=f(e,n))||t.enumerable});return l};var v=(l=>(e,i)=>l&&l.get(e)||(i=y(V({}),e,1),l&&l.set(e,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var a=(l,e,i)=>(b(l,typeof e!="symbol"?e+"":e,i),i);var T={};d(T,{Collection:()=>c,default:()=>k});var r=class extends Map{ensure(e,i){if(this.has(e))return this.get(e);let t=i(e,this);return this.set(e,t),t}hasAll(...e){return e.every(i=>super.has(i))}hasAny(...e){return e.some(i=>super.has(i))}first(e){if(typeof e=="undefined")return this.values().next().value;if(e<0)return this.last(e*-1);e=Math.min(this.size,e);let i=this.values();return Array.from({length:e},()=>i.next().value)}firstKey(e){if(typeof e=="undefined")return this.keys().next().value;if(e<0)return this.lastKey(e*-1);e=Math.min(this.size,e);let i=this.keys();return Array.from({length:e},()=>i.next().value)}last(e){let i=[...this.values()];return typeof e=="undefined"?i[i.length-1]:e<0?this.first(e*-1):e?i.slice(-e):[]}lastKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[i.length-1]:e<0?this.firstKey(e*-1):e?i.slice(-e):[]}at(e){return e=Math.floor(e),[...this.values()].at(e)}keyAt(e){return e=Math.floor(e),[...this.keys()].at(e)}random(e){let i=[...this.values()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}randomKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}reverse(){let e=[...this.entries()].reverse();this.clear();for(let[i,t]of e)this.set(i,t);return this}find(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return n}findKey(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return t}sweep(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.size;for(let[n,o]of this)e(o,n,this)&&this.delete(n);return t-this.size}filter(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[n,o]of this)e(o,n,this)&&t.set(n,o);return t}partition(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(let[n,o]of this)e(o,n,this)?t[0].set(n,o):t[1].set(n,o);return t}flatMap(e,i){let t=this.map(e,i);return new this.constructor[Symbol.species]().concat(...t)}map(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.entries();return Array.from({length:this.size},()=>{let[n,o]=t.next().value;return e(o,n,this)})}mapValues(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[n,o]of this)t.set(n,e(o,n,this));return t}some(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return!0;return!1}every(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(!e(n,t,this))return!1;return!0}reduce(e,i){let t;if(typeof i!="undefined"){t=i;for(let[o,u]of this)t=e(t,u,o,this);return t}let n=!0;for(let[o,u]of this){if(n){t=u,n=!1;continue}t=e(t,u,o,this)}if(n)throw new TypeError("Reduce of empty collection with no initial value");return t}each(e,i){return this.forEach(e,i),this}tap(e,i){return typeof i!="undefined"&&(e=e.bind(i)),e(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...e){let i=this.clone();for(let t of e)for(let[n,o]of t)i.set(n,o);return i}equals(e){if(!e)return!1;if(this===e)return!0;if(this.size!==e.size)return!1;for(let[i,t]of this)if(!e.has(i)||t!==e.get(i))return!1;return!0}sort(e=r.defaultSort){let i=[...this.entries()];i.sort((t,n)=>e(t[1],n[1],t[0],n[0])),super.clear();for(let[t,n]of i)super.set(t,n);return this}intersect(e){let i=new this.constructor[Symbol.species];for(let[t,n]of e)this.has(t)&&i.set(t,n);return i}difference(e){let i=new this.constructor[Symbol.species];for(let[t,n]of e)this.has(t)||i.set(t,n);for(let[t,n]of this)e.has(t)||i.set(t,n);return i}sorted(e=r.defaultSort){return new this.constructor[Symbol.species](this).sort((i,t,n,o)=>e(i,t,n,o))}toJSON(){return[...this.values()]}static defaultSort(e,i){return Number(e>i)||Number(e===i)-1}},c=r;h(c,"Collection"),a(c,"default",r);var k=c;module.exports=v(T);0&&(module.exports={Collection});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n * @extends {Map}\n * @property {number} size - The amount of elements in this collection.\n */\nexport class Collection<K, V> extends Map<K, V> {\n\tpublic static readonly default: typeof Collection = Collection;\n\tpublic override ['constructor']: CollectionConstructor;\n\n\t/**\n\t * Identical to [Map.get()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get).\n\t * Gets an element with the specified key, and returns its value, or `undefined` if the element does not exist.\n\t * @param {*} key - The key to get from this collection\n\t * @returns {* | undefined}\n\t */\n\tpublic override get(key: K): V | undefined {\n\t\treturn super.get(key);\n\t}\n\n\t/**\n\t * Identical to [Map.set()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set).\n\t * Sets a new element in the collection with the specified key and value.\n\t * @param {*} key - The key of the element to add\n\t * @param {*} value - The value of the element to add\n\t * @returns {Collection}\n\t */\n\tpublic override set(key: K, value: V): this {\n\t\treturn super.set(key, value);\n\t}\n\n\t/**\n\t * Identical to [Map.has()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has).\n\t * Checks if an element exists in the collection.\n\t * @param {*} key - The key of the element to check for\n\t * @returns {boolean} `true` if the element exists, `false` if it does not exist.\n\t */\n\tpublic override has(key: K): boolean {\n\t\treturn super.has(key);\n\t}\n\n\t/**\n\t * Identical to [Map.delete()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).\n\t * Deletes an element from the collection.\n\t * @param {*} key - The key to delete from the collection\n\t * @returns {boolean} `true` if the element was removed, `false` if the element does not exist.\n\t */\n\tpublic override delete(key: K): boolean {\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Identical to [Map.clear()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear).\n\t * Removes all elements from the collection.\n\t * @returns {undefined}\n\t */\n\tpublic override clear(): void {\n\t\treturn super.clear();\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t * @param {...*} keys - The keys of the elements to check for\n\t * @returns {boolean} `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]): boolean {\n\t\treturn keys.every((k) => super.has(k));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t * @param {...*} keys - The keys of the elements to check for\n\t * @returns {boolean} `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]): boolean {\n\t\treturn keys.some((k) => super.has(k));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t * @param {number} [amount] Amount of values to obtain from the beginning\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the end if\n\t * amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t * @param {number} [amount] Amount of keys to obtain from the beginning\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t * @param {number} [amount] Amount of values to obtain from the end\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t * @param {number} [amount] Amount of keys to obtain from the end\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t * @param {number} [amount] Amount of values to obtain randomly\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t * @param {number} [amount] Amount of keys to obtain randomly\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).\n\t * <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {*}\n\t * @example collection.find(user => user.username === 'Bob');\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): V | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),\n\t * but returns the key rather than the positional index.\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {*}\n\t * @example collection.findKey(user => user.username === 'Bob');\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): K | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {number} The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): number {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n\t * but returns a Collection instead of an Array.\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.filter(user => user.username === 'Bob');\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection[]}\n\t * @example const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => boolean): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => boolean,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => boolean,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).\n\t * @param {Function} fn Function that produces a new Collection\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.flatMap(guild => guild.members.cache);\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t * @param {Function} fn Function that produces an element of the new array, taking three arguments\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Array}\n\t * @example collection.map(user => user.tag);\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t * @param {Function} fn Function that produces an element of the new collection, taking three arguments\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.mapValues(user => user.tag);\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {boolean}\n\t * @example collection.some(user => user.discriminator === '0000');\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {boolean}\n\t * @example collection.every(user => !user.bot);\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).\n\t * @param {Function} fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param {*} [initialValue] Starting value for the accumulator\n\t * @returns {*}\n\t * @example collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t */\n\tpublic reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tlet accumulator!: T;\n\n\t\tif (typeof initialValue !== 'undefined') {\n\t\t\taccumulator = initialValue;\n\t\t\tfor (const [key, val] of this) accumulator = fn(accumulator, val, key, this);\n\t\t\treturn accumulator;\n\t\t}\n\t\tlet first = true;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (first) {\n\t\t\t\taccumulator = val as unknown as T;\n\t\t\t\tfirst = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taccumulator = fn(accumulator, val, key, this);\n\t\t}\n\n\t\t// No items iterated.\n\t\tif (first) {\n\t\t\tthrow new TypeError('Reduce of empty collection with no initial value');\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),\n\t * but returns the collection instead of undefined.\n\t * @param {Function} fn Function to execute for each element\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tthis.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t * @param {Function} fn Function to execute\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t * @returns {Collection}\n\t * @example const newColl = someColl.clone();\n\t */\n\tpublic clone(): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t * @param {...Collection} collections Collections to merge\n\t * @returns {Collection}\n\t * @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t */\n\tpublic concat(...collections: Collection<K, V>[]): Collection<K, V> {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t * @param {Collection} collection Collection to compare with\n\t * @returns {boolean} Whether the collections have identical contents\n\t */\n\tpublic equals(collection: Collection<K, V>): boolean {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t * @param {Function} [compareFunction] Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @returns {Collection}\n\t * @example collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort): this {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [k, v] of entries) {\n\t\t\tsuper.set(k, v);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys are present in both original structures.\n\t * @param {Collection} other The other Collection to filter against\n\t * @returns {Collection}\n\t */\n\tpublic intersect(other: Collection<K, V>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (this.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\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.\n\t * @param {Collection} other The other Collection to filter against\n\t * @returns {Collection}\n\t */\n\tpublic difference(other: Collection<K, V>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (!this.has(k)) coll.set(k, v);\n\t\t}\n\t\tfor (const [k, v] of this) {\n\t\t\tif (!other.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t * @param {Function} [compareFunction] Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @returns {Collection}\n\t * @example collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n}\n\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n\nexport default Collection;\n"],
|
|
5
|
-
"mappings": "oLAAA,4CAcO,mBAA+B,IAAU,CAU/B,IAAI,EAAuB,CAC1C,MAAO,OAAM,IAAI,GAUF,IAAI,EAAQ,EAAgB,CAC3C,MAAO,OAAM,IAAI,EAAK,GASP,IAAI,EAAiB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,OAAO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAK,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE/B,OAAW,CAAC,EAAG,IAAM,MACpB,AAAK,EAAM,IAAI,IAAI,EAAK,IAAI,EAAG,GAEhC,MAAO,GAaD,OAAO,EAAoC,EAAW,YAA+B,CAC3F,MAAO,IAAI,MAAK,YAAY,OAAO,SAAS,MAAM,KAAK,CAAC,EAAI,EAAI,EAAI,IAAO,EAAgB,EAAI,EAAI,EAAI,IAGjG,QAAS,CAEf,MAAO,CAAC,GAAG,KAAK,gBAGF,aAAe,EAAe,EAAwB,CACpE,MAAO,QAAO,EAAa,IAAgB,OAAO,IAAe,GAAe,IA5lB3E,sBAEW,cADM,AADjB,EACiB,QAA6B,EAimBrD,GAAO,GAAQ",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @internal\n */\nexport interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself\n *\n * @internal\n */\nexport interface Collection<K, V> extends Map<K, V> {\n\tconstructor: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n */\nexport class Collection<K, V> extends Map<K, V> {\n\tpublic static readonly default: typeof Collection = Collection;\n\n\t/**\n\t * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.\n\t *\n\t * @param key The key to get if it exists, or set otherwise\n\t * @param defaultValueGenerator A function that generates the default value\n\t *\n\t * @example\n\t * collection.ensure(guildId, () => defaultGuildConfig);\n\t */\n\tpublic ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {\n\t\tif (this.has(key)) return this.get(key)!;\n\t\tconst defaultValue = defaultValueGenerator(key, this);\n\t\tthis.set(key, defaultValue);\n\t\treturn defaultValue;\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t *\n\t * @returns `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]) {\n\t\treturn keys.every((k) => super.has(k));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t *\n\t * @returns `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]) {\n\t\treturn keys.some((k) => super.has(k));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t *\n\t * @param amount Amount of values to obtain from the beginning\n\t *\n\t * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t *\n\t * @param amount Amount of keys to obtain from the beginning\n\t *\n\t * @returns A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t *\n\t * @param amount Amount of values to obtain from the end\n\t *\n\t * @returns A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t *\n\t * @param amount Amount of keys to obtain from the end\n\t *\n\t * @returns A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).\n\t * Returns the item at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index The index of the element to obtain\n\t */\n\tpublic at(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.values()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).\n\t * Returns the key at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index The index of the key to obtain\n\t */\n\tpublic keyAt(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.keys()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t *\n\t * @param amount Amount of values to obtain randomly\n\t *\n\t * @returns A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V | undefined;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t *\n\t * @param amount Amount of keys to obtain randomly\n\t *\n\t * @returns A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K | undefined;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Identical to [Array.reverse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\n\t * but returns a Collection instead of an Array.\n\t */\n\tpublic reverse() {\n\t\tconst entries = [...this.entries()].reverse();\n\t\tthis.clear();\n\t\tfor (const [key, value] of entries) this.set(key, value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).\n\t * <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.find(user => user.username === 'Bob');\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): V | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),\n\t * but returns the key rather than the positional index.\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.findKey(user => user.username === 'Bob');\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): K | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @returns The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): number {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n\t * but returns a Collection instead of an Array.\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.filter(user => user.username === 'Bob');\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => boolean): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => boolean,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => boolean,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).\n\t *\n\t * @param fn Function that produces a new Collection\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.flatMap(guild => guild.members.cache);\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t *\n\t * @param fn Function that produces an element of the new array, taking three arguments\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.map(user => user.tag);\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t *\n\t * @param fn Function that produces an element of the new collection, taking three arguments\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.mapValues(user => user.tag);\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.some(user => user.discriminator === '0000');\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.every(user => !user.bot);\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).\n\t *\n\t * @param fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param initialValue Starting value for the accumulator\n\t *\n\t * @example\n\t * collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t */\n\tpublic reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tlet accumulator!: T;\n\n\t\tif (typeof initialValue !== 'undefined') {\n\t\t\taccumulator = initialValue;\n\t\t\tfor (const [key, val] of this) accumulator = fn(accumulator, val, key, this);\n\t\t\treturn accumulator;\n\t\t}\n\t\tlet first = true;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (first) {\n\t\t\t\taccumulator = val as unknown as T;\n\t\t\t\tfirst = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taccumulator = fn(accumulator, val, key, this);\n\t\t}\n\n\t\t// No items iterated.\n\t\tif (first) {\n\t\t\tthrow new TypeError('Reduce of empty collection with no initial value');\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),\n\t * but returns the collection instead of undefined.\n\t *\n\t * @param fn Function to execute for each element\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tthis.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t *\n\t * @param fn Function to execute\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t *\n\t * @example\n\t * const newColl = someColl.clone();\n\t */\n\tpublic clone() {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t *\n\t * @param collections Collections to merge\n\t *\n\t * @example\n\t * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t */\n\tpublic concat(...collections: Collection<K, V>[]) {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t *\n\t * @param collection Collection to compare with\n\t *\n\t * @returns Whether the collections have identical contents\n\t */\n\tpublic equals(collection: Collection<K, V>) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.\n\t *\n\t * @example\n\t * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [k, v] of entries) {\n\t\t\tsuper.set(k, v);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys are present in both original structures.\n\t *\n\t * @param other The other Collection to filter against\n\t */\n\tpublic intersect(other: Collection<K, V>) {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (this.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\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.\n\t *\n\t * @param other The other Collection to filter against\n\t */\n\tpublic difference(other: Collection<K, V>) {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (!this.has(k)) coll.set(k, v);\n\t\t}\n\t\tfor (const [k, v] of this) {\n\t\t\tif (!other.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t *\n\t * @example\n\t * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n}\n\n/**\n * @internal\n */\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n\nexport default Collection;\n"],"mappings":"ysBAAA,+CAwBO,mBAA+B,IAAU,CAYxC,OAAO,EAAQ,EAA2D,CAChF,GAAI,KAAK,IAAI,GAAM,MAAO,MAAK,IAAI,GACnC,GAAM,GAAe,EAAsB,EAAK,MAChD,YAAK,IAAI,EAAK,GACP,EAUD,UAAU,EAAW,CAC3B,MAAO,GAAK,MAAM,AAAC,GAAM,MAAM,IAAI,IAU7B,UAAU,EAAW,CAC3B,MAAO,GAAK,KAAK,AAAC,GAAM,MAAM,IAAI,IAY5B,MAAM,EAAsC,CAClD,GAAI,MAAO,IAAW,YAAa,MAAO,MAAK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AO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAK,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE/B,OAAW,CAAC,EAAG,IAAM,MACpB,AAAK,EAAM,IAAI,IAAI,EAAK,IAAI,EAAG,GAEhC,MAAO,GAeD,OAAO,EAAoC,EAAW,YAAa,CACzE,MAAO,IAAI,MAAK,YAAY,OAAO,SAAS,MAAM,KAAK,CAAC,EAAI,EAAI,EAAI,IAAO,EAAgB,EAAI,EAAI,EAAI,IAGjG,QAAS,CAEf,MAAO,CAAC,GAAG,KAAK,gBAGF,aAAe,EAAe,EAAwB,CACpE,MAAO,QAAO,EAAa,IAAgB,OAAO,IAAe,GAAe,IA7oB3E,sBACiB,EADjB,EACiB,UAA6B,GAqpBrD,GAAO,GAAQ","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
var u=Object.defineProperty;var f=(o,e,i)=>e in o?u(o,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[e]=i;var h=(o,e)=>u(o,"name",{value:e,configurable:!0});var a=(o,e,i)=>(f(o,typeof e!="symbol"?e+"":e,i),i);var s=class extends Map{ensure(e,i){if(this.has(e))return this.get(e);let t=i(e,this);return this.set(e,t),t}hasAll(...e){return e.every(i=>super.has(i))}hasAny(...e){return e.some(i=>super.has(i))}first(e){if(typeof e=="undefined")return this.values().next().value;if(e<0)return this.last(e*-1);e=Math.min(this.size,e);let i=this.values();return Array.from({length:e},()=>i.next().value)}firstKey(e){if(typeof e=="undefined")return this.keys().next().value;if(e<0)return this.lastKey(e*-1);e=Math.min(this.size,e);let i=this.keys();return Array.from({length:e},()=>i.next().value)}last(e){let i=[...this.values()];return typeof e=="undefined"?i[i.length-1]:e<0?this.first(e*-1):e?i.slice(-e):[]}lastKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[i.length-1]:e<0?this.firstKey(e*-1):e?i.slice(-e):[]}at(e){return e=Math.floor(e),[...this.values()].at(e)}keyAt(e){return e=Math.floor(e),[...this.keys()].at(e)}random(e){let i=[...this.values()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}randomKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}reverse(){let e=[...this.entries()].reverse();this.clear();for(let[i,t]of e)this.set(i,t);return this}find(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return n}findKey(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return t}sweep(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.size;for(let[n,l]of this)e(l,n,this)&&this.delete(n);return t-this.size}filter(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[n,l]of this)e(l,n,this)&&t.set(n,l);return t}partition(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(let[n,l]of this)e(l,n,this)?t[0].set(n,l):t[1].set(n,l);return t}flatMap(e,i){let t=this.map(e,i);return new this.constructor[Symbol.species]().concat(...t)}map(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.entries();return Array.from({length:this.size},()=>{let[n,l]=t.next().value;return e(l,n,this)})}mapValues(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[n,l]of this)t.set(n,e(l,n,this));return t}some(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(e(n,t,this))return!0;return!1}every(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,n]of this)if(!e(n,t,this))return!1;return!0}reduce(e,i){let t;if(typeof i!="undefined"){t=i;for(let[l,c]of this)t=e(t,c,l,this);return t}let n=!0;for(let[l,c]of this){if(n){t=c,n=!1;continue}t=e(t,c,l,this)}if(n)throw new TypeError("Reduce of empty collection with no initial value");return t}each(e,i){return this.forEach(e,i),this}tap(e,i){return typeof i!="undefined"&&(e=e.bind(i)),e(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...e){let i=this.clone();for(let t of e)for(let[n,l]of t)i.set(n,l);return i}equals(e){if(!e)return!1;if(this===e)return!0;if(this.size!==e.size)return!1;for(let[i,t]of this)if(!e.has(i)||t!==e.get(i))return!1;return!0}sort(e=s.defaultSort){let i=[...this.entries()];i.sort((t,n)=>e(t[1],n[1],t[0],n[0])),super.clear();for(let[t,n]of i)super.set(t,n);return this}intersect(e){let i=new this.constructor[Symbol.species];for(let[t,n]of e)this.has(t)&&i.set(t,n);return i}difference(e){let i=new this.constructor[Symbol.species];for(let[t,n]of e)this.has(t)||i.set(t,n);for(let[t,n]of this)e.has(t)||i.set(t,n);return i}sorted(e=s.defaultSort){return new this.constructor[Symbol.species](this).sort((i,t,n,l)=>e(i,t,n,l))}toJSON(){return[...this.values()]}static defaultSort(e,i){return Number(e>i)||Number(e===i)-1}},r=s;h(r,"Collection"),a(r,"default",s);var V=r;export{r as Collection,V as default};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n * @extends {Map}\n * @property {number} size - The amount of elements in this collection.\n */\nexport class Collection<K, V> extends Map<K, V> {\n\tpublic static readonly default: typeof Collection = Collection;\n\tpublic override ['constructor']: CollectionConstructor;\n\n\t/**\n\t * Identical to [Map.get()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get).\n\t * Gets an element with the specified key, and returns its value, or `undefined` if the element does not exist.\n\t * @param {*} key - The key to get from this collection\n\t * @returns {* | undefined}\n\t */\n\tpublic override get(key: K): V | undefined {\n\t\treturn super.get(key);\n\t}\n\n\t/**\n\t * Identical to [Map.set()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set).\n\t * Sets a new element in the collection with the specified key and value.\n\t * @param {*} key - The key of the element to add\n\t * @param {*} value - The value of the element to add\n\t * @returns {Collection}\n\t */\n\tpublic override set(key: K, value: V): this {\n\t\treturn super.set(key, value);\n\t}\n\n\t/**\n\t * Identical to [Map.has()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has).\n\t * Checks if an element exists in the collection.\n\t * @param {*} key - The key of the element to check for\n\t * @returns {boolean} `true` if the element exists, `false` if it does not exist.\n\t */\n\tpublic override has(key: K): boolean {\n\t\treturn super.has(key);\n\t}\n\n\t/**\n\t * Identical to [Map.delete()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).\n\t * Deletes an element from the collection.\n\t * @param {*} key - The key to delete from the collection\n\t * @returns {boolean} `true` if the element was removed, `false` if the element does not exist.\n\t */\n\tpublic override delete(key: K): boolean {\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Identical to [Map.clear()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear).\n\t * Removes all elements from the collection.\n\t * @returns {undefined}\n\t */\n\tpublic override clear(): void {\n\t\treturn super.clear();\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t * @param {...*} keys - The keys of the elements to check for\n\t * @returns {boolean} `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]): boolean {\n\t\treturn keys.every((k) => super.has(k));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t * @param {...*} keys - The keys of the elements to check for\n\t * @returns {boolean} `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]): boolean {\n\t\treturn keys.some((k) => super.has(k));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t * @param {number} [amount] Amount of values to obtain from the beginning\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the end if\n\t * amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t * @param {number} [amount] Amount of keys to obtain from the beginning\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t * @param {number} [amount] Amount of values to obtain from the end\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t * @param {number} [amount] Amount of keys to obtain from the end\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t * @param {number} [amount] Amount of values to obtain randomly\n\t * @returns {*|Array<*>} A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t * @param {number} [amount] Amount of keys to obtain randomly\n\t * @returns {*|Array<*>} A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).\n\t * <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {*}\n\t * @example collection.find(user => user.username === 'Bob');\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): V | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),\n\t * but returns the key rather than the positional index.\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {*}\n\t * @example collection.findKey(user => user.username === 'Bob');\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): K | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {number} The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): number {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n\t * but returns a Collection instead of an Array.\n\t * @param {Function} fn The function to test with (should return boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.filter(user => user.username === 'Bob');\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection[]}\n\t * @example const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => boolean): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => boolean,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => boolean,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).\n\t * @param {Function} fn Function that produces a new Collection\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.flatMap(guild => guild.members.cache);\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t * @param {Function} fn Function that produces an element of the new array, taking three arguments\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Array}\n\t * @example collection.map(user => user.tag);\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t * @param {Function} fn Function that produces an element of the new collection, taking three arguments\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example collection.mapValues(user => user.tag);\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {boolean}\n\t * @example collection.some(user => user.discriminator === '0000');\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).\n\t * @param {Function} fn Function used to test (should return a boolean)\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {boolean}\n\t * @example collection.every(user => !user.bot);\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).\n\t * @param {Function} fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param {*} [initialValue] Starting value for the accumulator\n\t * @returns {*}\n\t * @example collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t */\n\tpublic reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tlet accumulator!: T;\n\n\t\tif (typeof initialValue !== 'undefined') {\n\t\t\taccumulator = initialValue;\n\t\t\tfor (const [key, val] of this) accumulator = fn(accumulator, val, key, this);\n\t\t\treturn accumulator;\n\t\t}\n\t\tlet first = true;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (first) {\n\t\t\t\taccumulator = val as unknown as T;\n\t\t\t\tfirst = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taccumulator = fn(accumulator, val, key, this);\n\t\t}\n\n\t\t// No items iterated.\n\t\tif (first) {\n\t\t\tthrow new TypeError('Reduce of empty collection with no initial value');\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),\n\t * but returns the collection instead of undefined.\n\t * @param {Function} fn Function to execute for each element\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tthis.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t * @param {Function} fn Function to execute\n\t * @param {*} [thisArg] Value to use as `this` when executing function\n\t * @returns {Collection}\n\t * @example\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t * @returns {Collection}\n\t * @example const newColl = someColl.clone();\n\t */\n\tpublic clone(): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t * @param {...Collection} collections Collections to merge\n\t * @returns {Collection}\n\t * @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t */\n\tpublic concat(...collections: Collection<K, V>[]): Collection<K, V> {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t * @param {Collection} collection Collection to compare with\n\t * @returns {boolean} Whether the collections have identical contents\n\t */\n\tpublic equals(collection: Collection<K, V>): boolean {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t * @param {Function} [compareFunction] Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @returns {Collection}\n\t * @example collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort): this {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [k, v] of entries) {\n\t\t\tsuper.set(k, v);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys are present in both original structures.\n\t * @param {Collection} other The other Collection to filter against\n\t * @returns {Collection}\n\t */\n\tpublic intersect(other: Collection<K, V>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (this.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\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.\n\t * @param {Collection} other The other Collection to filter against\n\t * @returns {Collection}\n\t */\n\tpublic difference(other: Collection<K, V>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (!this.has(k)) coll.set(k, v);\n\t\t}\n\t\tfor (const [k, v] of this) {\n\t\t\tif (!other.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t * @param {Function} [compareFunction] Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @returns {Collection}\n\t * @example collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n}\n\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n\nexport default Collection;\n"],
|
|
5
|
-
"mappings": "+EAcO,mBAA+B,IAAU,CAU/B,IAAI,EAAuB,CAC1C,MAAO,OAAM,IAAI,GAUF,IAAI,EAAQ,EAAgB,CAC3C,MAAO,OAAM,IAAI,EAAK,GASP,IAAI,EAAiB,CACpC,MAAO,OAAM,IAAI,GASF,OAAO,EAAiB,CACvC,MAAO,OAAM,OAAO,GAQL,OAAc,CAC7B,MAAO,OAAM,QAQP,UAAU,EAAoB,CACpC,MAAO,GAAK,MAAM,AAAC,GAAM,MAAM,IAAI,IAQ7B,UAAU,EAAoB,CACpC,MAAO,GAAK,KAAK,AAAC,GAAM,MAAM,IAAI,IAW5B,MAAM,EAAsC,CAClD,GAAI,MAAO,IAAW,YAAa,MAAO,MAAK,SAAS,OAAO,MAC/D,GAAI,EAAS,EAAG,MAAO,MAAK,KAAK,EAAS,IAC1C,EAAS,KAAK,IAAI,KAAK,KAAM,GAC7B,GAAM,GAAO,KAAK,SAClB,MAAO,OAAM,KAAK,CAAE,OAAQ,GAAU,IAAS,EAAK,OAAO,OAWrD,SAAS,EAAsC,CACrD,GAAI,MAAO,IAAW,YAAa,MAAO,MAAK,OAAO,OAAO,MAC7D,GAAI,EAAS,EAAG,MAAO,MAAK,QAAQ,EAAS,IAC7C,EAAS,KAAK,IAAI,KAAK,KAAM,GAC7B,GAAM,GAAO,KAAK,OAClB,MAAO,OAAM,KAAK,CAAE,OAAQ,GAAU,IAAS,EAAK,OAAO,OAWrD,KAAK,EAAsC,CACjD,GAAM,GAAM,CAAC,GAAG,KAAK,UACrB,MAAI,OAAO,IAAW,YAAoB,EAAI,EAAI,OAAS,GACvD,EAAS,EAAU,KAAK,MAAM,EAAS,IACtC,EACE,EAAI,MAAM,CAAC,GADE,GAYd,QA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E,GAAI,EAAE,GAAI,EAAE,KAGnE,MAAM,QAGN,OAAW,CAAC,EAAG,IAAM,GACpB,MAAM,IAAI,EAAG,GAEd,MAAO,MAQD,UAAU,EAA2C,CAC3D,GAAM,GAAO,GAAI,MAAK,YAAY,OAAO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAI,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE9B,MAAO,GAQD,WAAW,EAA2C,CAC5D,GAAM,GAAO,GAAI,MAAK,YAAY,OAAO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAK,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE/B,OAAW,CAAC,EAAG,IAAM,MACpB,AAAK,EAAM,IAAI,IAAI,EAAK,IAAI,EAAG,GAEhC,MAAO,GAaD,OAAO,EAAoC,EAAW,YAA+B,CAC3F,MAAO,IAAI,MAAK,YAAY,OAAO,SAAS,MAAM,KAAK,CAAC,EAAI,EAAI,EAAI,IAAO,EAAgB,EAAI,EAAI,EAAI,IAGjG,QAAS,CAEf,MAAO,CAAC,GAAG,KAAK,gBAGF,aAAe,EAAe,EAAwB,CACpE,MAAO,QAAO,EAAa,IAAgB,OAAO,IAAe,GAAe,IA5lB3E,sBAEW,cADM,AADjB,EACiB,QAA6B,EAimBrD,GAAO,GAAQ",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @internal\n */\nexport interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself\n *\n * @internal\n */\nexport interface Collection<K, V> extends Map<K, V> {\n\tconstructor: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n */\nexport class Collection<K, V> extends Map<K, V> {\n\tpublic static readonly default: typeof Collection = Collection;\n\n\t/**\n\t * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.\n\t *\n\t * @param key The key to get if it exists, or set otherwise\n\t * @param defaultValueGenerator A function that generates the default value\n\t *\n\t * @example\n\t * collection.ensure(guildId, () => defaultGuildConfig);\n\t */\n\tpublic ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {\n\t\tif (this.has(key)) return this.get(key)!;\n\t\tconst defaultValue = defaultValueGenerator(key, this);\n\t\tthis.set(key, defaultValue);\n\t\treturn defaultValue;\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t *\n\t * @returns `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]) {\n\t\treturn keys.every((k) => super.has(k));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t *\n\t * @returns `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]) {\n\t\treturn keys.some((k) => super.has(k));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t *\n\t * @param amount Amount of values to obtain from the beginning\n\t *\n\t * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t *\n\t * @param amount Amount of keys to obtain from the beginning\n\t *\n\t * @returns A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (typeof amount === 'undefined') return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t *\n\t * @param amount Amount of values to obtain from the end\n\t *\n\t * @returns A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t *\n\t * @param amount Amount of keys to obtain from the end\n\t *\n\t * @returns A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).\n\t * Returns the item at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index The index of the element to obtain\n\t */\n\tpublic at(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.values()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Identical to [Array.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at).\n\t * Returns the key at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index The index of the key to obtain\n\t */\n\tpublic keyAt(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.keys()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t *\n\t * @param amount Amount of values to obtain randomly\n\t *\n\t * @returns A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V | undefined;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t *\n\t * @param amount Amount of keys to obtain randomly\n\t *\n\t * @returns A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K | undefined;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0],\n\t\t);\n\t}\n\n\t/**\n\t * Identical to [Array.reverse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\n\t * but returns a Collection instead of an Array.\n\t */\n\tpublic reverse() {\n\t\tconst entries = [...this.entries()].reverse();\n\t\tthis.clear();\n\t\tfor (const [key, value] of entries) this.set(key, value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).\n\t * <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.find(user => user.username === 'Bob');\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): V | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),\n\t * but returns the key rather than the positional index.\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.findKey(user => user.username === 'Bob');\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): K | undefined {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @returns The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): number {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n\t * but returns a Collection instead of an Array.\n\t *\n\t * @param fn The function to test with (should return boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.filter(user => user.username === 'Bob');\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => boolean): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => boolean,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => boolean,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).\n\t *\n\t * @param fn Function that produces a new Collection\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.flatMap(guild => guild.members.cache);\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t *\n\t * @param fn Function that produces an element of the new array, taking three arguments\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.map(user => user.tag);\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).\n\t *\n\t * @param fn Function that produces an element of the new collection, taking three arguments\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.mapValues(user => user.tag);\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.some(user => user.discriminator === '0000');\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).\n\t *\n\t * @param fn Function used to test (should return a boolean)\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection.every(user => !user.bot);\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => boolean, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): boolean {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).\n\t *\n\t * @param fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param initialValue Starting value for the accumulator\n\t *\n\t * @example\n\t * collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t */\n\tpublic reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tlet accumulator!: T;\n\n\t\tif (typeof initialValue !== 'undefined') {\n\t\t\taccumulator = initialValue;\n\t\t\tfor (const [key, val] of this) accumulator = fn(accumulator, val, key, this);\n\t\t\treturn accumulator;\n\t\t}\n\t\tlet first = true;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (first) {\n\t\t\t\taccumulator = val as unknown as T;\n\t\t\t\tfirst = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taccumulator = fn(accumulator, val, key, this);\n\t\t}\n\n\t\t// No items iterated.\n\t\tif (first) {\n\t\t\tthrow new TypeError('Reduce of empty collection with no initial value');\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),\n\t * but returns the collection instead of undefined.\n\t *\n\t * @param fn Function to execute for each element\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tthis.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t *\n\t * @param fn Function to execute\n\t * @param thisArg Value to use as `this` when executing function\n\t *\n\t * @example\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t *\n\t * @example\n\t * const newColl = someColl.clone();\n\t */\n\tpublic clone() {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t *\n\t * @param collections Collections to merge\n\t *\n\t * @example\n\t * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t */\n\tpublic concat(...collections: Collection<K, V>[]) {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t *\n\t * @param collection Collection to compare with\n\t *\n\t * @returns Whether the collections have identical contents\n\t */\n\tpublic equals(collection: Collection<K, V>) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.\n\t *\n\t * @example\n\t * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [k, v] of entries) {\n\t\t\tsuper.set(k, v);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys are present in both original structures.\n\t *\n\t * @param other The other Collection to filter against\n\t */\n\tpublic intersect(other: Collection<K, V>) {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (this.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\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.\n\t *\n\t * @param other The other Collection to filter against\n\t */\n\tpublic difference(other: Collection<K, V>) {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [k, v] of other) {\n\t\t\tif (!this.has(k)) coll.set(k, v);\n\t\t}\n\t\tfor (const [k, v] of this) {\n\t\t\tif (!other.has(k)) coll.set(k, v);\n\t\t}\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t *\n\t * @example\n\t * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n}\n\n/**\n * @internal\n */\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n\nexport default Collection;\n"],"mappings":"2NAwBO,mBAA+B,IAAU,CAYxC,OAAO,EAAQ,EAA2D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AE,GAAI,EAAE,KAGnE,MAAM,QAGN,OAAW,CAAC,EAAG,IAAM,GACpB,MAAM,IAAI,EAAG,GAEd,MAAO,MAQD,UAAU,EAAyB,CACzC,GAAM,GAAO,GAAI,MAAK,YAAY,OAAO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAI,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE9B,MAAO,GAQD,WAAW,EAAyB,CAC1C,GAAM,GAAO,GAAI,MAAK,YAAY,OAAO,SACzC,OAAW,CAAC,EAAG,IAAM,GACpB,AAAK,KAAK,IAAI,IAAI,EAAK,IAAI,EAAG,GAE/B,OAAW,CAAC,EAAG,IAAM,MACpB,AAAK,EAAM,IAAI,IAAI,EAAK,IAAI,EAAG,GAEhC,MAAO,GAeD,OAAO,EAAoC,EAAW,YAAa,CACzE,MAAO,IAAI,MAAK,YAAY,OAAO,SAAS,MAAM,KAAK,CAAC,EAAI,EAAI,EAAI,IAAO,EAAgB,EAAI,EAAI,EAAI,IAGjG,QAAS,CAEf,MAAO,CAAC,GAAG,KAAK,gBAGF,aAAe,EAAe,EAAwB,CACpE,MAAO,QAAO,EAAa,IAAgB,OAAO,IAAe,GAAe,IA7oB3E,sBACiB,EADjB,EACiB,UAA6B,GAqpBrD,GAAO,GAAQ","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordjs/collection",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Utility data structure used in Discord.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"pretest": "npm run build",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"lint:fix": "eslint src --ext mjs,js,ts --fix",
|
|
13
13
|
"format": "prettier --write **/*.{ts,js,json,yml,yaml}",
|
|
14
14
|
"prepare": "is-ci || husky install",
|
|
15
|
-
"docs": "
|
|
16
|
-
"
|
|
15
|
+
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs",
|
|
16
|
+
"prepublishOnly": "npm run lint && npm run test",
|
|
17
17
|
"release": "standard-version --preset angular"
|
|
18
18
|
},
|
|
19
19
|
"main": "./dist/index.js",
|
|
@@ -51,30 +51,29 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/discordjs/collection",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/
|
|
55
|
-
"@babel/
|
|
56
|
-
"@babel/preset-
|
|
57
|
-
"@
|
|
58
|
-
"@commitlint/
|
|
59
|
-
"@
|
|
60
|
-
"@types/jest": "^27.0.
|
|
54
|
+
"@babel/core": "^7.16.5",
|
|
55
|
+
"@babel/preset-env": "^7.16.5",
|
|
56
|
+
"@babel/preset-typescript": "^7.16.5",
|
|
57
|
+
"@commitlint/cli": "^15.0.0",
|
|
58
|
+
"@commitlint/config-angular": "^15.0.0",
|
|
59
|
+
"@discordjs/ts-docgen": "^0.3.4",
|
|
60
|
+
"@types/jest": "^27.0.3",
|
|
61
61
|
"@types/node": "^16.11.6",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
63
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
-
"
|
|
65
|
-
"eslint": "^
|
|
66
|
-
"eslint-config-marine": "^9.0.6",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
63
|
+
"@typescript-eslint/parser": "^5.8.0",
|
|
64
|
+
"eslint": "^8.5.0",
|
|
65
|
+
"eslint-config-marine": "^9.1.0",
|
|
67
66
|
"eslint-config-prettier": "^8.3.0",
|
|
68
67
|
"eslint-plugin-prettier": "^4.0.0",
|
|
69
68
|
"husky": "^7.0.4",
|
|
70
69
|
"is-ci": "^3.0.1",
|
|
71
|
-
"jest": "^27.
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"prettier": "^2.4.1",
|
|
70
|
+
"jest": "^27.4.5",
|
|
71
|
+
"lint-staged": "^12.1.4",
|
|
72
|
+
"prettier": "^2.5.1",
|
|
75
73
|
"standard-version": "^9.3.2",
|
|
76
|
-
"tsup": "^5.
|
|
77
|
-
"
|
|
74
|
+
"tsup": "^5.11.8",
|
|
75
|
+
"typedoc": "^0.22.10",
|
|
76
|
+
"typescript": "^4.5.4"
|
|
78
77
|
},
|
|
79
78
|
"engines": {
|
|
80
79
|
"node": ">=16.0.0",
|