@discordjs/util 2.0.0-dev.1793836959-ddbba3adb → 2.0.0-dev.1794787379-57db0bb10

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.
Files changed (56) hide show
  1. package/dist/Equatable.d.ts +19 -0
  2. package/dist/Equatable.d.ts.map +1 -0
  3. package/dist/Equatable.js +9 -0
  4. package/dist/Equatable.js.map +1 -0
  5. package/dist/RawFile.d.ts +33 -0
  6. package/dist/RawFile.d.ts.map +1 -0
  7. package/dist/RawFile.js +2 -0
  8. package/dist/RawFile.js.map +1 -0
  9. package/dist/encodables.d.ts +71 -0
  10. package/dist/encodables.d.ts.map +1 -0
  11. package/dist/encodables.js +25 -0
  12. package/dist/encodables.js.map +1 -0
  13. package/dist/functions/calculateShardId.d.ts +8 -0
  14. package/dist/functions/calculateShardId.d.ts.map +1 -0
  15. package/dist/functions/calculateShardId.js +10 -0
  16. package/dist/functions/calculateShardId.js.map +1 -0
  17. package/dist/functions/embedLength.d.ts +8 -0
  18. package/dist/functions/embedLength.d.ts.map +1 -0
  19. package/dist/functions/embedLength.js +13 -0
  20. package/dist/functions/embedLength.js.map +1 -0
  21. package/dist/functions/index.d.ts +7 -0
  22. package/dist/functions/index.d.ts.map +1 -0
  23. package/dist/functions/index.js +7 -0
  24. package/dist/functions/index.js.map +1 -0
  25. package/dist/functions/lazy.d.ts +14 -0
  26. package/dist/functions/lazy.d.ts.map +1 -0
  27. package/dist/functions/lazy.js +25 -0
  28. package/dist/functions/lazy.js.map +1 -0
  29. package/dist/functions/range.d.ts +45 -0
  30. package/dist/functions/range.d.ts.map +1 -0
  31. package/dist/functions/range.js +41 -0
  32. package/dist/functions/range.js.map +1 -0
  33. package/dist/functions/runtime.d.ts +2 -0
  34. package/dist/functions/runtime.d.ts.map +1 -0
  35. package/dist/functions/runtime.js +18 -0
  36. package/dist/functions/runtime.js.map +1 -0
  37. package/dist/functions/userAgentAppendix.d.ts +5 -0
  38. package/dist/functions/userAgentAppendix.d.ts.map +1 -0
  39. package/dist/functions/userAgentAppendix.js +40 -0
  40. package/dist/functions/userAgentAppendix.js.map +1 -0
  41. package/dist/gatewayRateLimitError.d.ts +33 -0
  42. package/dist/gatewayRateLimitError.d.ts.map +1 -0
  43. package/dist/gatewayRateLimitError.js +26 -0
  44. package/dist/gatewayRateLimitError.js.map +1 -0
  45. package/dist/index.d.ts +8 -244
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +11 -179
  48. package/dist/index.js.map +1 -1
  49. package/dist/types.d.ts +5 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +2 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +6 -14
  54. package/dist/index.d.mts +0 -250
  55. package/dist/index.mjs +0 -144
  56. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Represents a structure that can be checked against another
