@discordjs/collection 2.0.0-dev.1690416583-8f4256d.0 → 2.0.0-dev.1699445028-2bda883a0
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/README.md +1 -1
- package/dist/index.d.mts +101 -23
- package/dist/index.d.ts +101 -23
- package/dist/index.js +128 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +37 -30
- package/CHANGELOG.md +0 -152
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -132,8 +132,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
132
132
|
* should use the `get` method. See
|
|
133
133
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.
|
|
134
134
|
*
|
|
135
|
-
* @param fn - The function to test with (should return boolean)
|
|
136
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
135
|
+
* @param fn - The function to test with (should return a boolean)
|
|
136
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
137
137
|
* @example
|
|
138
138
|
* ```ts
|
|
139
139
|
* collection.find(user => user.username === 'Bob');
|
|
@@ -148,8 +148,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
148
148
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
|
|
149
149
|
* but returns the key rather than the positional index.
|
|
150
150
|
*
|
|
151
|
-
* @param fn - The function to test with (should return boolean)
|
|
152
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
151
|
+
* @param fn - The function to test with (should return a boolean)
|
|
152
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
153
153
|
* @example
|
|
154
154
|
* ```ts
|
|
155
155
|
* collection.findKey(user => user.username === 'Bob');
|
|
@@ -159,11 +159,34 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
159
159
|
findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;
|
|
160
160
|
findKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined;
|
|
161
161
|
findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Searches for a last item where the given function returns a truthy value. This behaves like
|
|
164
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast | Array.findLast()}.
|
|
165
|
+
*
|
|
166
|
+
* @param fn - The function to test with (should return a boolean)
|
|
167
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
168
|
+
*/
|
|
169
|
+
findLast<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
|
|
170
|
+
findLast(fn: (value: V, key: K, collection: this) => unknown): V | undefined;
|
|
171
|
+
findLast<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): V2 | undefined;
|
|
172
|
+
findLast<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Searches for the key of a last item where the given function returns a truthy value. This behaves like
|
|
175
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | Array.findLastIndex()},
|
|
176
|
+
* but returns the key rather than the positional index.
|
|
177
|
+
*
|
|
178
|
+
* @param fn - The function to test with (should return a boolean)
|
|
179
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
180
|
+
*/
|
|
181
|
+
findLastKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
|
|
182
|
+
findLastKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;
|
|
183
|
+
findLastKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined;
|
|
184
|
+
findLastKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;
|
|
162
185
|
/**
|
|
163
186
|
* Removes items that satisfy the provided filter function.
|
|
164
187
|
*
|
|
165
188
|
* @param fn - Function used to test (should return a boolean)
|
|
166
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
189
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
167
190
|
* @returns The number of removed entries
|
|
168
191
|
*/
|
|
169
192
|
sweep(fn: (value: V, key: K, collection: this) => unknown): number;
|
|
@@ -173,8 +196,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
173
196
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
|
|
174
197
|
* but returns a Collection instead of an Array.
|
|
175
198
|
*
|
|
176
|
-
* @param fn - The function to test with (should return boolean)
|
|
177
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
199
|
+
* @param fn - The function to test with (should return a boolean)
|
|
200
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
178
201
|
* @example
|
|
179
202
|
* ```ts
|
|
180
203
|
* collection.filter(user => user.username === 'Bob');
|
|
@@ -191,7 +214,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
191
214
|
* contains the items that passed and the second contains the items that failed.
|
|
192
215
|
*
|
|
193
216
|
* @param fn - Function used to test (should return a boolean)
|
|
194
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
217
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
195
218
|
* @example
|
|
196
219
|
* ```ts
|
|
197
220
|
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
|
@@ -208,7 +231,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
208
231
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
|
|
209
232
|
*
|
|
210
233
|
* @param fn - Function that produces a new Collection
|
|
211
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
234
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
212
235
|
* @example
|
|
213
236
|
* ```ts
|
|
214
237
|
* collection.flatMap(guild => guild.members.cache);
|
|
@@ -221,7 +244,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
221
244
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
222
245
|
*
|
|
223
246
|
* @param fn - Function that produces an element of the new array, taking three arguments
|
|
224
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
247
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
225
248
|
* @example
|
|
226
249
|
* ```ts
|
|
227
250
|
* collection.map(user => user.tag);
|
|
@@ -234,7 +257,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
234
257
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
235
258
|
*
|
|
236
259
|
* @param fn - Function that produces an element of the new collection, taking three arguments
|
|
237
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
260
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
238
261
|
* @example
|
|
239
262
|
* ```ts
|
|
240
263
|
* collection.mapValues(user => user.tag);
|
|
@@ -247,7 +270,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
247
270
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
|
|
248
271
|
*
|
|
249
272
|
* @param fn - Function used to test (should return a boolean)
|
|
250
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
273
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
251
274
|
* @example
|
|
252
275
|
* ```ts
|
|
253
276
|
* collection.some(user => user.discriminator === '0000');
|
|
@@ -260,7 +283,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
260
283
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
|
|
261
284
|
*
|
|
262
285
|
* @param fn - Function used to test (should return a boolean)
|
|
263
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
286
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
264
287
|
* @example
|
|
265
288
|
* ```ts
|
|
266
289
|
* collection.every(user => !user.bot);
|
|
@@ -285,13 +308,21 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
285
308
|
* ```
|
|
286
309
|
*/
|
|
287
310
|
reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
|
311
|
+
/**
|
|
312
|
+
* Applies a function to produce a single value. Identical in behavior to
|
|
313
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
|
314
|
+
*
|
|
315
|
+
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
|
316
|
+
* @param initialValue - Starting value for the accumulator
|
|
317
|
+
*/
|
|
318
|
+
reduceRight<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
|
288
319
|
/**
|
|
289
320
|
* Identical to
|
|
290
321
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
|
|
291
322
|
* but returns the collection instead of undefined.
|
|
292
323
|
*
|
|
293
324
|
* @param fn - Function to execute for each element
|
|
294
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
325
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
295
326
|
* @example
|
|
296
327
|
* ```ts
|
|
297
328
|
* collection
|
|
@@ -306,7 +337,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
306
337
|
* Runs a function on the collection and returns the collection.
|
|
307
338
|
*
|
|
308
339
|
* @param fn - Function to execute
|
|
309
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
340
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
310
341
|
* @example
|
|
311
342
|
* ```ts
|
|
312
343
|
* collection
|
|
@@ -359,23 +390,65 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
359
390
|
*/
|
|
360
391
|
sort(compareFunction?: Comparator<K, V>): this;
|
|
361
392
|
/**
|
|
362
|
-
* The
|
|
393
|
+
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
|
394
|
+
*
|
|
395
|
+
* @param other - The other Collection to filter against
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
399
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
400
|
+
* const intersection = col1.intersection(col2);
|
|
401
|
+
* console.log(col1.intersection(col2));
|
|
402
|
+
* // => Collection { 'a' => 1 }
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
intersection<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
406
|
+
/**
|
|
407
|
+
* Returns a new collection containing the items where the key is present in either of the collections.
|
|
408
|
+
*
|
|
409
|
+
* @remarks
|
|
363
410
|
*
|
|
411
|
+
* If the collections have any items with the same key, the value from the first collection will be used.
|
|
364
412
|
* @param other - The other Collection to filter against
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
416
|
+
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
|
417
|
+
* const union = col1.union(col2);
|
|
418
|
+
* console.log(union);
|
|
419
|
+
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
|
420
|
+
* ```
|
|
365
421
|
*/
|
|
366
|
-
|
|
422
|
+
union<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
367
423
|
/**
|
|
368
|
-
*
|
|
424
|
+
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
|
369
425
|
*
|
|
370
426
|
* @param other - The other Collection to filter against
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
430
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
431
|
+
* console.log(col1.difference(col2));
|
|
432
|
+
* // => Collection { 'b' => 2 }
|
|
433
|
+
* console.log(col2.difference(col1));
|
|
434
|
+
* // => Collection { 'c' => 3 }
|
|
435
|
+
* ```
|
|
371
436
|
*/
|
|
372
|
-
|
|
437
|
+
difference<T>(other: ReadonlyCollection<K, T>): Collection<K, V>;
|
|
373
438
|
/**
|
|
374
|
-
*
|
|
439
|
+
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
|
375
440
|
*
|
|
376
441
|
* @param other - The other Collection to filter against
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
445
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
446
|
+
* const symmetricDifference = col1.symmetricDifference(col2);
|
|
447
|
+
* console.log(col1.symmetricDifference(col2));
|
|
448
|
+
* // => Collection { 'b' => 2, 'c' => 3 }
|
|
449
|
+
* ```
|
|
377
450
|
*/
|
|
378
|
-
|
|
451
|
+
symmetricDifference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
379
452
|
/**
|
|
380
453
|
* Merges two Collections together into a new Collection.
|
|
381
454
|
*
|
|
@@ -405,6 +478,11 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
405
478
|
* ```
|
|
406
479
|
*/
|
|
407
480
|
merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>;
|
|
481
|
+
/**
|
|
482
|
+
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
|
483
|
+
* but returns a Collection instead of an Array.
|
|
484
|
+
*/
|
|
485
|
+
toReversed(): Collection<K, V>;
|
|
408
486
|
/**
|
|
409
487
|
* The sorted method sorts the items of a collection and returns it.
|
|
410
488
|
* The sort is not necessarily stable in Node 10 or older.
|
|
@@ -418,8 +496,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
418
496
|
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
419
497
|
* ```
|
|
420
498
|
*/
|
|
421
|
-
|
|
422
|
-
toJSON(): V[];
|
|
499
|
+
toSorted(compareFunction?: Comparator<K, V>): Collection<K, V>;
|
|
500
|
+
toJSON(): [K, V][];
|
|
423
501
|
private static defaultSort;
|
|
424
502
|
/**
|
|
425
503
|
* Creates a Collection from a list of entries.
|
package/dist/index.d.ts
CHANGED
|
@@ -132,8 +132,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
132
132
|
* should use the `get` method. See
|
|
133
133
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.
|
|
134
134
|
*
|
|
135
|
-
* @param fn - The function to test with (should return boolean)
|
|
136
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
135
|
+
* @param fn - The function to test with (should return a boolean)
|
|
136
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
137
137
|
* @example
|
|
138
138
|
* ```ts
|
|
139
139
|
* collection.find(user => user.username === 'Bob');
|
|
@@ -148,8 +148,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
148
148
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
|
|
149
149
|
* but returns the key rather than the positional index.
|
|
150
150
|
*
|
|
151
|
-
* @param fn - The function to test with (should return boolean)
|
|
152
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
151
|
+
* @param fn - The function to test with (should return a boolean)
|
|
152
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
153
153
|
* @example
|
|
154
154
|
* ```ts
|
|
155
155
|
* collection.findKey(user => user.username === 'Bob');
|
|
@@ -159,11 +159,34 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
159
159
|
findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;
|
|
160
160
|
findKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined;
|
|
161
161
|
findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Searches for a last item where the given function returns a truthy value. This behaves like
|
|
164
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast | Array.findLast()}.
|
|
165
|
+
*
|
|
166
|
+
* @param fn - The function to test with (should return a boolean)
|
|
167
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
168
|
+
*/
|
|
169
|
+
findLast<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
|
|
170
|
+
findLast(fn: (value: V, key: K, collection: this) => unknown): V | undefined;
|
|
171
|
+
findLast<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): V2 | undefined;
|
|
172
|
+
findLast<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Searches for the key of a last item where the given function returns a truthy value. This behaves like
|
|
175
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | Array.findLastIndex()},
|
|
176
|
+
* but returns the key rather than the positional index.
|
|
177
|
+
*
|
|
178
|
+
* @param fn - The function to test with (should return a boolean)
|
|
179
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
180
|
+
*/
|
|
181
|
+
findLastKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
|
|
182
|
+
findLastKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;
|
|
183
|
+
findLastKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined;
|
|
184
|
+
findLastKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;
|
|
162
185
|
/**
|
|
163
186
|
* Removes items that satisfy the provided filter function.
|
|
164
187
|
*
|
|
165
188
|
* @param fn - Function used to test (should return a boolean)
|
|
166
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
189
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
167
190
|
* @returns The number of removed entries
|
|
168
191
|
*/
|
|
169
192
|
sweep(fn: (value: V, key: K, collection: this) => unknown): number;
|
|
@@ -173,8 +196,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
173
196
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
|
|
174
197
|
* but returns a Collection instead of an Array.
|
|
175
198
|
*
|
|
176
|
-
* @param fn - The function to test with (should return boolean)
|
|
177
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
199
|
+
* @param fn - The function to test with (should return a boolean)
|
|
200
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
178
201
|
* @example
|
|
179
202
|
* ```ts
|
|
180
203
|
* collection.filter(user => user.username === 'Bob');
|
|
@@ -191,7 +214,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
191
214
|
* contains the items that passed and the second contains the items that failed.
|
|
192
215
|
*
|
|
193
216
|
* @param fn - Function used to test (should return a boolean)
|
|
194
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
217
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
195
218
|
* @example
|
|
196
219
|
* ```ts
|
|
197
220
|
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
|
@@ -208,7 +231,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
208
231
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
|
|
209
232
|
*
|
|
210
233
|
* @param fn - Function that produces a new Collection
|
|
211
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
234
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
212
235
|
* @example
|
|
213
236
|
* ```ts
|
|
214
237
|
* collection.flatMap(guild => guild.members.cache);
|
|
@@ -221,7 +244,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
221
244
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
222
245
|
*
|
|
223
246
|
* @param fn - Function that produces an element of the new array, taking three arguments
|
|
224
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
247
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
225
248
|
* @example
|
|
226
249
|
* ```ts
|
|
227
250
|
* collection.map(user => user.tag);
|
|
@@ -234,7 +257,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
234
257
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
235
258
|
*
|
|
236
259
|
* @param fn - Function that produces an element of the new collection, taking three arguments
|
|
237
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
260
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
238
261
|
* @example
|
|
239
262
|
* ```ts
|
|
240
263
|
* collection.mapValues(user => user.tag);
|
|
@@ -247,7 +270,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
247
270
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
|
|
248
271
|
*
|
|
249
272
|
* @param fn - Function used to test (should return a boolean)
|
|
250
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
273
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
251
274
|
* @example
|
|
252
275
|
* ```ts
|
|
253
276
|
* collection.some(user => user.discriminator === '0000');
|
|
@@ -260,7 +283,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
260
283
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
|
|
261
284
|
*
|
|
262
285
|
* @param fn - Function used to test (should return a boolean)
|
|
263
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
286
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
264
287
|
* @example
|
|
265
288
|
* ```ts
|
|
266
289
|
* collection.every(user => !user.bot);
|
|
@@ -285,13 +308,21 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
285
308
|
* ```
|
|
286
309
|
*/
|
|
287
310
|
reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
|
311
|
+
/**
|
|
312
|
+
* Applies a function to produce a single value. Identical in behavior to
|
|
313
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
|
314
|
+
*
|
|
315
|
+
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
|
316
|
+
* @param initialValue - Starting value for the accumulator
|
|
317
|
+
*/
|
|
318
|
+
reduceRight<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
|
288
319
|
/**
|
|
289
320
|
* Identical to
|
|
290
321
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
|
|
291
322
|
* but returns the collection instead of undefined.
|
|
292
323
|
*
|
|
293
324
|
* @param fn - Function to execute for each element
|
|
294
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
325
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
295
326
|
* @example
|
|
296
327
|
* ```ts
|
|
297
328
|
* collection
|
|
@@ -306,7 +337,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
306
337
|
* Runs a function on the collection and returns the collection.
|
|
307
338
|
*
|
|
308
339
|
* @param fn - Function to execute
|
|
309
|
-
* @param thisArg - Value to use as `this` when executing function
|
|
340
|
+
* @param thisArg - Value to use as `this` when executing the function
|
|
310
341
|
* @example
|
|
311
342
|
* ```ts
|
|
312
343
|
* collection
|
|
@@ -359,23 +390,65 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
359
390
|
*/
|
|
360
391
|
sort(compareFunction?: Comparator<K, V>): this;
|
|
361
392
|
/**
|
|
362
|
-
* The
|
|
393
|
+
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
|
394
|
+
*
|
|
395
|
+
* @param other - The other Collection to filter against
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
399
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
400
|
+
* const intersection = col1.intersection(col2);
|
|
401
|
+
* console.log(col1.intersection(col2));
|
|
402
|
+
* // => Collection { 'a' => 1 }
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
intersection<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
406
|
+
/**
|
|
407
|
+
* Returns a new collection containing the items where the key is present in either of the collections.
|
|
408
|
+
*
|
|
409
|
+
* @remarks
|
|
363
410
|
*
|
|
411
|
+
* If the collections have any items with the same key, the value from the first collection will be used.
|
|
364
412
|
* @param other - The other Collection to filter against
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
416
|
+
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
|
417
|
+
* const union = col1.union(col2);
|
|
418
|
+
* console.log(union);
|
|
419
|
+
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
|
420
|
+
* ```
|
|
365
421
|
*/
|
|
366
|
-
|
|
422
|
+
union<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
367
423
|
/**
|
|
368
|
-
*
|
|
424
|
+
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
|
369
425
|
*
|
|
370
426
|
* @param other - The other Collection to filter against
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
430
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
431
|
+
* console.log(col1.difference(col2));
|
|
432
|
+
* // => Collection { 'b' => 2 }
|
|
433
|
+
* console.log(col2.difference(col1));
|
|
434
|
+
* // => Collection { 'c' => 3 }
|
|
435
|
+
* ```
|
|
371
436
|
*/
|
|
372
|
-
|
|
437
|
+
difference<T>(other: ReadonlyCollection<K, T>): Collection<K, V>;
|
|
373
438
|
/**
|
|
374
|
-
*
|
|
439
|
+
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
|
375
440
|
*
|
|
376
441
|
* @param other - The other Collection to filter against
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
|
445
|
+
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
|
446
|
+
* const symmetricDifference = col1.symmetricDifference(col2);
|
|
447
|
+
* console.log(col1.symmetricDifference(col2));
|
|
448
|
+
* // => Collection { 'b' => 2, 'c' => 3 }
|
|
449
|
+
* ```
|
|
377
450
|
*/
|
|
378
|
-
|
|
451
|
+
symmetricDifference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
|
|
379
452
|
/**
|
|
380
453
|
* Merges two Collections together into a new Collection.
|
|
381
454
|
*
|
|
@@ -405,6 +478,11 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
405
478
|
* ```
|
|
406
479
|
*/
|
|
407
480
|
merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>;
|
|
481
|
+
/**
|
|
482
|
+
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
|
483
|
+
* but returns a Collection instead of an Array.
|
|
484
|
+
*/
|
|
485
|
+
toReversed(): Collection<K, V>;
|
|
408
486
|
/**
|
|
409
487
|
* The sorted method sorts the items of a collection and returns it.
|
|
410
488
|
* The sort is not necessarily stable in Node 10 or older.
|
|
@@ -418,8 +496,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
418
496
|
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
419
497
|
* ```
|
|
420
498
|
*/
|
|
421
|
-
|
|
422
|
-
toJSON(): V[];
|
|
499
|
+
toSorted(compareFunction?: Comparator<K, V>): Collection<K, V>;
|
|
500
|
+
toJSON(): [K, V][];
|
|
423
501
|
private static defaultSort;
|
|
424
502
|
/**
|
|
425
503
|
* Creates a Collection from a list of entries.
|