beniocord.js 2.0.8 → 2.0.9

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/helpers/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  function formatUrl(url) {
2
2
  const base = 'https://api.beniocord.site';
3
- if (!url) return undefined;
3
+ if (!url) return null;
4
4
  if (url.startsWith(base) || url.startsWith('http')) return url;
5
5
  return base + (url.startsWith('/') ? url : '/' + url);
6
6
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "dependencies": {
3
+ "@discordjs/collection": "^2.1.1",
3
4
  "axios": "^1.12.2",
4
5
  "socket.io-client": "^4.8.1"
5
6
  },
6
7
  "name": "beniocord.js",
7
- "version": "2.0.8",
8
+ "version": "2.0.9",
8
9
  "description": "Uma biblioteca leve e intuitiva para integração com APIs de bots em plataformas de mensagens, como Discord. Facilita o envio de mensagens, gerenciamento de canais e interação com usuários, proporcionando uma experiência de desenvolvimento ágil e eficiente.",
9
10
  "main": "Client.js",
10
- "devDependencies": {},
11
11
  "scripts": {
12
12
  "test": "node bot.js"
13
13
  },
@@ -1,6 +1,6 @@
1
1
  const { formatUrl } = require('../helpers');
2
2
  const MessageCollector = require('./MessageCollector');
3
- const Collection = require('../collection').Collection;
3
+ const Collection = require('@discordjs/collection').Collection;
4
4
 
5
5
  let client;
6
6
  class Channel {
@@ -8,16 +8,16 @@ class Channel {
8
8
  client = clientInstance;
9
9
 
10
10
  this.id = data.id;
11
- this.ownerId = data.created_by;
12
11
  this.name = data.name;
13
12
  this.description = data.description;
14
13
  this.type = data.type || "text";
14
+ this.iconUrl = formatUrl(data.icon_url) || null;
15
+ this.ownerId = data.created_by;
15
16
  this.isPrivate = data.is_private;
16
17
  this.isLocked = data.is_locked;
17
- this.iconUrl = formatUrl(data.icon_url) || null;
18
+ this.memberCount = Number(data.member_count);
18
19
  this.createdAt = data.created_at;
19
20
  this.updatedAt = data.updated_at;
20
- this.memberCount = data.member_count;
21
21
 
22
22
  this.members = new Collection();
23
23
  this.members.fetch = async () => {
@@ -11,12 +11,11 @@ class Message {
11
11
  this.fileUrl = formatUrl(data.file_url);
12
12
  this.fileName = data.file_name;
13
13
  this.fileSize = data.file_size;
14
+ this.attachments = [];
14
15
  this.replyTo = data.reply_to;
16
+ this.stickerId = data.sticker_id;
15
17
  this.editedAt = data.edited_at;
16
18
  this.createdAt = data.created_at;
17
- this.stickerId = data.sticker_id;
18
-
19
- this.attachments = [];
20
19
 
21
20
  if (data.file_url) {
22
21
  this.attachments.push({
@@ -8,9 +8,9 @@ class User {
8
8
  this.avatarUrl = formatUrl(data.avatar_url);
9
9
  this.status = data.status || "offline";
10
10
  this.emblems = data.emblems || [];
11
+ this.isBot = data.is_bot;
11
12
  this.lastSeen = data.last_seen;
12
13
  this.createdAt = data.created_at;
13
- this.isBot = data.is_bot;
14
14
  // this.email = data.email;
15
15
  // this.updatedAt = data.updated_at;
16
16
  }
@@ -1,457 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- interface CollectionConstructor {
5
- new (): Collection<unknown, unknown>;
6
- new <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>;
7
- new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;
8
- readonly prototype: Collection<unknown, unknown>;
9
- readonly [Symbol.species]: CollectionConstructor;
10
- }
11
- /**
12
- * Represents an immutable version of a collection
13
- */
14
- type ReadonlyCollection<K, V> = Omit<Collection<K, V>, 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<K, V>;
15
- /**
16
- * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
17
- *
18
- * @internal
19
- */
20
- interface Collection<K, V> extends Map<K, V> {
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 K - The key type this collection holds
28
- * @typeParam V - The value type this collection holds
29
- */
30
- declare class Collection<K, V> extends Map<K, V> {
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: K, defaultValueGenerator: (key: K, collection: this) => V): V;
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: K[]): 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: K[]): 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(): V | undefined;
63
- first(amount: number): V[];
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(): K | undefined;
72
- firstKey(amount: number): K[];
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(): V | undefined;
81
- last(amount: number): V[];
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(): K | undefined;
90
- lastKey(amount: number): K[];
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): V | 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): K | 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(): V | undefined;
114
- random(amount: number): V[];
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(): K | undefined;
122
- randomKey(amount: number): K[];
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 boolean)
136
- * @param thisArg - Value to use as `this` when executing function
137
- * @example
138
- * ```ts
139
- * collection.find(user => user.username === 'Bob');
140
- * ```
141
- */
142
- find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
143
- find(fn: (value: V, key: K, collection: this) => unknown): V | undefined;
144
- find<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): V2 | undefined;
145
- find<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | 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 boolean)
152
- * @param thisArg - Value to use as `this` when executing function
153
- * @example
154
- * ```ts
155
- * collection.findKey(user => user.username === 'Bob');
156
- * ```
157
- */
158
- findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
159
- findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;
160
- findKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined;
161
- findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;
162
- /**
163
- * Removes items that satisfy the provided filter function.
164
- *
165
- * @param fn - Function used to test (should return a boolean)
166
- * @param thisArg - Value to use as `this` when executing function
167
- * @returns The number of removed entries
168
- */
169
- sweep(fn: (value: V, key: K, collection: this) => unknown): number;
170
- sweep<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): number;
171
- /**
172
- * Identical to
173
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
174
- * but returns a Collection instead of an Array.
175
- *
176
- * @param fn - The function to test with (should return boolean)
177
- * @param thisArg - Value to use as `this` when executing function
178
- * @example
179
- * ```ts
180
- * collection.filter(user => user.username === 'Bob');
181
- * ```
182
- */
183
- filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;
184
- filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;
185
- filter(fn: (value: V, key: K, collection: this) => unknown): Collection<K, V>;
186
- filter<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): Collection<K2, V>;
187
- filter<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): Collection<K, V2>;
188
- filter<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): Collection<K, V>;
189
- /**
190
- * Partitions the collection into two collections where the first collection
191
- * contains the items that passed and the second contains the items that failed.
192
- *
193
- * @param fn - Function used to test (should return a boolean)
194
- * @param thisArg - Value to use as `this` when executing function
195
- * @example
196
- * ```ts
197
- * const [big, small] = collection.partition(guild => guild.memberCount > 250);
198
- * ```
199
- */
200
- partition<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];
201
- partition<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];
202
- partition(fn: (value: V, key: K, collection: this) => unknown): [Collection<K, V>, Collection<K, V>];
203
- partition<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];
204
- partition<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];
205
- partition<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): [Collection<K, V>, Collection<K, V>];
206
- /**
207
- * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
208
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
209
- *
210
- * @param fn - Function that produces a new Collection
211
- * @param thisArg - Value to use as `this` when executing function
212
- * @example
213
- * ```ts
214
- * collection.flatMap(guild => guild.members.cache);
215
- * ```
216
- */
217
- flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
218
- flatMap<T, This>(fn: (this: This, value: V, key: K, collection: this) => Collection<K, T>, thisArg: This): Collection<K, T>;
219
- /**
220
- * Maps each item to another value into an array. Identical in behavior to
221
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
222
- *
223
- * @param fn - Function that produces an element of the new array, taking three arguments
224
- * @param thisArg - Value to use as `this` when executing function
225
- * @example
226
- * ```ts
227
- * collection.map(user => user.tag);
228
- * ```
229
- */
230
- map<T>(fn: (value: V, key: K, collection: this) => T): T[];
231
- map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
232
- /**
233
- * Maps each item to another value into a collection. Identical in behavior to
234
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
235
- *
236
- * @param fn - Function that produces an element of the new collection, taking three arguments
237
- * @param thisArg - Value to use as `this` when executing function
238
- * @example
239
- * ```ts
240
- * collection.mapValues(user => user.tag);
241
- * ```
242
- */
243
- mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
244
- mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
245
- /**
246
- * Checks if there exists an item that passes a test. Identical in behavior to
247
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
248
- *
249
- * @param fn - Function used to test (should return a boolean)
250
- * @param thisArg - Value to use as `this` when executing function
251
- * @example
252
- * ```ts
253
- * collection.some(user => user.discriminator === '0000');
254
- * ```
255
- */
256
- some(fn: (value: V, key: K, collection: this) => unknown): boolean;
257
- some<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): boolean;
258
- /**
259
- * Checks if all items passes a test. Identical in behavior to
260
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
261
- *
262
- * @param fn - Function used to test (should return a boolean)
263
- * @param thisArg - Value to use as `this` when executing function
264
- * @example
265
- * ```ts
266
- * collection.every(user => !user.bot);
267
- * ```
268
- */
269
- every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;
270
- every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;
271
- every(fn: (value: V, key: K, collection: this) => unknown): boolean;
272
- every<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): this is Collection<K2, V>;
273
- every<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): this is Collection<K, V2>;
274
- every<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): boolean;
275
- /**
276
- * Applies a function to produce a single value. Identical in behavior to
277
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
278
- *
279
- * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
280
- * and `collection`
281
- * @param initialValue - Starting value for the accumulator
282
- * @example
283
- * ```ts
284
- * collection.reduce((acc, guild) => acc + guild.memberCount, 0);
285
- * ```
286
- */
287
- reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
288
- /**
289
- * Identical to
290
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
291
- * but returns the collection instead of undefined.
292
- *
293
- * @param fn - Function to execute for each element
294
- * @param thisArg - Value to use as `this` when executing function
295
- * @example
296
- * ```ts
297
- * collection
298
- * .each(user => console.log(user.username))
299
- * .filter(user => user.bot)
300
- * .each(user => console.log(user.username));
301
- * ```
302
- */
303
- each(fn: (value: V, key: K, collection: this) => void): this;
304
- each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
305
- /**
306
- * Runs a function on the collection and returns the collection.
307
- *
308
- * @param fn - Function to execute
309
- * @param thisArg - Value to use as `this` when executing function
310
- * @example
311
- * ```ts
312
- * collection
313
- * .tap(coll => console.log(coll.size))
314
- * .filter(user => user.bot)
315
- * .tap(coll => console.log(coll.size))
316
- * ```
317
- */
318
- tap(fn: (collection: this) => void): this;
319
- tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
320
- /**
321
- * Creates an identical shallow copy of this collection.
322
- *
323
- * @example
324
- * ```ts
325
- * const newColl = someColl.clone();
326
- * ```
327
- */
328
- clone(): Collection<K, V>;
329
- /**
330
- * Combines this collection with others into a new collection. None of the source collections are modified.
331
- *
332
- * @param collections - Collections to merge
333
- * @example
334
- * ```ts
335
- * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
336
- * ```
337
- */
338
- concat(...collections: ReadonlyCollection<K, V>[]): Collection<K, V>;
339
- /**
340
- * Checks if this collection shares identical items with another.
341
- * This is different to checking for equality using equal-signs, because
342
- * the collections may be different objects, but contain the same data.
343
- *
344
- * @param collection - Collection to compare with
345
- * @returns Whether the collections have identical contents
346
- */
347
- equals(collection: ReadonlyCollection<K, V>): boolean;
348
- /**
349
- * The sort method sorts the items of a collection in place and returns it.
350
- * The sort is not necessarily stable in Node 10 or older.
351
- * The default sort order is according to string Unicode code points.
352
- *
353
- * @param compareFunction - Specifies a function that defines the sort order.
354
- * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
355
- * @example
356
- * ```ts
357
- * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
358
- * ```
359
- */
360
- sort(compareFunction?: Comparator<K, V>): this;
361
- /**
362
- * The intersect method returns a new structure containing items where the keys and values are present in both original structures.
363
- *
364
- * @param other - The other Collection to filter against
365
- */
366
- intersect<T>(other: ReadonlyCollection<K, T>): Collection<K, T>;
367
- /**
368
- * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.
369
- *
370
- * @param other - The other Collection to filter against
371
- */
372
- subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V>;
373
- /**
374
- * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
375
- *
376
- * @param other - The other Collection to filter against
377
- */
378
- difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>;
379
- /**
380
- * Merges two Collections together into a new Collection.
381
- *
382
- * @param other - The other Collection to merge with
383
- * @param whenInSelf - Function getting the result if the entry only exists in this Collection
384
- * @param whenInOther - Function getting the result if the entry only exists in the other Collection
385
- * @param whenInBoth - Function getting the result if the entry exists in both Collections
386
- * @example
387
- * ```ts
388
- * // Sums up the entries in two collections.
389
- * coll.merge(
390
- * other,
391
- * x => ({ keep: true, value: x }),
392
- * y => ({ keep: true, value: y }),
393
- * (x, y) => ({ keep: true, value: x + y }),
394
- * );
395
- * ```
396
- * @example
397
- * ```ts
398
- * // Intersects two collections in a left-biased manner.
399
- * coll.merge(
400
- * other,
401
- * x => ({ keep: false }),
402
- * y => ({ keep: false }),
403
- * (x, _) => ({ keep: true, value: x }),
404
- * );
405
- * ```
406
- */
407
- merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>;
408
- /**
409
- * The sorted method sorts the items of a collection and returns it.
410
- * The sort is not necessarily stable in Node 10 or older.
411
- * The default sort order is according to string Unicode code points.
412
- *
413
- * @param compareFunction - Specifies a function that defines the sort order.
414
- * If omitted, the collection is sorted according to each character's Unicode code point value,
415
- * according to the string conversion of each element.
416
- * @example
417
- * ```ts
418
- * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
419
- * ```
420
- */
421
- sorted(compareFunction?: Comparator<K, V>): Collection<K, V>;
422
- toJSON(): V[];
423
- private static defaultSort;
424
- /**
425
- * Creates a Collection from a list of entries.
426
- *
427
- * @param entries - The list of entries
428
- * @param combine - Function to combine an existing entry with a new one
429
- * @example
430
- * ```ts
431
- * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
432
- * // returns Collection { "a" => 3, "b" => 2 }
433
- * ```
434
- */
435
- static combineEntries<K, V>(entries: Iterable<[K, V]>, combine: (firstValue: V, secondValue: V, key: K) => V): Collection<K, V>;
436
- }
437
- /**
438
- * @internal
439
- */
440
- type Keep<V> = {
441
- keep: false;
442
- } | {
443
- keep: true;
444
- value: V;
445
- };
446
- /**
447
- * @internal
448
- */
449
- type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;
450
-
451
- /**
452
- * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version
453
- * that you are currently using.
454
- */
455
- declare const version: string;
456
-
457
- export { Collection, CollectionConstructor, Comparator, Keep, ReadonlyCollection, version };
@@ -1,543 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var src_exports = {};
23
- __export(src_exports, {
24
- Collection: () => Collection,
25
- version: () => version
26
- });
27
- module.exports = __toCommonJS(src_exports);
28
-
29
- // src/collection.ts
30
- var Collection = class _Collection extends Map {
31
- static {
32
- __name(this, "Collection");
33
- }
34
- /**
35
- * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
36
- *
37
- * @param key - The key to get if it exists, or set otherwise
38
- * @param defaultValueGenerator - A function that generates the default value
39
- * @example
40
- * ```ts
41
- * collection.ensure(guildId, () => defaultGuildConfig);
42
- * ```
43
- */
44
- ensure(key, defaultValueGenerator) {
45
- if (this.has(key))
46
- return this.get(key);
47
- if (typeof defaultValueGenerator !== "function")
48
- throw new TypeError(`${defaultValueGenerator} is not a function`);
49
- const defaultValue = defaultValueGenerator(key, this);
50
- this.set(key, defaultValue);
51
- return defaultValue;
52
- }
53
- /**
54
- * Checks if all of the elements exist in the collection.
55
- *
56
- * @param keys - The keys of the elements to check for
57
- * @returns `true` if all of the elements exist, `false` if at least one does not exist.
58
- */
59
- hasAll(...keys) {
60
- return keys.every((key) => super.has(key));
61
- }
62
- /**
63
- * Checks if any of the elements exist in the collection.
64
- *
65
- * @param keys - The keys of the elements to check for
66
- * @returns `true` if any of the elements exist, `false` if none exist.
67
- */
68
- hasAny(...keys) {
69
- return keys.some((key) => super.has(key));
70
- }
71
- first(amount) {
72
- if (amount === void 0)
73
- return this.values().next().value;
74
- if (amount < 0)
75
- return this.last(amount * -1);
76
- amount = Math.min(this.size, amount);
77
- const iter = this.values();
78
- return Array.from({ length: amount }, () => iter.next().value);
79
- }
80
- firstKey(amount) {
81
- if (amount === void 0)
82
- return this.keys().next().value;
83
- if (amount < 0)
84
- return this.lastKey(amount * -1);
85
- amount = Math.min(this.size, amount);
86
- const iter = this.keys();
87
- return Array.from({ length: amount }, () => iter.next().value);
88
- }
89
- last(amount) {
90
- const arr = [...this.values()];
91
- if (amount === void 0)
92
- return arr[arr.length - 1];
93
- if (amount < 0)
94
- return this.first(amount * -1);
95
- if (!amount)
96
- return [];
97
- return arr.slice(-amount);
98
- }
99
- lastKey(amount) {
100
- const arr = [...this.keys()];
101
- if (amount === void 0)
102
- return arr[arr.length - 1];
103
- if (amount < 0)
104
- return this.firstKey(amount * -1);
105
- if (!amount)
106
- return [];
107
- return arr.slice(-amount);
108
- }
109
- /**
110
- * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
111
- * Returns the item at a given index, allowing for positive and negative integers.
112
- * Negative integers count back from the last item in the collection.
113
- *
114
- * @param index - The index of the element to obtain
115
- */
116
- at(index) {
117
- index = Math.floor(index);
118
- const arr = [...this.values()];
119
- return arr.at(index);
120
- }
121
- /**
122
- * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
123
- * Returns the key at a given index, allowing for positive and negative integers.
124
- * Negative integers count back from the last item in the collection.
125
- *
126
- * @param index - The index of the key to obtain
127
- */
128
- keyAt(index) {
129
- index = Math.floor(index);
130
- const arr = [...this.keys()];
131
- return arr.at(index);
132
- }
133
- random(amount) {
134
- const arr = [...this.values()];
135
- if (amount === void 0)
136
- return arr[Math.floor(Math.random() * arr.length)];
137
- if (!arr.length || !amount)
138
- return [];
139
- return Array.from(
140
- { length: Math.min(amount, arr.length) },
141
- () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
142
- );
143
- }
144
- randomKey(amount) {
145
- const arr = [...this.keys()];
146
- if (amount === void 0)
147
- return arr[Math.floor(Math.random() * arr.length)];
148
- if (!arr.length || !amount)
149
- return [];
150
- return Array.from(
151
- { length: Math.min(amount, arr.length) },
152
- () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
153
- );
154
- }
155
- /**
156
- * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
157
- * but returns a Collection instead of an Array.
158
- */
159
- reverse() {
160
- const entries = [...this.entries()].reverse();
161
- this.clear();
162
- for (const [key, value] of entries)
163
- this.set(key, value);
164
- return this;
165
- }
166
- find(fn, thisArg) {
167
- if (typeof fn !== "function")
168
- throw new TypeError(`${fn} is not a function`);
169
- if (thisArg !== void 0)
170
- fn = fn.bind(thisArg);
171
- for (const [key, val] of this) {
172
- if (fn(val, key, this))
173
- return val;
174
- }
175
- return void 0;
176
- }
177
- findKey(fn, thisArg) {
178
- if (typeof fn !== "function")
179
- throw new TypeError(`${fn} is not a function`);
180
- if (thisArg !== void 0)
181
- fn = fn.bind(thisArg);
182
- for (const [key, val] of this) {
183
- if (fn(val, key, this))
184
- return key;
185
- }
186
- return void 0;
187
- }
188
- sweep(fn, thisArg) {
189
- if (typeof fn !== "function")
190
- throw new TypeError(`${fn} is not a function`);
191
- if (thisArg !== void 0)
192
- fn = fn.bind(thisArg);
193
- const previousSize = this.size;
194
- for (const [key, val] of this) {
195
- if (fn(val, key, this))
196
- this.delete(key);
197
- }
198
- return previousSize - this.size;
199
- }
200
- filter(fn, thisArg) {
201
- if (typeof fn !== "function")
202
- throw new TypeError(`${fn} is not a function`);
203
- if (thisArg !== void 0)
204
- fn = fn.bind(thisArg);
205
- const results = new this.constructor[Symbol.species]();
206
- for (const [key, val] of this) {
207
- if (fn(val, key, this))
208
- results.set(key, val);
209
- }
210
- return results;
211
- }
212
- partition(fn, thisArg) {
213
- if (typeof fn !== "function")
214
- throw new TypeError(`${fn} is not a function`);
215
- if (thisArg !== void 0)
216
- fn = fn.bind(thisArg);
217
- const results = [
218
- new this.constructor[Symbol.species](),
219
- new this.constructor[Symbol.species]()
220
- ];
221
- for (const [key, val] of this) {
222
- if (fn(val, key, this)) {
223
- results[0].set(key, val);
224
- } else {
225
- results[1].set(key, val);
226
- }
227
- }
228
- return results;
229
- }
230
- flatMap(fn, thisArg) {
231
- const collections = this.map(fn, thisArg);
232
- return new this.constructor[Symbol.species]().concat(...collections);
233
- }
234
- map(fn, thisArg) {
235
- if (typeof fn !== "function")
236
- throw new TypeError(`${fn} is not a function`);
237
- if (thisArg !== void 0)
238
- fn = fn.bind(thisArg);
239
- const iter = this.entries();
240
- return Array.from({ length: this.size }, () => {
241
- const [key, value] = iter.next().value;
242
- return fn(value, key, this);
243
- });
244
- }
245
- mapValues(fn, thisArg) {
246
- if (typeof fn !== "function")
247
- throw new TypeError(`${fn} is not a function`);
248
- if (thisArg !== void 0)
249
- fn = fn.bind(thisArg);
250
- const coll = new this.constructor[Symbol.species]();
251
- for (const [key, val] of this)
252
- coll.set(key, fn(val, key, this));
253
- return coll;
254
- }
255
- some(fn, thisArg) {
256
- if (typeof fn !== "function")
257
- throw new TypeError(`${fn} is not a function`);
258
- if (thisArg !== void 0)
259
- fn = fn.bind(thisArg);
260
- for (const [key, val] of this) {
261
- if (fn(val, key, this))
262
- return true;
263
- }
264
- return false;
265
- }
266
- every(fn, thisArg) {
267
- if (typeof fn !== "function")
268
- throw new TypeError(`${fn} is not a function`);
269
- if (thisArg !== void 0)
270
- fn = fn.bind(thisArg);
271
- for (const [key, val] of this) {
272
- if (!fn(val, key, this))
273
- return false;
274
- }
275
- return true;
276
- }
277
- /**
278
- * Applies a function to produce a single value. Identical in behavior to
279
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
280
- *
281
- * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
282
- * and `collection`
283
- * @param initialValue - Starting value for the accumulator
284
- * @example
285
- * ```ts
286
- * collection.reduce((acc, guild) => acc + guild.memberCount, 0);
287
- * ```
288
- */
289
- reduce(fn, initialValue) {
290
- if (typeof fn !== "function")
291
- throw new TypeError(`${fn} is not a function`);
292
- let accumulator;
293
- const iterator = this.entries();
294
- if (initialValue === void 0) {
295
- if (this.size === 0)
296
- throw new TypeError("Reduce of empty collection with no initial value");
297
- accumulator = iterator.next().value[1];
298
- } else {
299
- accumulator = initialValue;
300
- }
301
- for (const [key, value] of iterator) {
302
- accumulator = fn(accumulator, value, key, this);
303
- }
304
- return accumulator;
305
- }
306
- each(fn, thisArg) {
307
- if (typeof fn !== "function")
308
- throw new TypeError(`${fn} is not a function`);
309
- if (thisArg !== void 0)
310
- fn = fn.bind(thisArg);
311
- for (const [key, value] of this) {
312
- fn(value, key, this);
313
- }
314
- return this;
315
- }
316
- tap(fn, thisArg) {
317
- if (typeof fn !== "function")
318
- throw new TypeError(`${fn} is not a function`);
319
- if (thisArg !== void 0)
320
- fn = fn.bind(thisArg);
321
- fn(this);
322
- return this;
323
- }
324
- /**
325
- * Creates an identical shallow copy of this collection.
326
- *
327
- * @example
328
- * ```ts
329
- * const newColl = someColl.clone();
330
- * ```
331
- */
332
- clone() {
333
- return new this.constructor[Symbol.species](this);
334
- }
335
- /**
336
- * Combines this collection with others into a new collection. None of the source collections are modified.
337
- *
338
- * @param collections - Collections to merge
339
- * @example
340
- * ```ts
341
- * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
342
- * ```
343
- */
344
- concat(...collections) {
345
- const newColl = this.clone();
346
- for (const coll of collections) {
347
- for (const [key, val] of coll)
348
- newColl.set(key, val);
349
- }
350
- return newColl;
351
- }
352
- /**
353
- * Checks if this collection shares identical items with another.
354
- * This is different to checking for equality using equal-signs, because
355
- * the collections may be different objects, but contain the same data.
356
- *
357
- * @param collection - Collection to compare with
358
- * @returns Whether the collections have identical contents
359
- */
360
- equals(collection) {
361
- if (!collection)
362
- return false;
363
- if (this === collection)
364
- return true;
365
- if (this.size !== collection.size)
366
- return false;
367
- for (const [key, value] of this) {
368
- if (!collection.has(key) || value !== collection.get(key)) {
369
- return false;
370
- }
371
- }
372
- return true;
373
- }
374
- /**
375
- * The sort method sorts the items of a collection in place and returns it.
376
- * The sort is not necessarily stable in Node 10 or older.
377
- * The default sort order is according to string Unicode code points.
378
- *
379
- * @param compareFunction - Specifies a function that defines the sort order.
380
- * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
381
- * @example
382
- * ```ts
383
- * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
384
- * ```
385
- */
386
- sort(compareFunction = _Collection.defaultSort) {
387
- const entries = [...this.entries()];
388
- entries.sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]));
389
- super.clear();
390
- for (const [key, value] of entries) {
391
- super.set(key, value);
392
- }
393
- return this;
394
- }
395
- /**
396
- * The intersect method returns a new structure containing items where the keys and values are present in both original structures.
397
- *
398
- * @param other - The other Collection to filter against
399
- */
400
- intersect(other) {
401
- const coll = new this.constructor[Symbol.species]();
402
- for (const [key, value] of other) {
403
- if (this.has(key) && Object.is(value, this.get(key))) {
404
- coll.set(key, value);
405
- }
406
- }
407
- return coll;
408
- }
409
- /**
410
- * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.
411
- *
412
- * @param other - The other Collection to filter against
413
- */
414
- subtract(other) {
415
- const coll = new this.constructor[Symbol.species]();
416
- for (const [key, value] of this) {
417
- if (!other.has(key) || !Object.is(value, other.get(key))) {
418
- coll.set(key, value);
419
- }
420
- }
421
- return coll;
422
- }
423
- /**
424
- * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
425
- *
426
- * @param other - The other Collection to filter against
427
- */
428
- difference(other) {
429
- const coll = new this.constructor[Symbol.species]();
430
- for (const [key, value] of other) {
431
- if (!this.has(key))
432
- coll.set(key, value);
433
- }
434
- for (const [key, value] of this) {
435
- if (!other.has(key))
436
- coll.set(key, value);
437
- }
438
- return coll;
439
- }
440
- /**
441
- * Merges two Collections together into a new Collection.
442
- *
443
- * @param other - The other Collection to merge with
444
- * @param whenInSelf - Function getting the result if the entry only exists in this Collection
445
- * @param whenInOther - Function getting the result if the entry only exists in the other Collection
446
- * @param whenInBoth - Function getting the result if the entry exists in both Collections
447
- * @example
448
- * ```ts
449
- * // Sums up the entries in two collections.
450
- * coll.merge(
451
- * other,
452
- * x => ({ keep: true, value: x }),
453
- * y => ({ keep: true, value: y }),
454
- * (x, y) => ({ keep: true, value: x + y }),
455
- * );
456
- * ```
457
- * @example
458
- * ```ts
459
- * // Intersects two collections in a left-biased manner.
460
- * coll.merge(
461
- * other,
462
- * x => ({ keep: false }),
463
- * y => ({ keep: false }),
464
- * (x, _) => ({ keep: true, value: x }),
465
- * );
466
- * ```
467
- */
468
- merge(other, whenInSelf, whenInOther, whenInBoth) {
469
- const coll = new this.constructor[Symbol.species]();
470
- const keys = /* @__PURE__ */ new Set([...this.keys(), ...other.keys()]);
471
- for (const key of keys) {
472
- const hasInSelf = this.has(key);
473
- const hasInOther = other.has(key);
474
- if (hasInSelf && hasInOther) {
475
- const result = whenInBoth(this.get(key), other.get(key), key);
476
- if (result.keep)
477
- coll.set(key, result.value);
478
- } else if (hasInSelf) {
479
- const result = whenInSelf(this.get(key), key);
480
- if (result.keep)
481
- coll.set(key, result.value);
482
- } else if (hasInOther) {
483
- const result = whenInOther(other.get(key), key);
484
- if (result.keep)
485
- coll.set(key, result.value);
486
- }
487
- }
488
- return coll;
489
- }
490
- /**
491
- * The sorted method sorts the items of a collection and returns it.
492
- * The sort is not necessarily stable in Node 10 or older.
493
- * The default sort order is according to string Unicode code points.
494
- *
495
- * @param compareFunction - Specifies a function that defines the sort order.
496
- * If omitted, the collection is sorted according to each character's Unicode code point value,
497
- * according to the string conversion of each element.
498
- * @example
499
- * ```ts
500
- * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
501
- * ```
502
- */
503
- sorted(compareFunction = _Collection.defaultSort) {
504
- return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
505
- }
506
- toJSON() {
507
- return [...this.values()];
508
- }
509
- static defaultSort(firstValue, secondValue) {
510
- return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;
511
- }
512
- /**
513
- * Creates a Collection from a list of entries.
514
- *
515
- * @param entries - The list of entries
516
- * @param combine - Function to combine an existing entry with a new one
517
- * @example
518
- * ```ts
519
- * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
520
- * // returns Collection { "a" => 3, "b" => 2 }
521
- * ```
522
- */
523
- static combineEntries(entries, combine) {
524
- const coll = new _Collection();
525
- for (const [key, value] of entries) {
526
- if (coll.has(key)) {
527
- coll.set(key, combine(coll.get(key), value, key));
528
- } else {
529
- coll.set(key, value);
530
- }
531
- }
532
- return coll;
533
- }
534
- };
535
-
536
- // src/index.ts
537
- var version = "1.5.3";
538
- // Annotate the CommonJS export names for ESM import in node:
539
- 0 && (module.exports = {
540
- Collection,
541
- version
542
- });
543
- //# sourceMappingURL=index.js.map