@discordjs/util 2.0.0-dev.1794009739-5bb74922a → 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
package/dist/index.d.ts CHANGED
@@ -1,250 +1,14 @@
1
- import { APIEmbed, RESTAPIAttachment, GatewayRateLimitedDispatchData, GatewayOpcodeRateLimitMetadataMap } from 'discord-api-types/v10';
2
- import { Buffer } from 'node:buffer';
3
-
4
- /**
5
- * Represents a type that may or may not be a promise
6
- */
7
- type Awaitable<Value> = PromiseLike<Value> | Value;
8
-
9
- /**
10
- * Calculates the shard id for a given guild id.
11
- *
12
- * @param guildId - The guild id to calculate the shard id for
13
- * @param shardCount - The total number of shards
14
- */
15
- declare function calculateShardId(guildId: string, shardCount: number): number;
16
-
17
- /**
18
- * Calculates the length of an embed.
19
- *
20
- * @param data - The embed data to check
21
- */
22
- declare function embedLength(data: APIEmbed): number;
23
-
24
- /**
25
- * Lazy is a wrapper around a value that is computed lazily. It is useful for
26
- * cases where the value is expensive to compute and the computation may not
27
- * be needed at all.
28
- *
29
- * @param cb - The callback to lazily evaluate
30
- * @typeParam Value - The type of the value
31
- * @example
32
- * ```ts
33
- * const value = lazy(() => computeExpensiveValue());
34
- * ```
35
- */
36
- declare function lazy<Value>(cb: () => Value): () => Value;
37
-
38
- /**
39
- * Options for creating a range
40
- */
41
- interface RangeOptions {
42
- /**
43
- * The end of the range (exclusive)
44
- */
45
- end: number;
46
- /**
47
- * The start of the range (inclusive)
48
- */
49
- start: number;
50
- /**
51
- * The amount to increment by
52
- *
53
- * @defaultValue `1`
54
- */
55
- step?: number;
56
- }
57
- /**
58
- * A generator to yield numbers in a given range
59
- *
60
- * @remarks
61
- * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you
62
- * prefer for the end to be included add 1 to the range or `end` option.
63
- * @param range - A number representing the range to yield (exclusive) or an object with start, end and step
64
- * @example
65
- * Basic range
66
- * ```ts
67
- * for (const number of range(5)) {
68
- * console.log(number);
69
- * }
70
- * // Prints 0, 1, 2, 3, 4
71
- * ```
72
- * @example
73
- * Range with a step
74
- * ```ts
75
- * for (const number of range({ start: 3, end: 10, step: 2 })) {
76
- * console.log(number);
77
- * }
78
- * // Prints 3, 5, 7, 9
79
- * ```
80
- */
81
- declare function range(range: RangeOptions | number): Generator<number, void, unknown>;
82
-
83
- declare function shouldUseGlobalFetchAndWebSocket(): boolean;
84
-
85
- /**
86
- * Resolves the user agent appendix string for the current environment.
87
- */
88
- declare function getUserAgentAppendix(): string;
89
-
90
- /**
91
- * Represents a file to be added to a request with multipart/form-data encoding
92
- */
93
- interface RawFile {
94
- /**
95
- * Content-Type of the file.
96
- * If not provided, it will be inferred from the file data when possible
97
- *
98
- * @example 'image/png'
99
- * @example 'application/pdf'
100
- */
101
- contentType?: string;
102
- /**
103
- * The actual data for the file
104
- */
105
- data: Buffer | Uint8Array | boolean | number | string;
106
- /**
107
- * An explicit key to use for the formdata field for this file.
108
- * When not provided, the index of the file in the files array is used in the form `files[${index}]`.
109
- * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
110
- */
111
- key?: string;
112
- /**
113
- * The name of the file. This is the actual filename that will be used when uploading to Discord.
114
- * This is also the name you'll use to reference the file with attachment:// URLs.
115
- *
116
- * @example 'image.png'
117
- * @example 'document.pdf'
118
- */
119
- name: string;
120
- }
121
-
122
- /**
123
- * Represents an object capable of representing itself as a JSON object
124
- *
125
- * @typeParam Value - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
126
- */
127
- interface JSONEncodable<Value> {
128
- /**
129
- * Transforms this object to its JSON format
130
- */
131
- toJSON(): Value;
132
- }
133
- /**
134
- * Indicates if an object is encodable or not.
135
- *
136
- * @param maybeEncodable - The object to check against
137
- */
138
- declare function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown>;
139
- /**
140
- * Result of encoding an object that includes file attachments
141
- *
142
- * @typeParam BodyValue - The JSON body type
143
- */
144
- interface FileBodyEncodableResult<BodyValue> {
145
- /**
146
- * The JSON body to send with the request
147
- */
148
- body: BodyValue;
149
- /**
150
- * The files to attach to the request
151
- */
152
- files: RawFile[];
153
- }
154
- /**
155
- * Represents an object capable of representing itself as a request body with file attachments.
156
- * Objects implementing this interface can separate JSON body data from binary file data,
157
- * which is necessary for multipart/form-data requests.
158
- *
159
- * @typeParam BodyValue - The JSON body type
160
- */
161
- interface FileBodyEncodable<BodyValue> {
162
- /**
163
- * Transforms this object to its file body format, separating the JSON body from file attachments.
164
- */
165
- toFileBody(): FileBodyEncodableResult<BodyValue>;
166
- }
167
- /**
168
- * Indicates if an object is file body encodable or not.
169
- *
170
- * @param maybeEncodable - The object to check against
171
- */
172
- declare function isFileBodyEncodable(maybeEncodable: unknown): maybeEncodable is FileBodyEncodable<unknown>;
173
- /**
174
- * Represents an object capable of representing itself as a raw file attachment.
175
- * Objects implementing this interface can return binary file data to be sent as part of
176
- * multipart/form-data requests.
177
- */
178
- interface RawFileEncodable extends JSONEncodable<RESTAPIAttachment> {
179
- /**
180
- * Returns the raw file of an attachment.
181
- */
182
- getRawFile(): Partial<RawFile> | undefined;
183
- }
184
- /**
185
- * Indicates if an object is raw file encodable or not.
186
- *
187
- * @param maybeEncodable - The object to check against
188
- */
189
- declare function isRawFileEncodable(maybeEncodable: unknown): maybeEncodable is RawFileEncodable;
190
-
191
- /**
192
- * Represents a structure that can be checked against another
193
- * given structure for equality
194
- *
195
- * @typeParam Value - The type of object to compare the current object to
196
- */
197
- interface Equatable<Value> {
198
- /**
199
- * Whether or not this is equal to another structure
200
- */
201
- equals(other: Value): boolean;
202
- }
203
- /**
204
- * Indicates if an object is equatable or not.
205
- *
206
- * @param maybeEquatable - The object to check against
207
- */
208
- declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown>;
209
-
210
- /**
211
- * Represents the error thrown when the gateway emits a `RATE_LIMITED` event after a certain request.
212
- */
213
- declare class GatewayRateLimitError extends Error {
214
- /**
215
- * The data associated with the rate limit event
216
- */
217
- readonly data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>;
218
- /**
219
- * The payload data that lead to this rate limit
220
- *
221
- * @privateRemarks
222
- * Too complicated to type properly here (i.e. extract the ['data']
223
- * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
224
- */
225
- readonly payload: unknown;
226
- readonly name: string;
227
- constructor(
228
- /**
229
- * The data associated with the rate limit event
230
- */
231
- data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>,
232
- /**
233
- * The payload data that lead to this rate limit
234
- *
235
- * @privateRemarks
236
- * Too complicated to type properly here (i.e. extract the ['data']
237
- * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
238
- */
239
- payload: unknown);
240
- }
241
-
1
+ export type * from './types.js';
2
+ export * from './functions/index.js';
3
+ export * from './encodables.js';
4
+ export type * from './RawFile.js';
5
+ export * from './Equatable.js';
6
+ export * from './gatewayRateLimitError.js';
242
7
  /**
243
8
  * The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} version
244
9
  * that you are currently using.
245
10
  *
246
11
  * @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild.
247
12
  */
