@discordjs/collection 2.0.0-dev.1699704219-5b0aa92c8 → 2.0.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/dist/index.d.mts +89 -89
- package/dist/index.d.ts +89 -89
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,31 +3,31 @@
|
|
|
3
3
|
*/
|
|
4
4
|
interface CollectionConstructor {
|
|
5
5
|
new (): Collection<unknown, unknown>;
|
|
6
|
-
new <
|
|
7
|
-
new <
|
|
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
8
|
readonly prototype: Collection<unknown, unknown>;
|
|
9
9
|
readonly [Symbol.species]: CollectionConstructor;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Represents an immutable version of a collection
|
|
13
13
|
*/
|
|
14
|
-
type ReadonlyCollection<
|
|
14
|
+
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
|
|
15
15
|
/**
|
|
16
16
|
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
|
|
17
17
|
*
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
|
-
interface Collection<
|
|
20
|
+
interface Collection<Key, Value> extends Map<Key, Value> {
|
|
21
21
|
constructor: CollectionConstructor;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
|
25
25
|
* an ID, for significantly improved performance and ease-of-use.
|
|
26
26
|
*
|
|
27
|
-
* @typeParam
|
|
28
|
-
* @typeParam
|
|
27
|
+
* @typeParam Key - The key type this collection holds
|
|
28
|
+
* @typeParam Value - The value type this collection holds
|
|
29
29
|
*/
|
|
30
|
-
declare class Collection<
|
|
30
|
+
declare class Collection<Key, Value> extends Map<Key, Value> {
|
|
31
31
|
/**
|
|
32
32
|
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
|
33
33
|
*
|
|
@@ -38,29 +38,29 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
38
38
|
* collection.ensure(guildId, () => defaultGuildConfig);
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
ensure(key:
|
|
41
|
+
ensure(key: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
|
|
42
42
|
/**
|
|
43
43
|
* Checks if all of the elements exist in the collection.
|
|
44
44
|
*
|
|
45
45
|
* @param keys - The keys of the elements to check for
|
|
46
46
|
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
|
47
47
|
*/
|
|
48
|
-
hasAll(...keys:
|
|
48
|
+
hasAll(...keys: Key[]): boolean;
|
|
49
49
|
/**
|
|
50
50
|
* Checks if any of the elements exist in the collection.
|
|
51
51
|
*
|
|
52
52
|
* @param keys - The keys of the elements to check for
|
|
53
53
|
* @returns `true` if any of the elements exist, `false` if none exist.
|
|
54
54
|
*/
|
|
55
|
-
hasAny(...keys:
|
|
55
|
+
hasAny(...keys: Key[]): boolean;
|
|
56
56
|
/**
|
|
57
57
|
* Obtains the first value(s) in this collection.
|
|
58
58
|
*
|
|
59
59
|
* @param amount - Amount of values to obtain from the beginning
|
|
60
60
|
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
|
|
61
61
|
*/
|
|
62
|
-
first():
|
|
63
|
-
first(amount: number):
|
|
62
|
+
first(): Value | undefined;
|
|
63
|
+
first(amount: number): Value[];
|
|
64
64
|
/**
|
|
65
65
|
* Obtains the first key(s) in this collection.
|
|
66
66
|
*
|
|
@@ -68,8 +68,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
68
68
|
* @returns A single key if no amount is provided or an array of keys, starting from the end if
|
|
69
69
|
* amount is negative
|
|
70
70
|
*/
|
|
71
|
-
firstKey():
|
|
72
|
-
firstKey(amount: number):
|
|
71
|
+
firstKey(): Key | undefined;
|
|
72
|
+
firstKey(amount: number): Key[];
|
|
73
73
|
/**
|
|
74
74
|
* Obtains the last value(s) in this collection.
|
|
75
75
|
*
|
|
@@ -77,8 +77,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
77
77
|
* @returns A single value if no amount is provided or an array of values, starting from the start if
|
|
78
78
|
* amount is negative
|
|
79
79
|
*/
|
|
80
|
-
last():
|
|
81
|
-
last(amount: number):
|
|
80
|
+
last(): Value | undefined;
|
|
81
|
+
last(amount: number): Value[];
|
|
82
82
|
/**
|
|
83
83
|
* Obtains the last key(s) in this collection.
|
|
84
84
|
*
|
|
@@ -86,8 +86,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
86
86
|
* @returns A single key if no amount is provided or an array of keys, starting from the start if
|
|
87
87
|
* amount is negative
|
|
88
88
|
*/
|
|
89
|
-
lastKey():
|
|
90
|
-
lastKey(amount: number):
|
|
89
|
+
lastKey(): Key | undefined;
|
|
90
|
+
lastKey(amount: number): Key[];
|
|
91
91
|
/**
|
|
92
92
|
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
|
93
93
|
* Returns the item at a given index, allowing for positive and negative integers.
|
|
@@ -95,7 +95,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
95
95
|
*
|
|
96
96
|
* @param index - The index of the element to obtain
|
|
97
97
|
*/
|
|
98
|
-
at(index: number):
|
|
98
|
+
at(index: number): Value | undefined;
|
|
99
99
|
/**
|
|
100
100
|
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
|
101
101
|
* Returns the key at a given index, allowing for positive and negative integers.
|
|
@@ -103,23 +103,23 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
103
103
|
*
|
|
104
104
|
* @param index - The index of the key to obtain
|
|
105
105
|
*/
|
|
106
|
-
keyAt(index: number):
|
|
106
|
+
keyAt(index: number): Key | undefined;
|
|
107
107
|
/**
|
|
108
108
|
* Obtains unique random value(s) from this collection.
|
|
109
109
|
*
|
|
110
110
|
* @param amount - Amount of values to obtain randomly
|
|
111
111
|
* @returns A single value if no amount is provided or an array of values
|
|
112
112
|
*/
|
|
113
|
-
random():
|
|
114
|
-
random(amount: number):
|
|
113
|
+
random(): Value | undefined;
|
|
114
|
+
random(amount: number): Value[];
|
|
115
115
|
/**
|
|
116
116
|
* Obtains unique random key(s) from this collection.
|
|
117
117
|
*
|
|
118
118
|
* @param amount - Amount of keys to obtain randomly
|
|
119
119
|
* @returns A single key if no amount is provided or an array
|
|
120
120
|
*/
|
|
121
|
-
randomKey():
|
|
122
|
-
randomKey(amount: number):
|
|
121
|
+
randomKey(): Key | undefined;
|
|
122
|
+
randomKey(amount: number): Key[];
|
|
123
123
|
/**
|
|
124
124
|
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
|
|
125
125
|
* but returns a Collection instead of an Array.
|
|
@@ -139,10 +139,10 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
139
139
|
* collection.find(user => user.username === 'Bob');
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
|
-
find<
|
|
143
|
-
find(fn: (value:
|
|
144
|
-
find<This,
|
|
145
|
-
find<This>(fn: (this: This, value:
|
|
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
146
|
/**
|
|
147
147
|
* Searches for the key of a single item where the given function returns a truthy value. This behaves like
|
|
148
148
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
|
|
@@ -155,10 +155,10 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
155
155
|
* collection.findKey(user => user.username === 'Bob');
|
|
156
156
|
* ```
|
|
157
157
|
*/
|
|
158
|
-
findKey<
|
|
159
|
-
findKey(fn: (value:
|
|
160
|
-
findKey<This,
|
|
161
|
-
findKey<This>(fn: (this: This, value:
|
|
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
162
|
/**
|
|
163
163
|
* Searches for a last item where the given function returns a truthy value. This behaves like
|
|
164
164
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast | Array.findLast()}.
|
|
@@ -166,10 +166,10 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
166
166
|
* @param fn - The function to test with (should return a boolean)
|
|
167
167
|
* @param thisArg - Value to use as `this` when executing the function
|
|
168
168
|
*/
|
|
169
|
-
findLast<
|
|
170
|
-
findLast(fn: (value:
|
|
171
|
-
findLast<This,
|
|
172
|
-
findLast<This>(fn: (this: This, value:
|
|
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
173
|
/**
|
|
174
174
|
* Searches for the key of a last item where the given function returns a truthy value. This behaves like
|
|
175
175
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | Array.findLastIndex()},
|
|
@@ -178,10 +178,10 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
178
178
|
* @param fn - The function to test with (should return a boolean)
|
|
179
179
|
* @param thisArg - Value to use as `this` when executing the function
|
|
180
180
|
*/
|
|
181
|
-
findLastKey<
|
|
182
|
-
findLastKey(fn: (value:
|
|
183
|
-
findLastKey<This,
|
|
184
|
-
findLastKey<This>(fn: (this: This, value:
|
|
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
185
|
/**
|
|
186
186
|
* Removes items that satisfy the provided filter function.
|
|
187
187
|
*
|
|
@@ -189,8 +189,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
189
189
|
* @param thisArg - Value to use as `this` when executing the function
|
|
190
190
|
* @returns The number of removed entries
|
|
191
191
|
*/
|
|
192
|
-
sweep(fn: (value:
|
|
193
|
-
sweep<
|
|
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
194
|
/**
|
|
195
195
|
* Identical to
|
|
196
196
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
|
|
@@ -203,12 +203,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
203
203
|
* collection.filter(user => user.username === 'Bob');
|
|
204
204
|
* ```
|
|
205
205
|
*/
|
|
206
|
-
filter<
|
|
207
|
-
filter<
|
|
208
|
-
filter(fn: (value:
|
|
209
|
-
filter<This,
|
|
210
|
-
filter<This,
|
|
211
|
-
filter<This>(fn: (this: This, value:
|
|
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
212
|
/**
|
|
213
213
|
* Partitions the collection into two collections where the first collection
|
|
214
214
|
* contains the items that passed and the second contains the items that failed.
|
|
@@ -220,12 +220,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
220
220
|
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
partition<
|
|
224
|
-
partition<
|
|
225
|
-
partition(fn: (value:
|
|
226
|
-
partition<This,
|
|
227
|
-
partition<This,
|
|
228
|
-
partition<This>(fn: (this: This, value:
|
|
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
229
|
/**
|
|
230
230
|
* Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
|
|
231
231
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
|
|
@@ -237,8 +237,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
237
237
|
* collection.flatMap(guild => guild.members.cache);
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
|
-
flatMap<
|
|
241
|
-
flatMap<
|
|
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
242
|
/**
|
|
243
243
|
* Maps each item to another value into an array. Identical in behavior to
|
|
244
244
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
@@ -250,8 +250,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
250
250
|
* collection.map(user => user.tag);
|
|
251
251
|
* ```
|
|
252
252
|
*/
|
|
253
|
-
map<
|
|
254
|
-
map<This,
|
|
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
255
|
/**
|
|
256
256
|
* Maps each item to another value into a collection. Identical in behavior to
|
|
257
257
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
|
@@ -263,8 +263,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
263
263
|
* collection.mapValues(user => user.tag);
|
|
264
264
|
* ```
|
|
265
265
|
*/
|
|
266
|
-
mapValues<
|
|
267
|
-
mapValues<This,
|
|
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
268
|
/**
|
|
269
269
|
* Checks if there exists an item that passes a test. Identical in behavior to
|
|
270
270
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
|
|
@@ -276,8 +276,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
276
276
|
* collection.some(user => user.discriminator === '0000');
|
|
277
277
|
* ```
|
|
278
278
|
*/
|
|
279
|
-
some(fn: (value:
|
|
280
|
-
some<
|
|
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
281
|
/**
|
|
282
282
|
* Checks if all items passes a test. Identical in behavior to
|
|
283
283
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
|
|
@@ -289,12 +289,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
289
289
|
* collection.every(user => !user.bot);
|
|
290
290
|
* ```
|
|
291
291
|
*/
|
|
292
|
-
every<
|
|
293
|
-
every<
|
|
294
|
-
every(fn: (value:
|
|
295
|
-
every<This,
|
|
296
|
-
every<This,
|
|
297
|
-
every<This>(fn: (this: This, value:
|
|
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
298
|
/**
|
|
299
299
|
* Applies a function to produce a single value. Identical in behavior to
|
|
300
300
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
|
|
@@ -307,7 +307,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
307
307
|
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
|
308
308
|
* ```
|
|
309
309
|
*/
|
|
310
|
-
reduce<
|
|
310
|
+
reduce<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
|
311
311
|
/**
|
|
312
312
|
* Applies a function to produce a single value. Identical in behavior to
|
|
313
313
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
|
@@ -315,7 +315,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
315
315
|
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
|
316
316
|
* @param initialValue - Starting value for the accumulator
|
|
317
317
|
*/
|
|
318
|
-
reduceRight<
|
|
318
|
+
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
|
319
319
|
/**
|
|
320
320
|
* Identical to
|
|
321
321
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
|
|
@@ -331,8 +331,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
331
331
|
* .each(user => console.log(user.username));
|
|
332
332
|
* ```
|
|
333
333
|
*/
|
|
334
|
-
each(fn: (value:
|
|
335
|
-
each<
|
|
334
|
+
each(fn: (value: Value, key: Key, collection: this) => void): this;
|
|
335
|
+
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): this;
|
|
336
336
|
/**
|
|
337
337
|
* Runs a function on the collection and returns the collection.
|
|
338
338
|
*
|
|
@@ -347,7 +347,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
347
347
|
* ```
|
|
348
348
|
*/
|
|
349
349
|
tap(fn: (collection: this) => void): this;
|
|
350
|
-
tap<
|
|
350
|
+
tap<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
|
|
351
351
|
/**
|
|
352
352
|
* Creates an identical shallow copy of this collection.
|
|
353
353
|
*
|
|
@@ -356,7 +356,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
356
356
|
* const newColl = someColl.clone();
|
|
357
357
|
* ```
|
|
358
358
|
*/
|
|
359
|
-
clone(): Collection<
|
|
359
|
+
clone(): Collection<Key, Value>;
|
|
360
360
|
/**
|
|
361
361
|
* Combines this collection with others into a new collection. None of the source collections are modified.
|
|
362
362
|
*
|
|
@@ -366,7 +366,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
366
366
|
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
|
367
367
|
* ```
|
|
368
368
|
*/
|
|
369
|
-
concat(...collections: ReadonlyCollection<
|
|
369
|
+
concat(...collections: ReadonlyCollection<Key, Value>[]): Collection<Key, Value>;
|
|
370
370
|
/**
|
|
371
371
|
* Checks if this collection shares identical items with another.
|
|
372
372
|
* This is different to checking for equality using equal-signs, because
|
|
@@ -375,7 +375,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
375
375
|
* @param collection - Collection to compare with
|
|
376
376
|
* @returns Whether the collections have identical contents
|
|
377
377
|
*/
|
|
378
|
-
equals(collection: ReadonlyCollection<
|
|
378
|
+
equals(collection: ReadonlyCollection<Key, Value>): boolean;
|
|
379
379
|
/**
|
|
380
380
|
* The sort method sorts the items of a collection in place and returns it.
|
|
381
381
|
* The sort is not necessarily stable in Node 10 or older.
|
|
@@ -388,7 +388,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
388
388
|
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
389
389
|
* ```
|
|
390
390
|
*/
|
|
391
|
-
sort(compareFunction?: Comparator<
|
|
391
|
+
sort(compareFunction?: Comparator<Key, Value>): this;
|
|
392
392
|
/**
|
|
393
393
|
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
|
394
394
|
*
|
|
@@ -402,7 +402,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
402
402
|
* // => Collection { 'a' => 1 }
|
|
403
403
|
* ```
|
|
404
404
|
*/
|
|
405
|
-
intersection
|
|
405
|
+
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
|
406
406
|
/**
|
|
407
407
|
* Returns a new collection containing the items where the key is present in either of the collections.
|
|
408
408
|
*
|
|
@@ -419,7 +419,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
419
419
|
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
|
420
420
|
* ```
|
|
421
421
|
*/
|
|
422
|
-
union<
|
|
422
|
+
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
|
423
423
|
/**
|
|
424
424
|
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
|
425
425
|
*
|
|
@@ -434,7 +434,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
434
434
|
* // => Collection { 'c' => 3 }
|
|
435
435
|
* ```
|
|
436
436
|
*/
|
|
437
|
-
difference
|
|
437
|
+
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
|
438
438
|
/**
|
|
439
439
|
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
|
440
440
|
*
|
|
@@ -448,7 +448,7 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
448
448
|
* // => Collection { 'b' => 2, 'c' => 3 }
|
|
449
449
|
* ```
|
|
450
450
|
*/
|
|
451
|
-
symmetricDifference<
|
|
451
|
+
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
|
452
452
|
/**
|
|
453
453
|
* Merges two Collections together into a new Collection.
|
|
454
454
|
*
|
|
@@ -477,12 +477,12 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
477
477
|
* );
|
|
478
478
|
* ```
|
|
479
479
|
*/
|
|
480
|
-
merge<
|
|
480
|
+
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>;
|
|
481
481
|
/**
|
|
482
482
|
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
|
483
483
|
* but returns a Collection instead of an Array.
|
|
484
484
|
*/
|
|
485
|
-
toReversed(): Collection<
|
|
485
|
+
toReversed(): Collection<Key, Value>;
|
|
486
486
|
/**
|
|
487
487
|
* The sorted method sorts the items of a collection and returns it.
|
|
488
488
|
* The sort is not necessarily stable in Node 10 or older.
|
|
@@ -496,8 +496,8 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
496
496
|
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
|
497
497
|
* ```
|
|
498
498
|
*/
|
|
499
|
-
toSorted(compareFunction?: Comparator<
|
|
500
|
-
toJSON(): [
|
|
499
|
+
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
|
|
500
|
+
toJSON(): [Key, Value][];
|
|
501
501
|
private static defaultSort;
|
|
502
502
|
/**
|
|
503
503
|
* Creates a Collection from a list of entries.
|
|
@@ -510,21 +510,21 @@ declare class Collection<K, V> extends Map<K, V> {
|
|
|
510
510
|
* // returns Collection { "a" => 3, "b" => 2 }
|
|
511
511
|
* ```
|
|
512
512
|
*/
|
|
513
|
-
static combineEntries<
|
|
513
|
+
static combineEntries<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
|
|
514
514
|
}
|
|
515
515
|
/**
|
|
516
516
|
* @internal
|
|
517
517
|
*/
|
|
518
|
-
type Keep<
|
|
518
|
+
type Keep<Value> = {
|
|
519
519
|
keep: false;
|
|
520
520
|
} | {
|
|
521
521
|
keep: true;
|
|
522
|
-
value:
|
|
522
|
+
value: Value;
|
|
523
523
|
};
|
|
524
524
|
/**
|
|
525
525
|
* @internal
|
|
526
526
|
*/
|
|
527
|
-
type Comparator<
|
|
527
|
+
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => number;
|
|
528
528
|
|
|
529
529
|
/**
|
|
530
530
|
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version
|