3
+ * given structure for equality
4
+ *
5
+ * @typeParam Value - The type of object to compare the current object to
6
+ */
7
+ export interface Equatable<Value> {
8
+ /**
9
+ * Whether or not this is equal to another structure
10
+ */
11
+ equals(other: Value): boolean;
12
+ }
13
+ /**
14
+ * Indicates if an object is equatable or not.
15
+ *
16
+ * @param maybeEquatable - The object to check against
17
+ */
18
+ export declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown>;
19
+ //# sourceMappingURL=Equatable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Equatable.d.ts","sourceRoot":"","sources":["../src/Equatable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,SAAS,CAAC,KAAK;IAC/B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,IAAI,SAAS,CAAC,OAAO,CAAC,CAEzF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Indicates if an object is equatable or not.
3
+ *
4
+ * @param maybeEquatable - The object to check against
5
+ */
6
+ export function isEquatable(maybeEquatable) {
7
+ return maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;
8
+ }
9
+ //# sourceMappingURL=Equatable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Equatable.js","sourceRoot":"","sources":["../src/Equatable.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,cAAuB;IAClD,OAAO,cAAc,KAAK,IAAI,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,QAAQ,IAAI,cAAc,CAAC;AACpG,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { Buffer } from 'node:buffer';
2
+ /**
3
+ * Represents a file to be added to a request with multipart/form-data encoding
4
+ */
5
+ export interface RawFile {
6
+ /**
7
+ * Content-Type of the file.
8
+ * If not provided, it will be inferred from the file data when possible
9
+ *
10
+ * @example 'image/png'
11
+ * @example 'application/pdf'
12
+ */
13
+ contentType?: string;
14
+ /**
15
+ * The actual data for the file
16
+ */
17
+ data: Buffer | Uint8Array | boolean | number | string;
18
+ /**
19
+ * An explicit key to use for the formdata field for this file.
20
+ * When not provided, the index of the file in the files array is used in the form `files[${index}]`.
21
+ * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
22
+ */
23
+ key?: string;
24
+ /**
25
+ * The name of the file. This is the actual filename that will be used when uploading to Discord.
26
+ * This is also the name you'll use to reference the file with attachment:// URLs.
27
+ *
28
+ * @example 'image.png'
29
+ * @example 'document.pdf'
30
+ */
31
+ name: string;
32
+ }
33
+ //# sourceMappingURL=RawFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RawFile.d.ts","sourceRoot":"","sources":["../src/RawFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC;CACb"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RawFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RawFile.js","sourceRoot":"","sources":["../src/RawFile.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import type { RESTAPIAttachment } from 'discord-api-types/v10';
2
+ import type { RawFile } from './RawFile.js';
3
+ /**
4
+ * Represents an object capable of representing itself as a JSON object
5
+ *
6
+ * @typeParam Value - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
7
+ */
8
+ export interface JSONEncodable<Value> {
9
+ /**
10
+ * Transforms this object to its JSON format
11
+ */
12
+ toJSON(): Value;
13
+ }
14
+ /**
15
+ * Indicates if an object is encodable or not.
16
+ *
17
+ * @param maybeEncodable - The object to check against
18
+ */
19
+ export declare function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown>;
20
+ /**
21
+ * Result of encoding an object that includes file attachments
22
+ *
23
+ * @typeParam BodyValue - The JSON body type
24
+ */
25
+ export interface FileBodyEncodableResult<BodyValue> {
26
+ /**
27
+ * The JSON body to send with the request
28
+ */
29
+ body: BodyValue;
30
+ /**
31
+ * The files to attach to the request
32
+ */
33
+ files: RawFile[];
34
+ }
35
+ /**
36
+ * Represents an object capable of representing itself as a request body with file attachments.
37
+ * Objects implementing this interface can separate JSON body data from binary file data,
38
+ * which is necessary for multipart/form-data requests.
39
+ *
40
+ * @typeParam BodyValue - The JSON body type
41
+ */
42
+ export interface FileBodyEncodable<BodyValue> {
43
+ /**
44
+ * Transforms this object to its file body format, separating the JSON body from file attachments.
45
+ */
46
+ toFileBody(): FileBodyEncodableResult<BodyValue>;
47
+ }
48
+ /**
49
+ * Indicates if an object is file body encodable or not.
50
+ *
51
+ * @param maybeEncodable - The object to check against
52
+ */
53
+ export declare function isFileBodyEncodable(maybeEncodable: unknown): maybeEncodable is FileBodyEncodable<unknown>;
54
+ /**
55
+ * Represents an object capable of representing itself as a raw file attachment.
56
+ * Objects implementing this interface can return binary file data to be sent as part of
57
+ * multipart/form-data requests.
58
+ */
59
+ export interface RawFileEncodable extends JSONEncodable<RESTAPIAttachment> {
60
+ /**
61
+ * Returns the raw file of an attachment.
62
+ */
63
+ getRawFile(): Partial<RawFile> | undefined;
64
+ }
65
+ /**
66
+ * Indicates if an object is raw file encodable or not.
67
+ *
68
+ * @param maybeEncodable - The object to check against
69
+ */
70
+ export declare function isRawFileEncodable(maybeEncodable: unknown): maybeEncodable is RawFileEncodable;
71
+ //# sourceMappingURL=encodables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodables.d.ts","sourceRoot":"","sources":["../src/encodables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK;IACnC;;OAEG;IACH,MAAM,IAAI,KAAK,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,IAAI,aAAa,CAAC,OAAO,CAAC,CAEjG;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB,CAAC,SAAS;IACjD;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,OAAO,EAAE,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB,CAAC,SAAS;IAC3C;;OAEG;IACH,UAAU,IAAI,uBAAuB,CAAC,SAAS,CAAC,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAEzG;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,aAAa,CAAC,iBAAiB,CAAC;IACzE;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,IAAI,gBAAgB,CAE9F"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Indicates if an object is encodable or not.
3
+ *
4
+ * @param maybeEncodable - The object to check against
5
+ */
6
+ export function isJSONEncodable(maybeEncodable) {
7
+ return maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;
8
+ }
9
+ /**
10
+ * Indicates if an object is file body encodable or not.
11
+ *
12
+ * @param maybeEncodable - The object to check against
13
+ */
14
+ export function isFileBodyEncodable(maybeEncodable) {
15
+ return maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toFileBody' in maybeEncodable;
16
+ }
17
+ /**
18
+ * Indicates if an object is raw file encodable or not.
19
+ *
20
+ * @param maybeEncodable - The object to check against
21
+ */
22
+ export function isRawFileEncodable(maybeEncodable) {
23
+ return isJSONEncodable(maybeEncodable) && 'getRawFile' in maybeEncodable;
24
+ }
25
+ //# sourceMappingURL=encodables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodables.js","sourceRoot":"","sources":["../src/encodables.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,cAAuB;IACtD,OAAO,cAAc,KAAK,IAAI,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,QAAQ,IAAI,cAAc,CAAC;AACpG,CAAC;AAgCD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,cAAuB;IAC1D,OAAO,cAAc,KAAK,IAAI,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,YAAY,IAAI,cAAc,CAAC;AACxG,CAAC;AAcD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAAuB;IACzD,OAAO,eAAe,CAAC,cAAc,CAAC,IAAI,YAAY,IAAI,cAAc,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculates the shard id for a given guild id.
3
+ *
4
+ * @param guildId - The guild id to calculate the shard id for
5
+ * @param shardCount - The total number of shards
6
+ */
7
+ export declare function calculateShardId(guildId: string, shardCount: number): number;
8
+ //# sourceMappingURL=calculateShardId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateShardId.d.ts","sourceRoot":"","sources":["../../src/functions/calculateShardId.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAEnE"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculates the shard id for a given guild id.
3
+ *
4
+ * @param guildId - The guild id to calculate the shard id for
5
+ * @param shardCount - The total number of shards
6
+ */
7
+ export function calculateShardId(guildId, shardCount) {
8
+ return Number(BigInt(guildId) >> 22n) % shardCount;
9
+ }
10
+ //# sourceMappingURL=calculateShardId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateShardId.js","sourceRoot":"","sources":["../../src/functions/calculateShardId.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,UAAkB;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,UAAU,CAAC;AACpD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { APIEmbed } from 'discord-api-types/v10';
2
+ /**
3
+ * Calculates the length of an embed.
4
+ *
5
+ * @param data - The embed data to check
6
+ */
7
+ export declare function embedLength(data: APIEmbed): number;
8
+ //# sourceMappingURL=embedLength.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedLength.d.ts","sourceRoot":"","sources":["../../src/functions/embedLength.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,UAQzC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Calculates the length of an embed.
3
+ *
4
+ * @param data - The embed data to check
5
+ */
6
+ export function embedLength(data) {
7
+ return ((data.title?.length ?? 0) +
8
+ (data.description?.length ?? 0) +
9
+ (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) +
10
+ (data.footer?.text.length ?? 0) +
11
+ (data.author?.name.length ?? 0));
12
+ }
13
+ //# sourceMappingURL=embedLength.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedLength.js","sourceRoot":"","sources":["../../src/functions/embedLength.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAc;IACzC,OAAO,CACN,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC;QACzB,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC;QAC/B,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1F,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QAC/B,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAC/B,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './calculateShardId.js';
2
+ export * from './embedLength.js';
3
+ export * from './lazy.js';
4
+ export * from './range.js';
5
+ export * from './runtime.js';
6
+ export * from './userAgentAppendix.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './calculateShardId.js';
2
+ export * from './embedLength.js';
3
+ export * from './lazy.js';
4
+ export * from './range.js';
5
+ export * from './runtime.js';
6
+ export * from './userAgentAppendix.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Lazy is a wrapper around a value that is computed lazily. It is useful for
3
+ * cases where the value is expensive to compute and the computation may not
4
+ * be needed at all.
5
+ *
6
+ * @param cb - The callback to lazily evaluate
7
+ * @typeParam Value - The type of the value
8
+ * @example
9
+ * ```ts
10
+ * const value = lazy(() => computeExpensiveValue());
11
+ * ```
12
+ */
13
+ export declare function lazy<Value>(cb: () => Value): () => Value;
14
+ //# sourceMappingURL=lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/functions/lazy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,wBAAgB,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,KAAK,GAAG,MAAM,KAAK,CASxD"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Lazy is a wrapper around a value that is computed lazily. It is useful for
3
+ * cases where the value is expensive to compute and the computation may not
4
+ * be needed at all.
5
+ *
6
+ * @param cb - The callback to lazily evaluate
7
+ * @typeParam Value - The type of the value
8
+ * @example
9
+ * ```ts
10
+ * const value = lazy(() => computeExpensiveValue());
11
+ * ```
12
+ */
13
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
14
+ export function lazy(cb) {
15
+ let defaultValue;
16
+ let called = false;
17
+ return () => {
18
+ if (called)
19
+ return defaultValue;
20
+ called = true;
21
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
22
+ return (defaultValue = cb());
23
+ };
24
+ }
25
+ //# sourceMappingURL=lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../src/functions/lazy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,MAAM,UAAU,IAAI,CAAQ,EAAe;IAC1C,IAAI,YAAmB,CAAC;IACxB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,OAAO,GAAG,EAAE;QACX,IAAI,MAAM;YAAE,OAAO,YAAY,CAAC;QAChC,MAAM,GAAG,IAAI,CAAC;QACd,6DAA6D;QAC7D,OAAO,CAAC,YAAY,GAAG,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Options for creating a range
3
+ */
4
+ export interface RangeOptions {
5
+ /**
6
+ * The end of the range (exclusive)
7
+ */
8
+ end: number;
9
+ /**
10
+ * The start of the range (inclusive)
11
+ */
12
+ start: number;
13
+ /**
14
+ * The amount to increment by
15
+ *
16
+ * @defaultValue `1`
17
+ */
18
+ step?: number;
19
+ }
20
+ /**
21
+ * A generator to yield numbers in a given range
22
+ *
23
+ * @remarks
24
+ * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you
25
+ * prefer for the end to be included add 1 to the range or `end` option.
26
+ * @param range - A number representing the range to yield (exclusive) or an object with start, end and step
27
+ * @example
28
+ * Basic range
29
+ * ```ts
30
+ * for (const number of range(5)) {
31
+ * console.log(number);
32
+ * }
33
+ * // Prints 0, 1, 2, 3, 4
34
+ * ```
35
+ * @example
36
+ * Range with a step
37
+ * ```ts
38
+ * for (const number of range({ start: 3, end: 10, step: 2 })) {
39
+ * console.log(number);
40
+ * }
41
+ * // Prints 3, 5, 7, 9
42
+ * ```
43
+ */
44
+ export declare function range(range: RangeOptions | number): Generator<number, void, unknown>;
45
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/functions/range.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAiB,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,oCAgBlD"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A generator to yield numbers in a given range
3
+ *
4
+ * @remarks
5
+ * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you
6
+ * prefer for the end to be included add 1 to the range or `end` option.
7
+ * @param range - A number representing the range to yield (exclusive) or an object with start, end and step
8
+ * @example
9
+ * Basic range
10
+ * ```ts
11
+ * for (const number of range(5)) {
12
+ * console.log(number);
13
+ * }
14
+ * // Prints 0, 1, 2, 3, 4
15
+ * ```
16
+ * @example
17
+ * Range with a step
18
+ * ```ts
19
+ * for (const number of range({ start: 3, end: 10, step: 2 })) {
20
+ * console.log(number);
21
+ * }
22
+ * // Prints 3, 5, 7, 9
23
+ * ```
24
+ */
25
+ export function* range(range) {
26
+ let rangeEnd;
27
+ let start = 0;
28
+ let step = 1;
29
+ if (typeof range === 'number') {
30
+ rangeEnd = range;
31
+ }
32
+ else {
33
+ start = range.start;
34
+ rangeEnd = range.end;
35
+ step = range.step ?? 1;
36
+ }
37
+ for (let index = start; index < rangeEnd; index += step) {
38
+ yield index;
39
+ }
40
+ }
41
+ //# sourceMappingURL=range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/functions/range.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,KAA4B;IAClD,IAAI,QAAgB,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,QAAQ,GAAG,KAAK,CAAC;IAClB,CAAC;SAAM,CAAC;QACP,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC;QACrB,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,IAAI,KAAK,GAAG,KAAK,EAAE,KAAK,GAAG,QAAQ,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;QACzD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function shouldUseGlobalFetchAndWebSocket(): boolean;
2
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/functions/runtime.ts"],"names":[],"mappings":"AAAA,wBAAgB,gCAAgC,YAmB/C"}
@@ -0,0 +1,18 @@
1
+ export function shouldUseGlobalFetchAndWebSocket() {
2
+ // Browser env and deno when ran directly
3
+ if (typeof globalThis.process === 'undefined') {
4
+ return 'fetch' in globalThis && 'WebSocket' in globalThis;
5
+ }
6
+ // Cloudflare Workers with nodejs_compat polyfills process (including
7
+ // process.versions.node), but natively supports the Web WebSocket API.
8
+ // WebSocketPair is a Workers-only global; no other runtime exposes it.
9
+ // @ts-expect-error WebSocketPair is not in the globalThis type
10
+ if (typeof globalThis.WebSocketPair !== 'undefined') {
11
+ return true;
12
+ }
13
+ if ('versions' in globalThis.process) {
14
+ return 'deno' in globalThis.process.versions || 'bun' in globalThis.process.versions;
15
+ }
16
+ return false;
17
+ }
18
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/functions/runtime.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gCAAgC;IAC/C,yCAAyC;IACzC,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC/C,OAAO,OAAO,IAAI,UAAU,IAAI,WAAW,IAAI,UAAU,CAAC;IAC3D,CAAC;IAED,qEAAqE;IACrE,uEAAuE;IACvE,uEAAuE;IACvE,+DAA+D;IAC/D,IAAI,OAAO,UAAU,CAAC,aAAa,KAAK,WAAW,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,UAAU,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACtC,OAAO,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Resolves the user agent appendix string for the current environment.
3
+ */
4
+ export declare function getUserAgentAppendix(): string;
5
+ //# sourceMappingURL=userAgentAppendix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userAgentAppendix.d.ts","sourceRoot":"","sources":["../../src/functions/userAgentAppendix.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA2C7C"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Resolves the user agent appendix string for the current environment.
3
+ */
4
+ export function getUserAgentAppendix() {
5
+ // https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime#check-if-you're-running-on-the-edge-runtime
6
+ // @ts-expect-error Vercel Edge functions
7
+ if (typeof globalThis.EdgeRuntime !== 'undefined') {
8
+ return 'Vercel-Edge-Functions';
9
+ }
10
+ // @ts-expect-error Cloudflare Workers
11
+ if (typeof globalThis.R2 !== 'undefined' && typeof globalThis.WebSocketPair !== 'undefined') {
12
+ // https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent
13
+ return 'Cloudflare-Workers';
14
+ }
15
+ // https://docs.netlify.com/edge-functions/api/#netlify-global-object
16
+ // @ts-expect-error Netlify Edge functions
17
+ if (typeof globalThis.Netlify !== 'undefined') {
18
+ return 'Netlify-Edge-Functions';
19
+ }
20
+ // Most (if not all) edge environments will have `process` defined. Within a web browser we'll extract it using `navigator.userAgent`.
21
+ if (typeof globalThis.process !== 'object') {
22
+ if (typeof globalThis.navigator === 'object') {
23
+ return globalThis.navigator.userAgent;
24
+ }
25
+ return 'UnknownEnvironment';
26
+ }
27
+ if ('versions' in globalThis.process) {
28
+ if ('deno' in globalThis.process.versions) {
29
+ return `Deno/${globalThis.process.versions.deno}`;
30
+ }
31
+ if ('bun' in globalThis.process.versions) {
32
+ return `Bun/${globalThis.process.versions.bun}`;
33
+ }
34
+ if ('node' in globalThis.process.versions) {
35
+ return `Node.js/${globalThis.process.versions.node}`;
36
+ }
37
+ }
38
+ return 'UnknownEnvironment';
39
+ }
40
+ //# sourceMappingURL=userAgentAppendix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userAgentAppendix.js","sourceRoot":"","sources":["../../src/functions/userAgentAppendix.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,oBAAoB;IACnC,qHAAqH;IACrH,yCAAyC;IACzC,IAAI,OAAO,UAAU,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;QACnD,OAAO,uBAAuB,CAAC;IAChC,CAAC;IAED,sCAAsC;IACtC,IAAI,OAAO,UAAU,CAAC,EAAE,KAAK,WAAW,IAAI,OAAO,UAAU,CAAC,aAAa,KAAK,WAAW,EAAE,CAAC;QAC7F,2FAA2F;QAC3F,OAAO,oBAAoB,CAAC;IAC7B,CAAC;IAED,qEAAqE;IACrE,0CAA0C;IAC1C,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC/C,OAAO,wBAAwB,CAAC;IACjC,CAAC;IAED,sIAAsI;IACtI,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC9C,OAAO,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC;QACvC,CAAC;QAED,OAAO,oBAAoB,CAAC;IAC7B,CAAC;IAED,IAAI,UAAU,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACtC,IAAI,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3C,OAAO,QAAQ,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnD,CAAC;QAED,IAAI,KAAK,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC1C,OAAO,OAAO,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACjD,CAAC;QAED,IAAI,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3C,OAAO,WAAW,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtD,CAAC;IACF,CAAC;IAED,OAAO,oBAAoB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { GatewayOpcodeRateLimitMetadataMap, GatewayRateLimitedDispatchData } from 'discord-api-types/v10';
2
+ /**
3
+ * Represents the error thrown when the gateway emits a `RATE_LIMITED` event after a certain request.
4
+ */
5
+ export declare class GatewayRateLimitError extends Error {
6
+ /**
7
+ * The data associated with the rate limit event
8
+ */
9
+ readonly data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>;
10
+ /**
11
+ * The payload data that lead to this rate limit
12
+ *
13
+ * @privateRemarks
14
+ * Too complicated to type properly here (i.e. extract the ['data']
15
+ * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
16
+ */
17
+ readonly payload: unknown;
18
+ readonly name: string;
19
+ constructor(
20
+ /**
21
+ * The data associated with the rate limit event
22
+ */
23
+ data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>,
24
+ /**
25
+ * The payload data that lead to this rate limit
26
+ *
27
+ * @privateRemarks
28
+ * Too complicated to type properly here (i.e. extract the ['data']
29
+ * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
30
+ */
31
+ payload: unknown);
32
+ }
33
+ //# sourceMappingURL=gatewayRateLimitError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatewayRateLimitError.d.ts","sourceRoot":"","sources":["../src/gatewayRateLimitError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAE/G;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAI9C;;OAEG;aACa,IAAI,EAAE,8BAA8B,CAAC,MAAM,iCAAiC,CAAC;IAC7F;;;;;;OAMG;aACa,OAAO,EAAE,OAAO;IAdjC,SAAyB,IAAI,SAA8B;IAE3D;IACC;;OAEG;IACa,IAAI,EAAE,8BAA8B,CAAC,MAAM,iCAAiC,CAAC;IAC7F;;;;;;OAMG;IACa,OAAO,EAAE,OAAO,EAGhC;CACD"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Represents the error thrown when the gateway emits a `RATE_LIMITED` event after a certain request.
3
+ */
4
+ export class GatewayRateLimitError extends Error {
5
+ data;
6
+ payload;
7
+ name = GatewayRateLimitError.name;
8
+ constructor(
9
+ /**
10
+ * The data associated with the rate limit event
11
+ */
12
+ data,
13
+ /**
14
+ * The payload data that lead to this rate limit
15
+ *
16
+ * @privateRemarks
17
+ * Too complicated to type properly here (i.e. extract the ['data']
18
+ * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
19
+ */
20
+ payload) {
21
+ super(`Request with opcode ${data.opcode} was rate limited. Retry after ${data.retry_after} seconds.`);
22
+ this.data = data;
23
+ this.payload = payload;
24
+ }
25
+ }
26
+ //# sourceMappingURL=gatewayRateLimitError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatewayRateLimitError.js","sourceRoot":"","sources":["../src/gatewayRateLimitError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAO9B,IAAI;IAQJ,OAAO;IAdC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC;IAE3D;IACC;;OAEG;IACa,IAA6E;IAC7F;;;;;;OAMG;IACa,OAAgB;QAEhC,KAAK,CAAC,uBAAuB,IAAI,CAAC,MAAM,kCAAkC,IAAI,CAAC,WAAW,WAAW,CAAC,CAAC;oBAVvF,IAAI;uBAQJ,OAAO;IAGxB,CAAC;CACD"}