248
- declare const version: string;
249
-
250
- export { type Awaitable, type Equatable, type FileBodyEncodable, type FileBodyEncodableResult, GatewayRateLimitError, type JSONEncodable, type RangeOptions, type RawFile, type RawFileEncodable, calculateShardId, embedLength, getUserAgentAppendix, isEquatable, isFileBodyEncodable, isJSONEncodable, isRawFileEncodable, lazy, range, shouldUseGlobalFetchAndWebSocket, version };
13
+ export declare const version: string;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,mBAAmB,cAAc,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAA4B,MAAM,CAAC"}
package/dist/index.js CHANGED
@@ -1,180 +1,12 @@
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 index_exports = {};
23
- __export(index_exports, {
24
- GatewayRateLimitError: () => GatewayRateLimitError,
25
- calculateShardId: () => calculateShardId,
26
- embedLength: () => embedLength,
27
- getUserAgentAppendix: () => getUserAgentAppendix,
28
- isEquatable: () => isEquatable,
29
- isFileBodyEncodable: () => isFileBodyEncodable,
30
- isJSONEncodable: () => isJSONEncodable,
31
- isRawFileEncodable: () => isRawFileEncodable,
32
- lazy: () => lazy,
33
- range: () => range,
34
- shouldUseGlobalFetchAndWebSocket: () => shouldUseGlobalFetchAndWebSocket,
35
- version: () => version
36
- });
37
- module.exports = __toCommonJS(index_exports);
38
-
39
- // src/functions/calculateShardId.ts
40
- function calculateShardId(guildId, shardCount) {
41
- return Number(BigInt(guildId) >> 22n) % shardCount;
42
- }
43
- __name(calculateShardId, "calculateShardId");
44
-
45
- // src/functions/embedLength.ts
46
- function embedLength(data) {
47
- return (data.title?.length ?? 0) + (data.description?.length ?? 0) + (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) + (data.footer?.text.length ?? 0) + (data.author?.name.length ?? 0);
48
- }
49
- __name(embedLength, "embedLength");
50
-
51
- // src/functions/lazy.ts
52
- function lazy(cb) {
53
- let defaultValue;
54
- let called = false;
55
- return () => {
56
- if (called) return defaultValue;
57
- called = true;
58
- return defaultValue = cb();
59
- };
60
- }
61
- __name(lazy, "lazy");
62
-
63
- // src/functions/range.ts
64
- function* range(range2) {
65
- let rangeEnd;
66
- let start = 0;
67
- let step = 1;
68
- if (typeof range2 === "number") {
69
- rangeEnd = range2;
70
- } else {
71
- start = range2.start;
72
- rangeEnd = range2.end;
73
- step = range2.step ?? 1;
74
- }
75
- for (let index = start; index < rangeEnd; index += step) {
76
- yield index;
77
- }
78
- }
79
- __name(range, "range");
80
-
81
- // src/functions/runtime.ts
82
- function shouldUseGlobalFetchAndWebSocket() {
83
- if (typeof globalThis.process === "undefined") {
84
- return "fetch" in globalThis && "WebSocket" in globalThis;
85
- }
86
- if (typeof globalThis.WebSocketPair !== "undefined") {
87
- return true;
88
- }
89
- if ("versions" in globalThis.process) {
90
- return "deno" in globalThis.process.versions || "bun" in globalThis.process.versions;
91
- }
92
- return false;
93
- }
94
- __name(shouldUseGlobalFetchAndWebSocket, "shouldUseGlobalFetchAndWebSocket");
95
-
96
- // src/functions/userAgentAppendix.ts
97
- function getUserAgentAppendix() {
98
- if (typeof globalThis.EdgeRuntime !== "undefined") {
99
- return "Vercel-Edge-Functions";
100
- }
101
- if (typeof globalThis.R2 !== "undefined" && typeof globalThis.WebSocketPair !== "undefined") {
102
- return "Cloudflare-Workers";
103
- }
104
- if (typeof globalThis.Netlify !== "undefined") {
105
- return "Netlify-Edge-Functions";
106
- }
107
- if (typeof globalThis.process !== "object") {
108
- if (typeof globalThis.navigator === "object") {
109
- return globalThis.navigator.userAgent;
110
- }
111
- return "UnknownEnvironment";
112
- }
113
- if ("versions" in globalThis.process) {
114
- if ("deno" in globalThis.process.versions) {
115
- return `Deno/${globalThis.process.versions.deno}`;
116
- }
117
- if ("bun" in globalThis.process.versions) {
118
- return `Bun/${globalThis.process.versions.bun}`;
119
- }
120
- if ("node" in globalThis.process.versions) {
121
- return `Node.js/${globalThis.process.versions.node}`;
122
- }
123
- }
124
- return "UnknownEnvironment";
125
- }
126
- __name(getUserAgentAppendix, "getUserAgentAppendix");
127
-
128
- // src/encodables.ts
129
- function isJSONEncodable(maybeEncodable) {
130
- return maybeEncodable !== null && typeof maybeEncodable === "object" && "toJSON" in maybeEncodable;
131
- }
132
- __name(isJSONEncodable, "isJSONEncodable");
133
- function isFileBodyEncodable(maybeEncodable) {
134
- return maybeEncodable !== null && typeof maybeEncodable === "object" && "toFileBody" in maybeEncodable;
135
- }
136
- __name(isFileBodyEncodable, "isFileBodyEncodable");
137
- function isRawFileEncodable(maybeEncodable) {
138
- return isJSONEncodable(maybeEncodable) && "getRawFile" in maybeEncodable;
139
- }
140
- __name(isRawFileEncodable, "isRawFileEncodable");
141
-
142
- // src/Equatable.ts
143
- function isEquatable(maybeEquatable) {
144
- return maybeEquatable !== null && typeof maybeEquatable === "object" && "equals" in maybeEquatable;
145
- }
146
- __name(isEquatable, "isEquatable");
147
-
148
- // src/gatewayRateLimitError.ts
149
- var GatewayRateLimitError = class _GatewayRateLimitError extends Error {
150
- constructor(data, payload) {
151
- super(`Request with opcode ${data.opcode} was rate limited. Retry after ${data.retry_after} seconds.`);
152
- this.data = data;
153
- this.payload = payload;
154
- }
155
- data;
156
- payload;
157
- static {
158
- __name(this, "GatewayRateLimitError");
159
- }
160
- name = _GatewayRateLimitError.name;
161
- };
162
-
163
- // src/index.ts
164
- var version = "2.0.0-dev.1794009739-5bb74922a";
165
- // Annotate the CommonJS export names for ESM import in node:
166
- 0 && (module.exports = {
167
- GatewayRateLimitError,
168
- calculateShardId,
169
- embedLength,
170
- getUserAgentAppendix,
171
- isEquatable,
172
- isFileBodyEncodable,
173
- isJSONEncodable,
174
- isRawFileEncodable,
175
- lazy,
176
- range,
177
- shouldUseGlobalFetchAndWebSocket,
178
- version
179
- });
1
+ export * from './functions/index.js';
2
+ export * from './encodables.js';
3
+ export * from './Equatable.js';
4
+ export * from './gatewayRateLimitError.js';
5
+ /**
6
+ * The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} version
7
+ * that you are currently using.
8
+ *
9
+ * @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild.
10
+ */
11
+ export const version = '2.0.0-dev.1794787379-57db0bb10';
180
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/functions/calculateShardId.ts","../src/functions/embedLength.ts","../src/functions/lazy.ts","../src/functions/range.ts","../src/functions/runtime.ts","../src/functions/userAgentAppendix.ts","../src/encodables.ts","../src/Equatable.ts","../src/gatewayRateLimitError.ts"],"sourcesContent":["export type * from './types.js';\nexport * from './functions/index.js';\nexport * from './encodables.js';\nexport type * from './RawFile.js';\nexport * from './Equatable.js';\nexport * from './gatewayRateLimitError.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '2.0.0-dev.1794009739-5bb74922a' as string;\n","/**\n * Calculates the shard id for a given guild id.\n *\n * @param guildId - The guild id to calculate the shard id for\n * @param shardCount - The total number of shards\n */\nexport function calculateShardId(guildId: string, shardCount: number) {\n\treturn Number(BigInt(guildId) >> 22n) % shardCount;\n}\n","import type { APIEmbed } from 'discord-api-types/v10';\n\n/**\n * Calculates the length of an embed.\n *\n * @param data - The embed data to check\n */\nexport function embedLength(data: APIEmbed) {\n\treturn (\n\t\t(data.title?.length ?? 0) +\n\t\t(data.description?.length ?? 0) +\n\t\t(data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) +\n\t\t(data.footer?.text.length ?? 0) +\n\t\t(data.author?.name.length ?? 0)\n\t);\n}\n","/**\n * Lazy is a wrapper around a value that is computed lazily. It is useful for\n * cases where the value is expensive to compute and the computation may not\n * be needed at all.\n *\n * @param cb - The callback to lazily evaluate\n * @typeParam Value - The type of the value\n * @example\n * ```ts\n * const value = lazy(() => computeExpensiveValue());\n * ```\n */\n// eslint-disable-next-line promise/prefer-await-to-callbacks\nexport function lazy<Value>(cb: () => Value): () => Value {\n\tlet defaultValue: Value;\n\tlet called = false;\n\treturn () => {\n\t\tif (called) return defaultValue;\n\t\tcalled = true;\n\t\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\t\treturn (defaultValue = cb());\n\t};\n}\n","/**\n * Options for creating a range\n */\nexport interface RangeOptions {\n\t/**\n\t * The end of the range (exclusive)\n\t */\n\tend: number;\n\t/**\n\t * The start of the range (inclusive)\n\t */\n\tstart: number;\n\t/**\n\t * The amount to increment by\n\t *\n\t * @defaultValue `1`\n\t */\n\tstep?: number;\n}\n\n/**\n * A generator to yield numbers in a given range\n *\n * @remarks\n * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you\n * prefer for the end to be included add 1 to the range or `end` option.\n * @param range - A number representing the range to yield (exclusive) or an object with start, end and step\n * @example\n * Basic range\n * ```ts\n * for (const number of range(5)) {\n * console.log(number);\n * }\n * // Prints 0, 1, 2, 3, 4\n * ```\n * @example\n * Range with a step\n * ```ts\n * for (const number of range({ start: 3, end: 10, step: 2 })) {\n * \tconsole.log(number);\n * }\n * // Prints 3, 5, 7, 9\n * ```\n */\nexport function* range(range: RangeOptions | number) {\n\tlet rangeEnd: number;\n\tlet start = 0;\n\tlet step = 1;\n\n\tif (typeof range === 'number') {\n\t\trangeEnd = range;\n\t} else {\n\t\tstart = range.start;\n\t\trangeEnd = range.end;\n\t\tstep = range.step ?? 1;\n\t}\n\n\tfor (let index = start; index < rangeEnd; index += step) {\n\t\tyield index;\n\t}\n}\n","export function shouldUseGlobalFetchAndWebSocket() {\n\t// Browser env and deno when ran directly\n\tif (typeof globalThis.process === 'undefined') {\n\t\treturn 'fetch' in globalThis && 'WebSocket' in globalThis;\n\t}\n\n\t// Cloudflare Workers with nodejs_compat polyfills process (including\n\t// process.versions.node), but natively supports the Web WebSocket API.\n\t// WebSocketPair is a Workers-only global; no other runtime exposes it.\n\t// @ts-expect-error WebSocketPair is not in the globalThis type\n\tif (typeof globalThis.WebSocketPair !== 'undefined') {\n\t\treturn true;\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\treturn 'deno' in globalThis.process.versions || 'bun' in globalThis.process.versions;\n\t}\n\n\treturn false;\n}\n","/**\n * Resolves the user agent appendix string for the current environment.\n */\nexport function getUserAgentAppendix(): string {\n\t// https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime#check-if-you're-running-on-the-edge-runtime\n\t// @ts-expect-error Vercel Edge functions\n\tif (typeof globalThis.EdgeRuntime !== 'undefined') {\n\t\treturn 'Vercel-Edge-Functions';\n\t}\n\n\t// @ts-expect-error Cloudflare Workers\n\tif (typeof globalThis.R2 !== 'undefined' && typeof globalThis.WebSocketPair !== 'undefined') {\n\t\t// https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent\n\t\treturn 'Cloudflare-Workers';\n\t}\n\n\t// https://docs.netlify.com/edge-functions/api/#netlify-global-object\n\t// @ts-expect-error Netlify Edge functions\n\tif (typeof globalThis.Netlify !== 'undefined') {\n\t\treturn 'Netlify-Edge-Functions';\n\t}\n\n\t// Most (if not all) edge environments will have `process` defined. Within a web browser we'll extract it using `navigator.userAgent`.\n\tif (typeof globalThis.process !== 'object') {\n\t\tif (typeof globalThis.navigator === 'object') {\n\t\t\treturn globalThis.navigator.userAgent;\n\t\t}\n\n\t\treturn 'UnknownEnvironment';\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\tif ('deno' in globalThis.process.versions) {\n\t\t\treturn `Deno/${globalThis.process.versions.deno}`;\n\t\t}\n\n\t\tif ('bun' in globalThis.process.versions) {\n\t\t\treturn `Bun/${globalThis.process.versions.bun}`;\n\t\t}\n\n\t\tif ('node' in globalThis.process.versions) {\n\t\t\treturn `Node.js/${globalThis.process.versions.node}`;\n\t\t}\n\t}\n\n\treturn 'UnknownEnvironment';\n}\n","import type { RESTAPIAttachment } from 'discord-api-types/v10';\nimport type { RawFile } from './RawFile.js';\n\n/**\n * Represents an object capable of representing itself as a JSON object\n *\n * @typeParam Value - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.\n */\nexport interface JSONEncodable<Value> {\n\t/**\n\t * Transforms this object to its JSON format\n\t */\n\ttoJSON(): Value;\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;\n}\n\n/**\n * Result of encoding an object that includes file attachments\n *\n * @typeParam BodyValue - The JSON body type\n */\nexport interface FileBodyEncodableResult<BodyValue> {\n\t/**\n\t * The JSON body to send with the request\n\t */\n\tbody: BodyValue;\n\t/**\n\t * The files to attach to the request\n\t */\n\tfiles: RawFile[];\n}\n\n/**\n * Represents an object capable of representing itself as a request body with file attachments.\n * Objects implementing this interface can separate JSON body data from binary file data,\n * which is necessary for multipart/form-data requests.\n *\n * @typeParam BodyValue - The JSON body type\n */\nexport interface FileBodyEncodable<BodyValue> {\n\t/**\n\t * Transforms this object to its file body format, separating the JSON body from file attachments.\n\t */\n\ttoFileBody(): FileBodyEncodableResult<BodyValue>;\n}\n\n/**\n * Indicates if an object is file body encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isFileBodyEncodable(maybeEncodable: unknown): maybeEncodable is FileBodyEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toFileBody' in maybeEncodable;\n}\n\n/**\n * Represents an object capable of representing itself as a raw file attachment.\n * Objects implementing this interface can return binary file data to be sent as part of\n * multipart/form-data requests.\n */\nexport interface RawFileEncodable extends JSONEncodable<RESTAPIAttachment> {\n\t/**\n\t * Returns the raw file of an attachment.\n\t */\n\tgetRawFile(): Partial<RawFile> | undefined;\n}\n\n/**\n * Indicates if an object is raw file encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isRawFileEncodable(maybeEncodable: unknown): maybeEncodable is RawFileEncodable {\n\treturn isJSONEncodable(maybeEncodable) && 'getRawFile' in maybeEncodable;\n}\n","/**\n * Represents a structure that can be checked against another\n * given structure for equality\n *\n * @typeParam Value - The type of object to compare the current object to\n */\nexport interface Equatable<Value> {\n\t/**\n\t * Whether or not this is equal to another structure\n\t */\n\tequals(other: Value): boolean;\n}\n\n/**\n * Indicates if an object is equatable or not.\n *\n * @param maybeEquatable - The object to check against\n */\nexport function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown> {\n\treturn maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;\n}\n","import type { GatewayOpcodeRateLimitMetadataMap, GatewayRateLimitedDispatchData } from 'discord-api-types/v10';\n\n/**\n * Represents the error thrown when the gateway emits a `RATE_LIMITED` event after a certain request.\n */\nexport class GatewayRateLimitError extends Error {\n\tpublic override readonly name = GatewayRateLimitError.name;\n\n\tpublic constructor(\n\t\t/**\n\t\t * The data associated with the rate limit event\n\t\t */\n\t\tpublic readonly data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>,\n\t\t/**\n\t\t * The payload data that lead to this rate limit\n\t\t *\n\t\t * @privateRemarks\n\t\t * Too complicated to type properly here (i.e. extract the ['data']\n\t\t * of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)\n\t\t */\n\t\tpublic readonly payload: unknown,\n\t) {\n\t\tsuper(`Request with opcode ${data.opcode} was rate limited. Retry after ${data.retry_after} seconds.`);\n\t}\n}\n"],"mappings":"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","names":["range"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,qBAA+B,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Represents a type that may or may not be a promise
3
+ */
4
+ export type Awaitable<Value> = PromiseLike<Value> | Value;
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@discordjs/util",
4
- "version": "2.0.0-dev.1794009739-5bb74922a",
4
+ "version": "2.0.0-dev.1794787379-57db0bb10",
5
5
  "description": "Utilities shared across Discord.js packages",
