@discordjs/collection 2.1.1-dev.1721153481-918f43411 → 2.1.1-dev.1721607094-b2970bb2d
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.js +69 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -137
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -42,10 +42,8 @@ var Collection = class _Collection extends Map {
|
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
ensure(key, defaultValueGenerator) {
|
|
45
|
-
if (this.has(key))
|
|
46
|
-
|
|
47
|
-
if (typeof defaultValueGenerator !== "function")
|
|
48
|
-
throw new TypeError(`${defaultValueGenerator} is not a function`);
|
|
45
|
+
if (this.has(key)) return this.get(key);
|
|
46
|
+
if (typeof defaultValueGenerator !== "function") throw new TypeError(`${defaultValueGenerator} is not a function`);
|
|
49
47
|
const defaultValue = defaultValueGenerator(key, this);
|
|
50
48
|
this.set(key, defaultValue);
|
|
51
49
|
return defaultValue;
|
|
@@ -69,41 +67,31 @@ var Collection = class _Collection extends Map {
|
|
|
69
67
|
return keys.some((key) => super.has(key));
|
|
70
68
|
}
|
|
71
69
|
first(amount) {
|
|
72
|
-
if (amount === void 0)
|
|
73
|
-
|
|
74
|
-
if (amount < 0)
|
|
75
|
-
return this.last(amount * -1);
|
|
70
|
+
if (amount === void 0) return this.values().next().value;
|
|
71
|
+
if (amount < 0) return this.last(amount * -1);
|
|
76
72
|
amount = Math.min(this.size, amount);
|
|
77
73
|
const iter = this.values();
|
|
78
74
|
return Array.from({ length: amount }, () => iter.next().value);
|
|
79
75
|
}
|
|
80
76
|
firstKey(amount) {
|
|
81
|
-
if (amount === void 0)
|
|
82
|
-
|
|
83
|
-
if (amount < 0)
|
|
84
|
-
return this.lastKey(amount * -1);
|
|
77
|
+
if (amount === void 0) return this.keys().next().value;
|
|
78
|
+
if (amount < 0) return this.lastKey(amount * -1);
|
|
85
79
|
amount = Math.min(this.size, amount);
|
|
86
80
|
const iter = this.keys();
|
|
87
81
|
return Array.from({ length: amount }, () => iter.next().value);
|
|
88
82
|
}
|
|
89
83
|
last(amount) {
|
|
90
84
|
const arr = [...this.values()];
|
|
91
|
-
if (amount === void 0)
|
|
92
|
-
|
|
93
|
-
if (amount
|
|
94
|
-
return this.first(amount * -1);
|
|
95
|
-
if (!amount)
|
|
96
|
-
return [];
|
|
85
|
+
if (amount === void 0) return arr[arr.length - 1];
|
|
86
|
+
if (amount < 0) return this.first(amount * -1);
|
|
87
|
+
if (!amount) return [];
|
|
97
88
|
return arr.slice(-amount);
|
|
98
89
|
}
|
|
99
90
|
lastKey(amount) {
|
|
100
91
|
const arr = [...this.keys()];
|
|
101
|
-
if (amount === void 0)
|
|
102
|
-
|
|
103
|
-
if (amount
|
|
104
|
-
return this.firstKey(amount * -1);
|
|
105
|
-
if (!amount)
|
|
106
|
-
return [];
|
|
92
|
+
if (amount === void 0) return arr[arr.length - 1];
|
|
93
|
+
if (amount < 0) return this.firstKey(amount * -1);
|
|
94
|
+
if (!amount) return [];
|
|
107
95
|
return arr.slice(-amount);
|
|
108
96
|
}
|
|
109
97
|
/**
|
|
@@ -132,10 +120,8 @@ var Collection = class _Collection extends Map {
|
|
|
132
120
|
}
|
|
133
121
|
random(amount) {
|
|
134
122
|
const arr = [...this.values()];
|
|
135
|
-
if (amount === void 0)
|
|
136
|
-
|
|
137
|
-
if (!arr.length || !amount)
|
|
138
|
-
return [];
|
|
123
|
+
if (amount === void 0) return arr[Math.floor(Math.random() * arr.length)];
|
|
124
|
+
if (!arr.length || !amount) return [];
|
|
139
125
|
return Array.from(
|
|
140
126
|
{ length: Math.min(amount, arr.length) },
|
|
141
127
|
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
|
@@ -143,10 +129,8 @@ var Collection = class _Collection extends Map {
|
|
|
143
129
|
}
|
|
144
130
|
randomKey(amount) {
|
|
145
131
|
const arr = [...this.keys()];
|
|
146
|
-
if (amount === void 0)
|
|
147
|
-
|
|
148
|
-
if (!arr.length || !amount)
|
|
149
|
-
return [];
|
|
132
|
+
if (amount === void 0) return arr[Math.floor(Math.random() * arr.length)];
|
|
133
|
+
if (!arr.length || !amount) return [];
|
|
150
134
|
return Array.from(
|
|
151
135
|
{ length: Math.min(amount, arr.length) },
|
|
152
136
|
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
|
@@ -159,89 +143,68 @@ var Collection = class _Collection extends Map {
|
|
|
159
143
|
reverse() {
|
|
160
144
|
const entries = [...this.entries()].reverse();
|
|
161
145
|
this.clear();
|
|
162
|
-
for (const [key, value] of entries)
|
|
163
|
-
this.set(key, value);
|
|
146
|
+
for (const [key, value] of entries) this.set(key, value);
|
|
164
147
|
return this;
|
|
165
148
|
}
|
|
166
149
|
find(fn, thisArg) {
|
|
167
|
-
if (typeof fn !== "function")
|
|
168
|
-
|
|
169
|
-
if (thisArg !== void 0)
|
|
170
|
-
fn = fn.bind(thisArg);
|
|
150
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
151
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
171
152
|
for (const [key, val] of this) {
|
|
172
|
-
if (fn(val, key, this))
|
|
173
|
-
return val;
|
|
153
|
+
if (fn(val, key, this)) return val;
|
|
174
154
|
}
|
|
175
155
|
return void 0;
|
|
176
156
|
}
|
|
177
157
|
findKey(fn, thisArg) {
|
|
178
|
-
if (typeof fn !== "function")
|
|
179
|
-
|
|
180
|
-
if (thisArg !== void 0)
|
|
181
|
-
fn = fn.bind(thisArg);
|
|
158
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
159
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
182
160
|
for (const [key, val] of this) {
|
|
183
|
-
if (fn(val, key, this))
|
|
184
|
-
return key;
|
|
161
|
+
if (fn(val, key, this)) return key;
|
|
185
162
|
}
|
|
186
163
|
return void 0;
|
|
187
164
|
}
|
|
188
165
|
findLast(fn, thisArg) {
|
|
189
|
-
if (typeof fn !== "function")
|
|
190
|
-
|
|
191
|
-
if (thisArg !== void 0)
|
|
192
|
-
fn = fn.bind(thisArg);
|
|
166
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
167
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
193
168
|
const entries = [...this.entries()];
|
|
194
169
|
for (let index = entries.length - 1; index >= 0; index--) {
|
|
195
170
|
const val = entries[index][1];
|
|
196
171
|
const key = entries[index][0];
|
|
197
|
-
if (fn(val, key, this))
|
|
198
|
-
return val;
|
|
172
|
+
if (fn(val, key, this)) return val;
|
|
199
173
|
}
|
|
200
174
|
return void 0;
|
|
201
175
|
}
|
|
202
176
|
findLastKey(fn, thisArg) {
|
|
203
|
-
if (typeof fn !== "function")
|
|
204
|
-
|
|
205
|
-
if (thisArg !== void 0)
|
|
206
|
-
fn = fn.bind(thisArg);
|
|
177
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
178
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
207
179
|
const entries = [...this.entries()];
|
|
208
180
|
for (let index = entries.length - 1; index >= 0; index--) {
|
|
209
181
|
const key = entries[index][0];
|
|
210
182
|
const val = entries[index][1];
|
|
211
|
-
if (fn(val, key, this))
|
|
212
|
-
return key;
|
|
183
|
+
if (fn(val, key, this)) return key;
|
|
213
184
|
}
|
|
214
185
|
return void 0;
|
|
215
186
|
}
|
|
216
187
|
sweep(fn, thisArg) {
|
|
217
|
-
if (typeof fn !== "function")
|
|
218
|
-
|
|
219
|
-
if (thisArg !== void 0)
|
|
220
|
-
fn = fn.bind(thisArg);
|
|
188
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
189
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
221
190
|
const previousSize = this.size;
|
|
222
191
|
for (const [key, val] of this) {
|
|
223
|
-
if (fn(val, key, this))
|
|
224
|
-
this.delete(key);
|
|
192
|
+
if (fn(val, key, this)) this.delete(key);
|
|
225
193
|
}
|
|
226
194
|
return previousSize - this.size;
|
|
227
195
|
}
|
|
228
196
|
filter(fn, thisArg) {
|
|
229
|
-
if (typeof fn !== "function")
|
|
230
|
-
|
|
231
|
-
if (thisArg !== void 0)
|
|
232
|
-
fn = fn.bind(thisArg);
|
|
197
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
198
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
233
199
|
const results = new this.constructor[Symbol.species]();
|
|
234
200
|
for (const [key, val] of this) {
|
|
235
|
-
if (fn(val, key, this))
|
|
236
|
-
results.set(key, val);
|
|
201
|
+
if (fn(val, key, this)) results.set(key, val);
|
|
237
202
|
}
|
|
238
203
|
return results;
|
|
239
204
|
}
|
|
240
205
|
partition(fn, thisArg) {
|
|
241
|
-
if (typeof fn !== "function")
|
|
242
|
-
|
|
243
|
-
if (thisArg !== void 0)
|
|
244
|
-
fn = fn.bind(thisArg);
|
|
206
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
207
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
245
208
|
const results = [
|
|
246
209
|
new this.constructor[Symbol.species](),
|
|
247
210
|
new this.constructor[Symbol.species]()
|
|
@@ -260,10 +223,8 @@ var Collection = class _Collection extends Map {
|
|
|
260
223
|
return new this.constructor[Symbol.species]().concat(...collections);
|
|
261
224
|
}
|
|
262
225
|
map(fn, thisArg) {
|
|
263
|
-
if (typeof fn !== "function")
|
|
264
|
-
|
|
265
|
-
if (thisArg !== void 0)
|
|
266
|
-
fn = fn.bind(thisArg);
|
|
226
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
227
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
267
228
|
const iter = this.entries();
|
|
268
229
|
return Array.from({ length: this.size }, () => {
|
|
269
230
|
const [key, value] = iter.next().value;
|
|
@@ -271,34 +232,25 @@ var Collection = class _Collection extends Map {
|
|
|
271
232
|
});
|
|
272
233
|
}
|
|
273
234
|
mapValues(fn, thisArg) {
|
|
274
|
-
if (typeof fn !== "function")
|
|
275
|
-
|
|
276
|
-
if (thisArg !== void 0)
|
|
277
|
-
fn = fn.bind(thisArg);
|
|
235
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
236
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
278
237
|
const coll = new this.constructor[Symbol.species]();
|
|
279
|
-
for (const [key, val] of this)
|
|
280
|
-
coll.set(key, fn(val, key, this));
|
|
238
|
+
for (const [key, val] of this) coll.set(key, fn(val, key, this));
|
|
281
239
|
return coll;
|
|
282
240
|
}
|
|
283
241
|
some(fn, thisArg) {
|
|
284
|
-
if (typeof fn !== "function")
|
|
285
|
-
|
|
286
|
-
if (thisArg !== void 0)
|
|
287
|
-
fn = fn.bind(thisArg);
|
|
242
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
243
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
288
244
|
for (const [key, val] of this) {
|
|
289
|
-
if (fn(val, key, this))
|
|
290
|
-
return true;
|
|
245
|
+
if (fn(val, key, this)) return true;
|
|
291
246
|
}
|
|
292
247
|
return false;
|
|
293
248
|
}
|
|
294
249
|
every(fn, thisArg) {
|
|
295
|
-
if (typeof fn !== "function")
|
|
296
|
-
|
|
297
|
-
if (thisArg !== void 0)
|
|
298
|
-
fn = fn.bind(thisArg);
|
|
250
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
251
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
299
252
|
for (const [key, val] of this) {
|
|
300
|
-
if (!fn(val, key, this))
|
|
301
|
-
return false;
|
|
253
|
+
if (!fn(val, key, this)) return false;
|
|
302
254
|
}
|
|
303
255
|
return true;
|
|
304
256
|
}
|
|
@@ -315,13 +267,11 @@ var Collection = class _Collection extends Map {
|
|
|
315
267
|
* ```
|
|
316
268
|
*/
|
|
317
269
|
reduce(fn, initialValue) {
|
|
318
|
-
if (typeof fn !== "function")
|
|
319
|
-
throw new TypeError(`${fn} is not a function`);
|
|
270
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
320
271
|
let accumulator;
|
|
321
272
|
const iterator = this.entries();
|
|
322
273
|
if (initialValue === void 0) {
|
|
323
|
-
if (this.size === 0)
|
|
324
|
-
throw new TypeError("Reduce of empty collection with no initial value");
|
|
274
|
+
if (this.size === 0) throw new TypeError("Reduce of empty collection with no initial value");
|
|
325
275
|
accumulator = iterator.next().value[1];
|
|
326
276
|
} else {
|
|
327
277
|
accumulator = initialValue;
|
|
@@ -339,14 +289,12 @@ var Collection = class _Collection extends Map {
|
|
|
339
289
|
* @param initialValue - Starting value for the accumulator
|
|
340
290
|
*/
|
|
341
291
|
reduceRight(fn, initialValue) {
|
|
342
|
-
if (typeof fn !== "function")
|
|
343
|
-
throw new TypeError(`${fn} is not a function`);
|
|
292
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
344
293
|
const entries = [...this.entries()];
|
|
345
294
|
let accumulator;
|
|
346
295
|
let index;
|
|
347
296
|
if (initialValue === void 0) {
|
|
348
|
-
if (entries.length === 0)
|
|
349
|
-
throw new TypeError("Reduce of empty collection with no initial value");
|
|
297
|
+
if (entries.length === 0) throw new TypeError("Reduce of empty collection with no initial value");
|
|
350
298
|
accumulator = entries[entries.length - 1][1];
|
|
351
299
|
index = entries.length - 1;
|
|
352
300
|
} else {
|
|
@@ -361,20 +309,16 @@ var Collection = class _Collection extends Map {
|
|
|
361
309
|
return accumulator;
|
|
362
310
|
}
|
|
363
311
|
each(fn, thisArg) {
|
|
364
|
-
if (typeof fn !== "function")
|
|
365
|
-
|
|
366
|
-
if (thisArg !== void 0)
|
|
367
|
-
fn = fn.bind(thisArg);
|
|
312
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
313
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
368
314
|
for (const [key, value] of this) {
|
|
369
315
|
fn(value, key, this);
|
|
370
316
|
}
|
|
371
317
|
return this;
|
|
372
318
|
}
|
|
373
319
|
tap(fn, thisArg) {
|
|
374
|
-
if (typeof fn !== "function")
|
|
375
|
-
|
|
376
|
-
if (thisArg !== void 0)
|
|
377
|
-
fn = fn.bind(thisArg);
|
|
320
|
+
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`);
|
|
321
|
+
if (thisArg !== void 0) fn = fn.bind(thisArg);
|
|
378
322
|
fn(this);
|
|
379
323
|
return this;
|
|
380
324
|
}
|
|
@@ -401,8 +345,7 @@ var Collection = class _Collection extends Map {
|
|
|
401
345
|
concat(...collections) {
|
|
402
346
|
const newColl = this.clone();
|
|
403
347
|
for (const coll of collections) {
|
|
404
|
-
for (const [key, val] of coll)
|
|
405
|
-
newColl.set(key, val);
|
|
348
|
+
for (const [key, val] of coll) newColl.set(key, val);
|
|
406
349
|
}
|
|
407
350
|
return newColl;
|
|
408
351
|
}
|
|
@@ -415,12 +358,9 @@ var Collection = class _Collection extends Map {
|
|
|
415
358
|
* @returns Whether the collections have identical contents
|
|
416
359
|
*/
|
|
417
360
|
equals(collection) {
|
|
418
|
-
if (!collection)
|
|
419
|
-
|
|
420
|
-
if (this
|
|
421
|
-
return true;
|
|
422
|
-
if (this.size !== collection.size)
|
|
423
|
-
return false;
|
|
361
|
+
if (!collection) return false;
|
|
362
|
+
if (this === collection) return true;
|
|
363
|
+
if (this.size !== collection.size) return false;
|
|
424
364
|
for (const [key, value] of this) {
|
|
425
365
|
if (!collection.has(key) || value !== collection.get(key)) {
|
|
426
366
|
return false;
|
|
@@ -465,8 +405,7 @@ var Collection = class _Collection extends Map {
|
|
|
465
405
|
intersection(other) {
|
|
466
406
|
const coll = new this.constructor[Symbol.species]();
|
|
467
407
|
for (const [key, value] of this) {
|
|
468
|
-
if (other.has(key))
|
|
469
|
-
coll.set(key, value);
|
|
408
|
+
if (other.has(key)) coll.set(key, value);
|
|
470
409
|
}
|
|
471
410
|
return coll;
|
|
472
411
|
}
|
|
@@ -489,8 +428,7 @@ var Collection = class _Collection extends Map {
|
|
|
489
428
|
union(other) {
|
|
490
429
|
const coll = new this.constructor[Symbol.species](this);
|
|
491
430
|
for (const [key, value] of other) {
|
|
492
|
-
if (!coll.has(key))
|
|
493
|
-
coll.set(key, value);
|
|
431
|
+
if (!coll.has(key)) coll.set(key, value);
|
|
494
432
|
}
|
|
495
433
|
return coll;
|
|
496
434
|
}
|
|
@@ -511,8 +449,7 @@ var Collection = class _Collection extends Map {
|
|
|
511
449
|
difference(other) {
|
|
512
450
|
const coll = new this.constructor[Symbol.species]();
|
|
513
451
|
for (const [key, value] of this) {
|
|
514
|
-
if (!other.has(key))
|
|
515
|
-
coll.set(key, value);
|
|
452
|
+
if (!other.has(key)) coll.set(key, value);
|
|
516
453
|
}
|
|
517
454
|
return coll;
|
|
518
455
|
}
|
|
@@ -532,12 +469,10 @@ var Collection = class _Collection extends Map {
|
|
|
532
469
|
symmetricDifference(other) {
|
|
533
470
|
const coll = new this.constructor[Symbol.species]();
|
|
534
471
|
for (const [key, value] of this) {
|
|
535
|
-
if (!other.has(key))
|
|
536
|
-
coll.set(key, value);
|
|
472
|
+
if (!other.has(key)) coll.set(key, value);
|
|
537
473
|
}
|
|
538
474
|
for (const [key, value] of other) {
|
|
539
|
-
if (!this.has(key))
|
|
540
|
-
coll.set(key, value);
|
|
475
|
+
if (!this.has(key)) coll.set(key, value);
|
|
541
476
|
}
|
|
542
477
|
return coll;
|
|
543
478
|
}
|
|
@@ -577,16 +512,13 @@ var Collection = class _Collection extends Map {
|
|
|
577
512
|
const hasInOther = other.has(key);
|
|
578
513
|
if (hasInSelf && hasInOther) {
|
|
579
514
|
const result = whenInBoth(this.get(key), other.get(key), key);
|
|
580
|
-
if (result.keep)
|
|
581
|
-
coll.set(key, result.value);
|
|
515
|
+
if (result.keep) coll.set(key, result.value);
|
|
582
516
|
} else if (hasInSelf) {
|
|
583
517
|
const result = whenInSelf(this.get(key), key);
|
|
584
|
-
if (result.keep)
|
|
585
|
-
coll.set(key, result.value);
|
|
518
|
+
if (result.keep) coll.set(key, result.value);
|
|
586
519
|
} else if (hasInOther) {
|
|
587
520
|
const result = whenInOther(other.get(key), key);
|
|
588
|
-
if (result.keep)
|
|
589
|
-
coll.set(key, result.value);
|
|
521
|
+
if (result.keep) coll.set(key, result.value);
|
|
590
522
|
}
|
|
591
523
|
}
|
|
592
524
|
return coll;
|
|
@@ -645,7 +577,7 @@ var Collection = class _Collection extends Map {
|
|
|
645
577
|
};
|
|
646
578
|
|
|
647
579
|
// src/index.ts
|
|
648
|
-
var version = "2.1.1-dev.
|
|
580
|
+
var version = "2.1.1-dev.1721607094-b2970bb2d";
|
|
649
581
|
// Annotate the CommonJS export names for ESM import in node:
|
|
650
582
|
0 && (module.exports = {
|
|
651
583
|
Collection,
|