1 |
|
2 |
|
3 |
|
4 | interface 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 |
|
13 |
|
14 | type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | interface 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 | */
|
30 | declare class Collection<Key, Value> extends Map<Key, Value> {
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | ensure(key: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | hasAll(...keys: Key[]): boolean;
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | hasAny(...keys: Key[]): boolean;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | first(): Value | undefined;
|
63 | first(amount: number): Value[];
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | firstKey(): Key | undefined;
|
72 | firstKey(amount: number): Key[];
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | last(): Value | undefined;
|
81 | last(amount: number): Value[];
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | lastKey(): Key | undefined;
|
90 | lastKey(amount: number): Key[];
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | at(index: number): Value | undefined;
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | keyAt(index: number): Key | undefined;
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | random(): Value | undefined;
|
114 | random(amount: number): Value[];
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | randomKey(): Key | undefined;
|
122 | randomKey(amount: number): Key[];
|
123 | |
124 |
|
125 |
|
126 |
|
127 | reverse(): this;
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
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 | *
|
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 | *
|
435 | * console.log(col2.difference(col1));
|
436 | *
|
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 | *
|
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 | *
|
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 | *
|
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 | *
|
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 | */
|
520 | type Keep<Value> = {
|
521 | keep: false;
|
522 | } | {
|
523 | keep: true;
|
524 | value: Value;
|
525 | };
|
526 | /**
|
527 | * @internal
|
528 | */
|
529 | type 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 | */
|
535 | declare const version: string;
|
536 |
|
537 | export { Collection, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };
|
538 |
|
\ | No newline at end of file |