UNPKG

27.1 kBTypeScriptView Raw
1/**
2 * @internal
3 */
4interface CollectionConstructor {
5 new (): Collection<unknown, unknown>;
6 new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
7 new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
8 readonly prototype: Collection<unknown, unknown>;
9 readonly [Symbol.species]: CollectionConstructor;
10}
11/**
12 * Represents an immutable version of a collection
13 */
14type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
15/**
16 * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
17 *
18 * @internal
19 */
20interface Collection<Key, Value> extends Map<Key, Value> {
21 constructor: CollectionConstructor;
22}
23/**
24 * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
25 * an ID, for significantly improved performance and ease-of-use.
26 *
27 * @typeParam Key - The key type this collection holds
28 * @typeParam Value - The value type this collection holds
29 */
30declare class Collection<Key, Value> extends Map<Key, Value> {
31 /**
32 * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
33 *
34 * @param key - The key to get if it exists, or set otherwise
35 * @param defaultValueGenerator - A function that generates the default value
36 * @example
37 * ```ts
38 * collection.ensure(guildId, () => defaultGuildConfig);
39 * ```
40 */
41 ensure(key: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
42 /**
43 * Checks if all of the elements exist in the collection.
44 *
45 * @param keys - The keys of the elements to check for
46 * @returns `true` if all of the elements exist, `false` if at least one does not exist.
47 */
48 hasAll(...keys: Key[]): boolean;
49 /**
50 * Checks if any of the elements exist in the collection.
51 *
52 * @param keys - The keys of the elements to check for
53 * @returns `true` if any of the elements exist, `false` if none exist.
54 */
55 hasAny(...keys: Key[]): boolean;
56 /**
57 * Obtains the first value(s) in this collection.
58 *
59 * @param amount - Amount of values to obtain from the beginning
60 * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
61 */
62 first(): Value | undefined;
63 first(amount: number): Value[];
64 /**
65 * Obtains the first key(s) in this collection.
66 *
67 * @param amount - Amount of keys to obtain from the beginning
68 * @returns A single key if no amount is provided or an array of keys, starting from the end if
69 * amount is negative
70 */
71 firstKey(): Key | undefined;
72 firstKey(amount: number): Key[];
73 /**
74 * Obtains the last value(s) in this collection.
75 *
76 * @param amount - Amount of values to obtain from the end
77 * @returns A single value if no amount is provided or an array of values, starting from the start if
78 * amount is negative
79 */
80 last(): Value | undefined;
81 last(amount: number): Value[];
82 /**
83 * Obtains the last key(s) in this collection.
84 *
85 * @param amount - Amount of keys to obtain from the end
86 * @returns A single key if no amount is provided or an array of keys, starting from the start if
87 * amount is negative
88 */
89 lastKey(): Key | undefined;
90 lastKey(amount: number): Key[];
91 /**
92 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
93 * Returns the item at a given index, allowing for positive and negative integers.
94 * Negative integers count back from the last item in the collection.
95 *
96 * @param index - The index of the element to obtain
97 */
98 at(index: number): Value | undefined;
99 /**
100 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
101 * Returns the key at a given index, allowing for positive and negative integers.
102 * Negative integers count back from the last item in the collection.
103 *
104 * @param index - The index of the key to obtain
105 */
106 keyAt(index: number): Key | undefined;
107 /**
108 * Obtains unique random value(s) from this collection.
109 *
110 * @param amount - Amount of values to obtain randomly
111 * @returns A single value if no amount is provided or an array of values
112 */
113 random(): Value | undefined;
114 random(amount: number): Value[];
115 /**
116 * Obtains unique random key(s) from this collection.
117 *
118 * @param amount - Amount of keys to obtain randomly
119 * @returns A single key if no amount is provided or an array
120 */
121 randomKey(): Key | undefined;
122 randomKey(amount: number): Key[];
123 /**
124 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
125 * but returns a Collection instead of an Array.
126 */
127 reverse(): this;
128 /**
129 * Searches for a single item where the given function returns a truthy value. This behaves like
130 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}.
131 * All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you
132 * should use the `get` method. See
133 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.
134 *
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 * @example
138 * ```ts
139 * collection.find(user => user.username === 'Bob');
140 * ```
141 */
142 find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
143 find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
144 find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
145 find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
146 /**
147 * Searches for the key of a single item where the given function returns a truthy value. This behaves like
148 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
149 * but returns the key rather than the positional index.
150 *
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 * @example
154 * ```ts
155 * collection.findKey(user => user.username === 'Bob');
156 * ```
157 */
158 findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
159 findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
160 findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
161 findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | 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<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
170 findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
171 findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
172 findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | 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<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
182 findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
183 findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
184 findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
185 /**
186 * Removes items that satisfy the provided filter function.
187 *
188 * @param fn - Function used to test (should return a boolean)
189 * @param thisArg - Value to use as `this` when executing the function
190 * @returns The number of removed entries
191 */
192 sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
193 sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): number;
194 /**
195 * Identical to
196 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
197 * but returns a Collection instead of an Array.
198 *
199 * @param fn - The function to test with (should return a boolean)
200 * @param thisArg - Value to use as `this` when executing the function
201 * @example
202 * ```ts
203 * collection.filter(user => user.username === 'Bob');
204 * ```
205 */
206 filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
207 filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
208 filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
209 filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
210 filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
211 filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
212 /**
213 * Partitions the collection into two collections where the first collection
214 * contains the items that passed and the second contains the items that failed.
215 *
216 * @param fn - Function used to test (should return a boolean)
217 * @param thisArg - Value to use as `this` when executing the function
218 * @example
219 * ```ts
220 * const [big, small] = collection.partition(guild => guild.memberCount > 250);
221 * ```
222 */
223 partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
224 partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
225 partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
226 partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
227 partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
228 partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
229 /**
230 * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
231 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
232 *
233 * @param fn - Function that produces a new Collection
234 * @param thisArg - Value to use as `this` when executing the function
235 * @example
236 * ```ts
237 * collection.flatMap(guild => guild.members.cache);
238 * ```
239 */
240 flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
241 flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
242 /**
243 * Maps each item to another value into an array. Identical in behavior to
244 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
245 *
246 * @param fn - Function that produces an element of the new array, taking three arguments
247 * @param thisArg - Value to use as `this` when executing the function
248 * @example
249 * ```ts
250 * collection.map(user => user.tag);
251 * ```
252 */
253 map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
254 map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
255 /**
256 * Maps each item to another value into a collection. Identical in behavior to
257 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
258 *
259 * @param fn - Function that produces an element of the new collection, taking three arguments
260 * @param thisArg - Value to use as `this` when executing the function
261 * @example
262 * ```ts
263 * collection.mapValues(user => user.tag);
264 * ```
265 */
266 mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
267 mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
268 /**
269 * Checks if there exists an item that passes a test. Identical in behavior to
270 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
271 *
272 * @param fn - Function used to test (should return a boolean)
273 * @param thisArg - Value to use as `this` when executing the function
274 * @example
275 * ```ts
276 * collection.some(user => user.discriminator === '0000');
277 * ```
278 */
279 some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
280 some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
281 /**
282 * Checks if all items passes a test. Identical in behavior to
283 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
284 *
285 * @param fn - Function used to test (should return a boolean)
286 * @param thisArg - Value to use as `this` when executing the function
287 * @example
288 * ```ts
289 * collection.every(user => !user.bot);
290 * ```
291 */
292 every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
293 every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
294 every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
295 every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
296 every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
297 every<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
298 /**
299 * Applies a function to produce a single value. Identical in behavior to
300 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
301 *
302 * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
303 * and `collection`
304 * @param initialValue - Starting value for the accumulator
305 * @example
306 * ```ts
307 * collection.reduce((acc, guild) => acc + guild.memberCount, 0);
308 * ```
309 */
310 reduce(fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value, initialValue?: Value): Value;
311 reduce<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue: InitialValue): InitialValue;
312 /**
313 * Applies a function to produce a single value. Identical in behavior to
314 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
315 *
316 * @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
317 * @param initialValue - Starting value for the accumulator
318 */
319 reduceRight(fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value, initialValue?: Value): Value;
320 reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue: InitialValue): InitialValue;
321 /**
322 * Identical to
323 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
324 * but returns the collection instead of undefined.
325 *
326 * @param fn - Function to execute for each element
327 * @param thisArg - Value to use as `this` when executing the function
328 * @example
329 * ```ts
330 * collection
331 * .each(user => console.log(user.username))
332 * .filter(user => user.bot)
333 * .each(user => console.log(user.username));
334 * ```
335 */
336 each(fn: (value: Value, key: Key, collection: this) => void): this;
337 each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): this;
338 /**
339 * Runs a function on the collection and returns the collection.
340 *
341 * @param fn - Function to execute
342 * @param thisArg - Value to use as `this` when executing the function
343 * @example
344 * ```ts
345 * collection
346 * .tap(coll => console.log(coll.size))
347 * .filter(user => user.bot)
348 * .tap(coll => console.log(coll.size))
349 * ```
350 */
351 tap(fn: (collection: this) => void): this;
352 tap<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
353 /**
354 * Creates an identical shallow copy of this collection.
355 *
356 * @example
357 * ```ts
358 * const newColl = someColl.clone();
359 * ```
360 */
361 clone(): Collection<Key, Value>;
362 /**
363 * Combines this collection with others into a new collection. None of the source collections are modified.
364 *
365 * @param collections - Collections to merge
366 * @example
367 * ```ts
368 * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
369 * ```
370 */
371 concat(...collections: ReadonlyCollection<Key, Value>[]): Collection<Key, Value>;
372 /**
373 * Checks if this collection shares identical items with another.
374 * This is different to checking for equality using equal-signs, because
375 * the collections may be different objects, but contain the same data.
376 *
377 * @param collection - Collection to compare with
378 * @returns Whether the collections have identical contents
379 */
380 equals(collection: ReadonlyCollection<Key, Value>): boolean;
381 /**
382 * The sort method sorts the items of a collection in place and returns it.
383 * The sort is not necessarily stable in Node 10 or older.
384 * The default sort order is according to string Unicode code points.
385 *
386 * @param compareFunction - Specifies a function that defines the sort order.
387 * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
388 * @example
389 * ```ts
390 * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
391 * ```
392 */
393 sort(compareFunction?: Comparator<Key, Value>): this;
394 /**
395 * The intersection method returns a new collection containing the items where the key is present in both collections.
396 *
397 * @param other - The other Collection to filter against
398 * @example
399 * ```ts
400 * const col1 = new Collection([['a', 1], ['b', 2]]);
401 * const col2 = new Collection([['a', 1], ['c', 3]]);
402 * const intersection = col1.intersection(col2);
403 * console.log(col1.intersection(col2));
404 * // => Collection { 'a' => 1 }
405 * ```
406 */
407 intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
408 /**
409 * Returns a new collection containing the items where the key is present in either of the collections.
410 *
411 * @remarks
412 *
413 * If the collections have any items with the same key, the value from the first collection will be used.
414 * @param other - The other Collection to filter against
415 * @example
416 * ```ts
417 * const col1 = new Collection([['a', 1], ['b', 2]]);
418 * const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
419 * const union = col1.union(col2);
420 * console.log(union);
421 * // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
422 * ```
423 */
424 union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
425 /**
426 * Returns a new collection containing the items where the key is present in this collection but not the other.
427 *
428 * @param other - The other Collection to filter against
429 * @example
430 * ```ts
431 * const col1 = new Collection([['a', 1], ['b', 2]]);
432 * const col2 = new Collection([['a', 1], ['c', 3]]);
433 * console.log(col1.difference(col2));
434 * // => Collection { 'b' => 2 }
435 * console.log(col2.difference(col1));
436 * // => Collection { 'c' => 3 }
437 * ```
438 */
439 difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
440 /**
441 * Returns a new collection containing only the items where the keys are present in either collection, but not both.
442 *
443 * @param other - The other Collection to filter against
444 * @example
445 * ```ts
446 * const col1 = new Collection([['a', 1], ['b', 2]]);
447 * const col2 = new Collection([['a', 1], ['c', 3]]);
448 * const symmetricDifference = col1.symmetricDifference(col2);
449 * console.log(col1.symmetricDifference(col2));
450 * // => Collection { 'b' => 2, 'c' => 3 }
451 * ```
452 */
453 symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
454 /**
455 * Merges two Collections together into a new Collection.
456 *
457 * @param other - The other Collection to merge with
458 * @param whenInSelf - Function getting the result if the entry only exists in this Collection
459 * @param whenInOther - Function getting the result if the entry only exists in the other Collection
460 * @param whenInBoth - Function getting the result if the entry exists in both Collections
461 * @example
462 * ```ts
463 * // Sums up the entries in two collections.
464 * coll.merge(
465 * other,
466 * x => ({ keep: true, value: x }),
467 * y => ({ keep: true, value: y }),
468 * (x, y) => ({ keep: true, value: x + y }),
469 * );
470 * ```
471 * @example
472 * ```ts
473 * // Intersects two collections in a left-biased manner.
474 * coll.merge(
475 * other,
476 * x => ({ keep: false }),
477 * y => ({ keep: false }),
478 * (x, _) => ({ keep: true, value: x }),
479 * );
480 * ```
481 */
482 merge<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
483 /**
484 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
485 * but returns a Collection instead of an Array.
486 */
487 toReversed(): Collection<Key, Value>;
488 /**
489 * The sorted method sorts the items of a collection and returns it.
490 * The sort is not necessarily stable in Node 10 or older.
491 * The default sort order is according to string Unicode code points.
492 *
493 * @param compareFunction - Specifies a function that defines the sort order.
494 * If omitted, the collection is sorted according to each character's Unicode code point value,
495 * according to the string conversion of each element.
496 * @example
497 * ```ts
498 * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
499 * ```
500 */
501 toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
502 toJSON(): [Key, Value][];
503 private static defaultSort;
504 /**
505 * Creates a Collection from a list of entries.
506 *
507 * @param entries - The list of entries
508 * @param combine - Function to combine an existing entry with a new one
509 * @example
510 * ```ts
511 * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
512 * // returns Collection { "a" => 3, "b" => 2 }
513 * ```
514 */
515 static combineEntries<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
516}
517/**
518 * @internal
519 */
520type Keep<Value> = {
521 keep: false;
522} | {
523 keep: true;
524 value: Value;
525};
526/**
527 * @internal
528 */
529type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => number;
530
531/**
532 * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection#readme | @discordjs/collection} version
533 * that you are currently using.
534 */
535declare const version: string;
536
537export { Collection, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };
538
\No newline at end of file