6
6
  "keywords": [
7
7
  "api",
@@ -34,19 +34,13 @@
34
34
  "files": [
35
35
  "dist"
36
36
  ],
37
+ "type": "module",
37
38
  "main": "./dist/index.js",
38
- "module": "./dist/index.mjs",
39
39
  "types": "./dist/index.d.ts",
40
40
  "exports": {
41
41
  ".": {
42
- "require": {
43
- "types": "./dist/index.d.ts",
44
- "default": "./dist/index.js"
45
- },
46
- "import": {
47
- "types": "./dist/index.d.mts",
48
- "default": "./dist/index.mjs"
49
- }
42
+ "types": "./dist/index.d.ts",
43
+ "default": "./dist/index.js"
50
44
  }
51
45
  },
52
46
  "publishConfig": {
@@ -62,20 +56,18 @@
62
56
  "@favware/cliff-jumper": "^6.1.0",
63
57
  "@types/node": "^24.13.3",
64
58
  "@vitest/coverage-v8": "^4.1.11",
65
- "esbuild-plugin-version-injector": "^1.2.1",
66
59
  "eslint-config-neon": "^0.5.4",
67
60
  "oxfmt": "^0.74.0",
68
61
  "oxlint": "^1.89.0",
69
- "tsup": "^8.5.1",
70
62
  "turbo": "^2.10.12",
71
- "typescript": "~5.9.3",
63
+ "typescript": "~7.0.2",
72
64
  "vitest": "^4.1.11"
73
65
  },
74
66
  "engines": {
75
67
  "node": ">=24.17.0"
76
68
  },
77
69
  "scripts": {
78
- "build": "tsc --noEmit && tsup",
70
+ "build": "tsc && inject-version",
79
71
  "build:docs": "tsc -p tsconfig.docs.json",
80
72
  "test": "vitest run --config ../../vitest.config.ts",
81
73
  "lint": "oxfmt --check && oxlint --tsconfig=tsconfig.eslint.json src",