@discordeno/utils 19.0.0-next.f98bb9b → 19.0.0-next.f9bdfce
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/README.md +6 -143
- package/dist/cjs/Collection.cjs +123 -0
- package/dist/cjs/base64.cjs +276 -0
- package/dist/cjs/bucket.cjs +96 -0
- package/dist/cjs/builders/embeds.cjs +292 -0
- package/dist/cjs/builders.cjs +27 -0
- package/dist/cjs/casing.cjs +75 -0
- package/dist/cjs/colors.cjs +456 -0
- package/dist/cjs/hash.cjs +37 -0
- package/dist/cjs/images.cjs +136 -0
- package/dist/cjs/index.cjs +36 -0
- package/dist/cjs/logger.cjs +157 -0
- package/dist/cjs/oauth2.cjs +26 -0
- package/dist/cjs/permissions.cjs +35 -0
- package/dist/cjs/reactions.cjs +21 -0
- package/dist/cjs/token.cjs +39 -0
- package/dist/cjs/typeguards.cjs +45 -0
- package/dist/cjs/urlToBase64.cjs +19 -0
- package/dist/cjs/urls.cjs +26 -0
- package/dist/cjs/utils.cjs +30 -0
- package/dist/esm/Collection.js +113 -0
- package/dist/esm/base64.js +262 -0
- package/dist/esm/bucket.js +81 -0
- package/dist/esm/builders/embeds.js +295 -0
- package/dist/esm/builders.js +5 -0
- package/dist/esm/casing.js +51 -0
- package/dist/esm/colors.js +467 -0
- package/dist/esm/hash.js +19 -0
- package/dist/esm/images.js +179 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/logger.js +130 -0
- package/dist/esm/oauth2.js +16 -0
- package/dist/esm/permissions.js +17 -0
- package/dist/esm/reactions.js +11 -0
- package/dist/esm/token.js +21 -0
- package/dist/esm/typeguards.js +18 -0
- package/dist/esm/urlToBase64.js +9 -0
- package/dist/esm/urls.js +8 -0
- package/dist/esm/utils.js +15 -0
- package/dist/{Collection.d.ts → types/Collection.d.ts} +2 -3
- package/dist/types/Collection.d.ts.map +1 -0
- package/dist/types/base64.d.ts.map +1 -0
- package/dist/{bucket.d.ts → types/bucket.d.ts} +9 -2
- package/dist/types/bucket.d.ts.map +1 -0
- package/dist/{builders → types/builders}/embeds.d.ts +17 -17
- package/dist/types/builders/embeds.d.ts.map +1 -0
- package/dist/types/builders.d.ts.map +1 -0
- package/dist/types/casing.d.ts.map +1 -0
- package/dist/types/colors.d.ts.map +1 -0
- package/dist/types/hash.d.ts.map +1 -0
- package/dist/types/images.d.ts +202 -0
- package/dist/types/images.d.ts.map +1 -0
- package/dist/{index.d.ts → types/index.d.ts} +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{oauth2.d.ts → types/oauth2.d.ts} +12 -1
- package/dist/types/oauth2.d.ts.map +1 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/reactions.d.ts.map +1 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/typeguards.d.ts.map +1 -0
- package/dist/types/urlToBase64.d.ts.map +1 -0
- package/dist/types/urls.d.ts +4 -0
- package/dist/types/urls.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +27 -22
- package/dist/Collection.d.ts.map +0 -1
- package/dist/Collection.js +0 -113
- package/dist/Collection.js.map +0 -1
- package/dist/base64.d.ts.map +0 -1
- package/dist/base64.js +0 -262
- package/dist/base64.js.map +0 -1
- package/dist/bucket.d.ts.map +0 -1
- package/dist/bucket.js +0 -76
- package/dist/bucket.js.map +0 -1
- package/dist/builders/embeds.d.ts.map +0 -1
- package/dist/builders/embeds.js +0 -295
- package/dist/builders/embeds.js.map +0 -1
- package/dist/builders.d.ts.map +0 -1
- package/dist/builders.js +0 -5
- package/dist/builders.js.map +0 -1
- package/dist/casing.d.ts.map +0 -1
- package/dist/casing.js +0 -51
- package/dist/casing.js.map +0 -1
- package/dist/colors.d.ts.map +0 -1
- package/dist/colors.js +0 -467
- package/dist/colors.js.map +0 -1
- package/dist/hash.d.ts.map +0 -1
- package/dist/hash.js +0 -19
- package/dist/hash.js.map +0 -1
- package/dist/images.d.ts +0 -68
- package/dist/images.d.ts.map +0 -1
- package/dist/images.js +0 -66
- package/dist/images.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -130
- package/dist/logger.js.map +0 -1
- package/dist/oauth2.d.ts.map +0 -1
- package/dist/oauth2.js +0 -16
- package/dist/oauth2.js.map +0 -1
- package/dist/permissions.d.ts.map +0 -1
- package/dist/permissions.js +0 -17
- package/dist/permissions.js.map +0 -1
- package/dist/reactions.d.ts.map +0 -1
- package/dist/reactions.js +0 -11
- package/dist/reactions.js.map +0 -1
- package/dist/token.d.ts.map +0 -1
- package/dist/token.js +0 -21
- package/dist/token.js.map +0 -1
- package/dist/typeguards.d.ts.map +0 -1
- package/dist/typeguards.js +0 -18
- package/dist/typeguards.js.map +0 -1
- package/dist/urlToBase64.d.ts.map +0 -1
- package/dist/urlToBase64.js +0 -9
- package/dist/urlToBase64.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -15
- package/dist/utils.js.map +0 -1
- /package/dist/{base64.d.ts → types/base64.d.ts} +0 -0
- /package/dist/{builders.d.ts → types/builders.d.ts} +0 -0
- /package/dist/{casing.d.ts → types/casing.d.ts} +0 -0
- /package/dist/{colors.d.ts → types/colors.d.ts} +0 -0
- /package/dist/{hash.d.ts → types/hash.d.ts} +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{permissions.d.ts → types/permissions.d.ts} +0 -0
- /package/dist/{reactions.d.ts → types/reactions.d.ts} +0 -0
- /package/dist/{token.d.ts → types/token.d.ts} +0 -0
- /package/dist/{typeguards.d.ts → types/typeguards.d.ts} +0 -0
- /package/dist/{urlToBase64.d.ts → types/urlToBase64.d.ts} +0 -0
- /package/dist/{utils.d.ts → types/utils.d.ts} +0 -0
package/dist/builders/embeds.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A builder to help create Discord embeds.
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @class EmbedsBuilder
|
|
6
|
-
* @typedef {EmbedsBuilder}
|
|
7
|
-
* @extends {Array<DiscordEmbed>}
|
|
8
|
-
* @example
|
|
9
|
-
* const embeds = new EmbedBuilder()
|
|
10
|
-
* .setTitle('My Embed')
|
|
11
|
-
* .setDescription('This is my new embed')
|
|
12
|
-
* .newEmbed()
|
|
13
|
-
* .setTitle('My Second Embed')
|
|
14
|
-
*/ export class EmbedsBuilder extends Array {
|
|
15
|
-
#currentEmbedIndex;
|
|
16
|
-
/**
|
|
17
|
-
* Adds a new field to the embed fields array.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} name - Field name
|
|
20
|
-
* @param {string} value - Field value
|
|
21
|
-
* @param {?boolean} [inline=false] - Field should be inline or not.
|
|
22
|
-
* @returns {EmbedsBuilder}
|
|
23
|
-
*/ addField(name, value, inline) {
|
|
24
|
-
if (this.#currentEmbed.fields === undefined) {
|
|
25
|
-
this.#currentEmbed.fields = [];
|
|
26
|
-
}
|
|
27
|
-
this.#currentEmbed.fields.push({
|
|
28
|
-
name,
|
|
29
|
-
value,
|
|
30
|
-
inline
|
|
31
|
-
});
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a blank embed.
|
|
36
|
-
*
|
|
37
|
-
* @returns {EmbedsBuilder}
|
|
38
|
-
*/ newEmbed() {
|
|
39
|
-
if (this.length >= 10) {
|
|
40
|
-
throw new Error('Maximum embed count exceeded. You can not have more than 10 embeds.');
|
|
41
|
-
}
|
|
42
|
-
this.push({});
|
|
43
|
-
this.setCurrentEmbed();
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Set the current embed author.
|
|
48
|
-
*
|
|
49
|
-
* @param {string} name - Name of the author
|
|
50
|
-
* @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options
|
|
51
|
-
* @returns {EmbedsBuilder}
|
|
52
|
-
*/ setAuthor(name, options) {
|
|
53
|
-
this.#currentEmbed.author = {
|
|
54
|
-
...this.#currentEmbed.author,
|
|
55
|
-
...options,
|
|
56
|
-
name
|
|
57
|
-
};
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Set the color on the side of the current embed.
|
|
62
|
-
*
|
|
63
|
-
* @param {(number | string)} color - The color, in base16 or hex color code
|
|
64
|
-
* @returns {EmbedsBuilder}
|
|
65
|
-
*/ setColor(color) {
|
|
66
|
-
if (typeof color === 'string') {
|
|
67
|
-
const convertedValue = parseInt(color.replace('#', ''), 16);
|
|
68
|
-
color = Number.isNaN(convertedValue) ? 0 : convertedValue;
|
|
69
|
-
}
|
|
70
|
-
this.#currentEmbed.color = color;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Set the current embed to a different index.
|
|
75
|
-
*
|
|
76
|
-
* WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.
|
|
77
|
-
*
|
|
78
|
-
* @param {?number} [index] - The index of the embed in the EmbedsBuilder array
|
|
79
|
-
* @returns {EmbedsBuilder}
|
|
80
|
-
*/ setCurrentEmbed(index) {
|
|
81
|
-
if (index === undefined) {
|
|
82
|
-
this.#currentEmbedIndex = this.length - 1;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
if (index >= this.length || index < 0) {
|
|
86
|
-
throw new Error('Can not set the current embed to a index out of bounds.');
|
|
87
|
-
}
|
|
88
|
-
this.#currentEmbedIndex = index;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Set the description of the current embed.
|
|
93
|
-
*
|
|
94
|
-
* @param {string} description - Description
|
|
95
|
-
* @returns {EmbedsBuilder}
|
|
96
|
-
*/ setDescription(description) {
|
|
97
|
-
this.#currentEmbed.description = description;
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Overwrite all fields on the current embed.
|
|
102
|
-
*
|
|
103
|
-
* @param {DiscordEmbedField[]} fields
|
|
104
|
-
* @returns {EmbedsBuilder}
|
|
105
|
-
*/ setFields(fields) {
|
|
106
|
-
this.#currentEmbed.fields = fields;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Set the footer in the current embed.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} text - The text to display in the footer
|
|
113
|
-
* @param {?Omit<DiscordEmbedFooter, 'text'>} [options]
|
|
114
|
-
* @returns {EmbedsBuilder}
|
|
115
|
-
*/ setFooter(text, options) {
|
|
116
|
-
this.#currentEmbed.footer = {
|
|
117
|
-
...this.#currentEmbed.footer,
|
|
118
|
-
...options,
|
|
119
|
-
text
|
|
120
|
-
};
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Set the image in the current embed.
|
|
125
|
-
*
|
|
126
|
-
* @param {string} url - URL of the image
|
|
127
|
-
* @param {?Omit<DiscordEmbedImage, 'url'>} [options]
|
|
128
|
-
* @returns {EmbedsBuilder}
|
|
129
|
-
*/ setImage(url, options) {
|
|
130
|
-
this.#currentEmbed.image = {
|
|
131
|
-
...this.#currentEmbed.image,
|
|
132
|
-
...options,
|
|
133
|
-
url
|
|
134
|
-
};
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Set the provider of the current embed.
|
|
139
|
-
*
|
|
140
|
-
* @param {string} name
|
|
141
|
-
* @param {?string} [url]
|
|
142
|
-
* @returns {EmbedsBuilder}
|
|
143
|
-
*/ setProvider(name, url) {
|
|
144
|
-
this.#currentEmbed.provider = {
|
|
145
|
-
name,
|
|
146
|
-
url
|
|
147
|
-
};
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Set the color of the current embed to a random value.
|
|
152
|
-
*
|
|
153
|
-
* @returns {EmbedsBuilder}
|
|
154
|
-
*/ setRandomColor() {
|
|
155
|
-
return this.setColor(Math.floor(Math.random() * (0xffffff + 1)));
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Set the title of the current embed.
|
|
159
|
-
*
|
|
160
|
-
* @param {string} title
|
|
161
|
-
* @param {?string} [url]
|
|
162
|
-
* @returns {EmbedsBuilder}
|
|
163
|
-
*/ setTitle(title, url) {
|
|
164
|
-
this.#currentEmbed.title = title;
|
|
165
|
-
if (url) {
|
|
166
|
-
this.setUrl(url);
|
|
167
|
-
}
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Set the timestamp of the current embed.
|
|
172
|
-
*
|
|
173
|
-
* @param {?(string | number | Date)} [timestamp]
|
|
174
|
-
* @returns {EmbedsBuilder}
|
|
175
|
-
*/ setTimestamp(timestamp) {
|
|
176
|
-
this.#currentEmbed.timestamp = new Date(timestamp).toISOString();
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Set the thumbnail of the current embed.
|
|
181
|
-
*
|
|
182
|
-
* @param {string} url - URL of the image
|
|
183
|
-
* @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]
|
|
184
|
-
* @returns {EmbedsBuilder}
|
|
185
|
-
*/ setThumbnail(url, options) {
|
|
186
|
-
this.#currentEmbed.thumbnail = {
|
|
187
|
-
...this.#currentEmbed.thumbnail,
|
|
188
|
-
...options,
|
|
189
|
-
url
|
|
190
|
-
};
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Set the URL of the current embed title.
|
|
195
|
-
*
|
|
196
|
-
* @param {string} url
|
|
197
|
-
* @returns {EmbedsBuilder}
|
|
198
|
-
*/ setUrl(url) {
|
|
199
|
-
this.#currentEmbed.url = url;
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Set the video of the current embed.
|
|
204
|
-
*
|
|
205
|
-
* @param {string} url
|
|
206
|
-
* @param {?Omit<DiscordEmbedVideo, 'url'>} [options]
|
|
207
|
-
* @returns {EmbedsBuilder}
|
|
208
|
-
*/ setVideo(url, options) {
|
|
209
|
-
this.#currentEmbed.video = {
|
|
210
|
-
...this.#currentEmbed.video,
|
|
211
|
-
...options,
|
|
212
|
-
url
|
|
213
|
-
};
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Validate all embeds available against current known Discord limits to help prevent bad requests.
|
|
218
|
-
*
|
|
219
|
-
* @returns {EmbedsBuilder}
|
|
220
|
-
*/ validate() {
|
|
221
|
-
let totalCharacters = 0;
|
|
222
|
-
if (this.length > 10) {
|
|
223
|
-
throw new Error('You can not have more than 10 embeds on a single message.');
|
|
224
|
-
}
|
|
225
|
-
this.forEach(({ author , description , fields , footer , title }, index)=>{
|
|
226
|
-
if (title) {
|
|
227
|
-
const trimmedTitle = title.trim();
|
|
228
|
-
if (trimmedTitle.length > 256) {
|
|
229
|
-
throw new Error(`Title of embed ${index} can not be longer than 256 characters.`);
|
|
230
|
-
}
|
|
231
|
-
totalCharacters += trimmedTitle.length;
|
|
232
|
-
}
|
|
233
|
-
if (description) {
|
|
234
|
-
const trimmedDescription = description.trim();
|
|
235
|
-
if (trimmedDescription.length > 4096) {
|
|
236
|
-
throw new Error(`Description of embed ${index} can not be longer than 4096 characters.`);
|
|
237
|
-
}
|
|
238
|
-
totalCharacters += trimmedDescription.length;
|
|
239
|
-
}
|
|
240
|
-
if (fields) {
|
|
241
|
-
if (fields.length > 25) {
|
|
242
|
-
throw new Error(`embed ${index} can not have more than 25 fields.`);
|
|
243
|
-
}
|
|
244
|
-
fields.forEach(({ name , value }, fieldIndex)=>{
|
|
245
|
-
const trimmedName = name.trim();
|
|
246
|
-
const trimmedValue = value.trim();
|
|
247
|
-
if (trimmedName.length > 256) {
|
|
248
|
-
throw new Error(`Name of field ${fieldIndex} on embed ${index} can not be longer than 256 characters.`);
|
|
249
|
-
}
|
|
250
|
-
if (trimmedValue.length > 4096) {
|
|
251
|
-
throw new Error(`Value of field ${fieldIndex} on embed ${index} can not be longer than 1024 characters.`);
|
|
252
|
-
}
|
|
253
|
-
totalCharacters += trimmedName.length;
|
|
254
|
-
totalCharacters += trimmedValue.length;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (footer) {
|
|
258
|
-
const trimmedFooterText = footer.text.trim();
|
|
259
|
-
if (trimmedFooterText.length > 2048) {
|
|
260
|
-
throw new Error(`Footer text of embed ${index} can not be longer than 2048 characters.`);
|
|
261
|
-
}
|
|
262
|
-
totalCharacters += trimmedFooterText.length;
|
|
263
|
-
}
|
|
264
|
-
if (author) {
|
|
265
|
-
const trimmedAuthorName = author.name.trim();
|
|
266
|
-
if (trimmedAuthorName.length > 256) {
|
|
267
|
-
throw new Error(`Author name of embed ${index} can not be longer than 256 characters.`);
|
|
268
|
-
}
|
|
269
|
-
totalCharacters += trimmedAuthorName.length;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
if (totalCharacters > 6000) {
|
|
273
|
-
throw new Error('Total character length of all embeds can not exceed 6000 characters.');
|
|
274
|
-
}
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Returns the current embed.
|
|
279
|
-
*
|
|
280
|
-
* @readonly
|
|
281
|
-
* @type {DiscordEmbed}
|
|
282
|
-
*/ get #currentEmbed() {
|
|
283
|
-
if (this.length === 0) {
|
|
284
|
-
this.newEmbed();
|
|
285
|
-
this.setCurrentEmbed();
|
|
286
|
-
}
|
|
287
|
-
return this[this.#currentEmbedIndex];
|
|
288
|
-
}
|
|
289
|
-
constructor(...args){
|
|
290
|
-
super(...args);
|
|
291
|
-
this.#currentEmbedIndex = 0;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
//# sourceMappingURL=embeds.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/builders/embeds.ts"],"sourcesContent":["import type {\n DiscordEmbed,\n DiscordEmbedAuthor,\n DiscordEmbedField,\n DiscordEmbedFooter,\n DiscordEmbedImage,\n DiscordEmbedThumbnail,\n DiscordEmbedVideo,\n} from '@discordeno/types'\n\n/**\n * A builder to help create Discord embeds.\n *\n * @export\n * @class EmbedsBuilder\n * @typedef {EmbedsBuilder}\n * @extends {Array<DiscordEmbed>}\n * @example\n * const embeds = new EmbedBuilder()\n * .setTitle('My Embed')\n * .setDescription('This is my new embed')\n * .newEmbed()\n * .setTitle('My Second Embed')\n */\nexport class EmbedsBuilder extends Array<DiscordEmbed> {\n #currentEmbedIndex: number = 0\n\n /**\n * Adds a new field to the embed fields array.\n *\n * @param {string} name - Field name\n * @param {string} value - Field value\n * @param {?boolean} [inline=false] - Field should be inline or not.\n * @returns {EmbedsBuilder}\n */\n addField(name: string, value: string, inline?: boolean): EmbedsBuilder {\n if (this.#currentEmbed.fields === undefined) {\n this.#currentEmbed.fields = []\n }\n\n this.#currentEmbed.fields.push({\n name,\n value,\n inline,\n })\n\n return this\n }\n\n /**\n * Creates a blank embed.\n *\n * @returns {EmbedsBuilder}\n */\n newEmbed(): EmbedsBuilder {\n if (this.length >= 10) {\n throw new Error('Maximum embed count exceeded. You can not have more than 10 embeds.')\n }\n\n this.push({})\n this.setCurrentEmbed()\n\n return this\n }\n\n /**\n * Set the current embed author.\n *\n * @param {string} name - Name of the author\n * @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options\n * @returns {EmbedsBuilder}\n */\n setAuthor(name: string, options?: Omit<DiscordEmbedAuthor, 'name'>): EmbedsBuilder {\n this.#currentEmbed.author = {\n ...this.#currentEmbed.author,\n ...options,\n name,\n }\n\n return this\n }\n\n /**\n * Set the color on the side of the current embed.\n *\n * @param {(number | string)} color - The color, in base16 or hex color code\n * @returns {EmbedsBuilder}\n */\n setColor(color: number | string): EmbedsBuilder {\n if (typeof color === 'string') {\n const convertedValue = parseInt(color.replace('#', ''), 16)\n color = Number.isNaN(convertedValue) ? 0 : convertedValue\n }\n\n this.#currentEmbed.color = color\n\n return this\n }\n\n /**\n * Set the current embed to a different index.\n *\n * WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.\n *\n * @param {?number} [index] - The index of the embed in the EmbedsBuilder array\n * @returns {EmbedsBuilder}\n */\n setCurrentEmbed(index?: number): EmbedsBuilder {\n if (index === undefined) {\n this.#currentEmbedIndex = this.length - 1\n\n return this\n }\n\n if (index >= this.length || index < 0) {\n throw new Error('Can not set the current embed to a index out of bounds.')\n }\n\n this.#currentEmbedIndex = index\n\n return this\n }\n\n /**\n * Set the description of the current embed.\n *\n * @param {string} description - Description\n * @returns {EmbedsBuilder}\n */\n setDescription(description: string): EmbedsBuilder {\n this.#currentEmbed.description = description\n\n return this\n }\n\n /**\n * Overwrite all fields on the current embed.\n *\n * @param {DiscordEmbedField[]} fields\n * @returns {EmbedsBuilder}\n */\n setFields(fields: DiscordEmbedField[]): EmbedsBuilder {\n this.#currentEmbed.fields = fields\n\n return this\n }\n\n /**\n * Set the footer in the current embed.\n *\n * @param {string} text - The text to display in the footer\n * @param {?Omit<DiscordEmbedFooter, 'text'>} [options]\n * @returns {EmbedsBuilder}\n */\n setFooter(text: string, options?: Omit<DiscordEmbedFooter, 'text'>): EmbedsBuilder {\n this.#currentEmbed.footer = {\n ...this.#currentEmbed.footer,\n ...options,\n text,\n }\n\n return this\n }\n\n /**\n * Set the image in the current embed.\n *\n * @param {string} url - URL of the image\n * @param {?Omit<DiscordEmbedImage, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setImage(url: string, options?: Omit<DiscordEmbedImage, 'url'>): EmbedsBuilder {\n this.#currentEmbed.image = {\n ...this.#currentEmbed.image,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Set the provider of the current embed.\n *\n * @param {string} name\n * @param {?string} [url]\n * @returns {EmbedsBuilder}\n */\n setProvider(name: string, url?: string): EmbedsBuilder {\n this.#currentEmbed.provider = {\n name,\n url,\n }\n\n return this\n }\n\n /**\n * Set the color of the current embed to a random value.\n *\n * @returns {EmbedsBuilder}\n */\n setRandomColor(): EmbedsBuilder {\n return this.setColor(Math.floor(Math.random() * (0xffffff + 1)))\n }\n\n /**\n * Set the title of the current embed.\n *\n * @param {string} title\n * @param {?string} [url]\n * @returns {EmbedsBuilder}\n */\n setTitle(title: string, url?: string): EmbedsBuilder {\n this.#currentEmbed.title = title\n\n if (url) {\n this.setUrl(url)\n }\n\n return this\n }\n\n /**\n * Set the timestamp of the current embed.\n *\n * @param {?(string | number | Date)} [timestamp]\n * @returns {EmbedsBuilder}\n */\n setTimestamp(timestamp?: string | number | Date): EmbedsBuilder {\n this.#currentEmbed.timestamp = new Date(timestamp!).toISOString()\n\n return this\n }\n\n /**\n * Set the thumbnail of the current embed.\n *\n * @param {string} url - URL of the image\n * @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setThumbnail(url: string, options?: Omit<DiscordEmbedThumbnail, 'url'>): EmbedsBuilder {\n this.#currentEmbed.thumbnail = {\n ...this.#currentEmbed.thumbnail,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Set the URL of the current embed title.\n *\n * @param {string} url\n * @returns {EmbedsBuilder}\n */\n setUrl(url: string): EmbedsBuilder {\n this.#currentEmbed.url = url\n\n return this\n }\n\n /**\n * Set the video of the current embed.\n *\n * @param {string} url\n * @param {?Omit<DiscordEmbedVideo, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setVideo(url: string, options?: Omit<DiscordEmbedVideo, 'url'>): EmbedsBuilder {\n this.#currentEmbed.video = {\n ...this.#currentEmbed.video,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Validate all embeds available against current known Discord limits to help prevent bad requests.\n *\n * @returns {EmbedsBuilder}\n */\n validate(): EmbedsBuilder {\n let totalCharacters = 0\n\n if (this.length > 10) {\n throw new Error('You can not have more than 10 embeds on a single message.')\n }\n\n this.forEach(({ author, description, fields, footer, title }, index) => {\n if (title) {\n const trimmedTitle = title.trim()\n\n if (trimmedTitle.length > 256) {\n throw new Error(`Title of embed ${index} can not be longer than 256 characters.`)\n }\n\n totalCharacters += trimmedTitle.length\n }\n\n if (description) {\n const trimmedDescription = description.trim()\n\n if (trimmedDescription.length > 4096) {\n throw new Error(`Description of embed ${index} can not be longer than 4096 characters.`)\n }\n\n totalCharacters += trimmedDescription.length\n }\n\n if (fields) {\n if (fields.length > 25) {\n throw new Error(`embed ${index} can not have more than 25 fields.`)\n }\n\n fields.forEach(({ name, value }, fieldIndex) => {\n const trimmedName = name.trim()\n const trimmedValue = value.trim()\n\n if (trimmedName.length > 256) {\n throw new Error(`Name of field ${fieldIndex} on embed ${index} can not be longer than 256 characters.`)\n }\n\n if (trimmedValue.length > 4096) {\n throw new Error(`Value of field ${fieldIndex} on embed ${index} can not be longer than 1024 characters.`)\n }\n\n totalCharacters += trimmedName.length\n totalCharacters += trimmedValue.length\n })\n }\n\n if (footer) {\n const trimmedFooterText = footer.text.trim()\n\n if (trimmedFooterText.length > 2048) {\n throw new Error(`Footer text of embed ${index} can not be longer than 2048 characters.`)\n }\n\n totalCharacters += trimmedFooterText.length\n }\n\n if (author) {\n const trimmedAuthorName = author.name.trim()\n\n if (trimmedAuthorName.length > 256) {\n throw new Error(`Author name of embed ${index} can not be longer than 256 characters.`)\n }\n\n totalCharacters += trimmedAuthorName.length\n }\n })\n\n if (totalCharacters > 6000) {\n throw new Error('Total character length of all embeds can not exceed 6000 characters.')\n }\n\n return this\n }\n\n /**\n * Returns the current embed.\n *\n * @readonly\n * @type {DiscordEmbed}\n */\n get #currentEmbed(): DiscordEmbed {\n if (this.length === 0) {\n this.newEmbed()\n this.setCurrentEmbed()\n }\n\n return this[this.#currentEmbedIndex]\n }\n}\n"],"names":["EmbedsBuilder","Array","currentEmbedIndex","addField","name","value","inline","currentEmbed","fields","undefined","push","newEmbed","length","Error","setCurrentEmbed","setAuthor","options","author","setColor","color","convertedValue","parseInt","replace","Number","isNaN","index","setDescription","description","setFields","setFooter","text","footer","setImage","url","image","setProvider","provider","setRandomColor","Math","floor","random","setTitle","title","setUrl","setTimestamp","timestamp","Date","toISOString","setThumbnail","thumbnail","setVideo","video","validate","totalCharacters","forEach","trimmedTitle","trim","trimmedDescription","fieldIndex","trimmedName","trimmedValue","trimmedFooterText","trimmedAuthorName"],"mappings":"AAUA;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMA,sBAAsBC;IACjC,CAACC,iBAAiB,CAAY;IAE9B;;;;;;;GAOC,GACDC,SAASC,IAAY,EAAEC,KAAa,EAAEC,MAAgB,EAAiB;QACrE,IAAI,IAAI,CAAC,CAACC,YAAY,CAACC,MAAM,KAAKC,WAAW;YAC3C,IAAI,CAAC,CAACF,YAAY,CAACC,MAAM,GAAG,EAAE;QAChC,CAAC;QAED,IAAI,CAAC,CAACD,YAAY,CAACC,MAAM,CAACE,IAAI,CAAC;YAC7BN;YACAC;YACAC;QACF;QAEA,OAAO,IAAI;IACb;IAEA;;;;GAIC,GACDK,WAA0B;QACxB,IAAI,IAAI,CAACC,MAAM,IAAI,IAAI;YACrB,MAAM,IAAIC,MAAM,uEAAsE;QACxF,CAAC;QAED,IAAI,CAACH,IAAI,CAAC,CAAC;QACX,IAAI,CAACI,eAAe;QAEpB,OAAO,IAAI;IACb;IAEA;;;;;;GAMC,GACDC,UAAUX,IAAY,EAAEY,OAA0C,EAAiB;QACjF,IAAI,CAAC,CAACT,YAAY,CAACU,MAAM,GAAG;YAC1B,GAAG,IAAI,CAAC,CAACV,YAAY,CAACU,MAAM;YAC5B,GAAGD,OAAO;YACVZ;QACF;QAEA,OAAO,IAAI;IACb;IAEA;;;;;GAKC,GACDc,SAASC,KAAsB,EAAiB;QAC9C,IAAI,OAAOA,UAAU,UAAU;YAC7B,MAAMC,iBAAiBC,SAASF,MAAMG,OAAO,CAAC,KAAK,KAAK;YACxDH,QAAQI,OAAOC,KA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CyC,mBAAmBO,aAAahD,MAAM;gBACxC;YACF,CAAC;YAED,IAAImB,QAAQ;gBACV,MAAM8B,oBAAoB9B,OAAOD,IAAI,CAAC0B,IAAI;gBAE1C,IAAIK,kBAAkBjD,MAAM,GAAG,MAAM;oBACnC,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAEY,MAAM,wCAAwC,CAAC,EAAC;gBAC1F,CAAC;gBAED4B,mBAAmBQ,kBAAkBjD,MAAM;YAC7C,CAAC;YAED,IAAIK,QAAQ;gBACV,MAAM6C,oBAAoB7C,OAAOb,IAAI,CAACoD,IAAI;gBAE1C,IAAIM,kBAAkBlD,MAAM,GAAG,KAAK;oBAClC,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAEY,MAAM,uCAAuC,CAAC,EAAC;gBACzF,CAAC;gBAED4B,mBAAmBS,kBAAkBlD,MAAM;YAC7C,CAAC;QACH;QAEA,IAAIyC,kBAAkB,MAAM;YAC1B,MAAM,IAAIxC,MAAM,wEAAuE;QACzF,CAAC;QAED,OAAO,IAAI;IACb;IAEA;;;;;GAKC,GACD,IAAI,CAACN,YAAY,GAAiB;QAChC,IAAI,IAAI,CAACK,MAAM,KAAK,GAAG;YACrB,IAAI,CAACD,QAAQ;YACb,IAAI,CAACG,eAAe;QACtB,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAACZ,iBAAiB,CAAC;IACtC;;;aAhWA,CAACA,iBAAiB,GAAW;;AAiW/B,CAAC"}
|
package/dist/builders.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,cAAc,sBAAsB,CAAA;AAEpC,eAAO,MAAM,YAAY,QAAO,aAAoC,CAAA"}
|
package/dist/builders.js
DELETED
package/dist/builders.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/builders.ts"],"sourcesContent":["import { EmbedsBuilder } from './builders/embeds.js'\n\nexport * from './builders/embeds.js'\n\nexport const createEmbeds = (): EmbedsBuilder => new EmbedsBuilder()\n"],"names":["EmbedsBuilder","createEmbeds"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAsB;AAEpD,cAAc,uBAAsB;AAEpC,OAAO,MAAMC,eAAe,IAAqB,IAAID,gBAAe"}
|
package/dist/casing.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../src/casing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE5D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAclD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAcpD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAepD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAapD"}
|
package/dist/casing.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export function camelize(object) {
|
|
2
|
-
if (Array.isArray(object)) {
|
|
3
|
-
return object.map((element)=>camelize(element));
|
|
4
|
-
}
|
|
5
|
-
if (typeof object === 'object' && object !== null) {
|
|
6
|
-
const obj = {};
|
|
7
|
-
Object.keys(object).forEach((key)=>{
|
|
8
|
-
obj[snakeToCamelCase(key)] = camelize(object[key]);
|
|
9
|
-
});
|
|
10
|
-
return obj;
|
|
11
|
-
}
|
|
12
|
-
return object;
|
|
13
|
-
}
|
|
14
|
-
export function snakelize(object) {
|
|
15
|
-
if (Array.isArray(object)) {
|
|
16
|
-
return object.map((element)=>snakelize(element));
|
|
17
|
-
}
|
|
18
|
-
if (typeof object === 'object' && object !== null) {
|
|
19
|
-
const obj = {};
|
|
20
|
-
Object.keys(object).forEach((key)=>{
|
|
21
|
-
obj[camelToSnakeCase(key)] = snakelize(object[key]);
|
|
22
|
-
});
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
return object;
|
|
26
|
-
}
|
|
27
|
-
export function snakeToCamelCase(str) {
|
|
28
|
-
if (!str.includes('_')) return str;
|
|
29
|
-
let result = '';
|
|
30
|
-
for(let i = 0, len = str.length; i < len; ++i){
|
|
31
|
-
if (str[i] === '_') {
|
|
32
|
-
result += str[++i].toUpperCase();
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
result += str[i];
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
export function camelToSnakeCase(str) {
|
|
40
|
-
let result = '';
|
|
41
|
-
for(let i = 0, len = str.length; i < len; ++i){
|
|
42
|
-
if (str[i] >= 'A' && str[i] <= 'Z') {
|
|
43
|
-
result += `_${str[i].toLowerCase()}`;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
result += str[i];
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=casing.js.map
|
package/dist/casing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Camelize, Snakelize } from '@discordeno/types'\n\nexport function camelize<T>(object: T): Camelize<T> {\n if (Array.isArray(object)) {\n return object.map((element) => camelize(element)) as Camelize<T>\n }\n\n if (typeof object === 'object' && object !== null) {\n const obj = {} as Camelize<T>\n ;(Object.keys(object) as Array<keyof T>).forEach((key) => {\n // @ts-expect-error js hack\n ;(obj[snakeToCamelCase(key)] as Camelize<(T & object)[keyof T]>) = camelize(object[key])\n })\n return obj\n }\n return object as Camelize<T>\n}\n\nexport function snakelize<T>(object: T): Snakelize<T> {\n if (Array.isArray(object)) {\n return object.map((element) => snakelize(element)) as Snakelize<T>\n }\n\n if (typeof object === 'object' && object !== null) {\n const obj = {} as Snakelize<T>\n ;(Object.keys(object) as Array<keyof T>).forEach((key) => {\n // @ts-expect-error js hack\n ;(obj[camelToSnakeCase(key)] as Snakelize<(T & object)[keyof T]>) = snakelize(object[key])\n })\n return obj\n }\n return object as Snakelize<T>\n}\n\nexport function snakeToCamelCase(str: string): string {\n if (!str.includes('_')) return str\n\n let result = ''\n for (let i = 0, len = str.length; i < len; ++i) {\n if (str[i] === '_') {\n result += str[++i].toUpperCase()\n\n continue\n }\n\n result += str[i]\n }\n\n return result\n}\n\nexport function camelToSnakeCase(str: string): string {\n let result = ''\n for (let i = 0, len = str.length; i < len; ++i) {\n if (str[i] >= 'A' && str[i] <= 'Z') {\n result += `_${str[i].toLowerCase()}`\n\n continue\n }\n\n result += str[i]\n }\n\n return result\n}\n"],"names":["camelize","object","Array","isArray","map","element","obj","Object","keys","forEach","key","snakeToCamelCase","snakelize","camelToSnakeCase","str","includes","result","i","len","length","toUpperCase","toLowerCase"],"mappings":"AAEA,OAAO,SAASA,SAAYC,MAAS,EAAe;IAClD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYL,SAASK;IAC1C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAEtDJ,GAAG,CAACK,iBAAiBD,KAAK,GAAuCV,SAASC,MAAM,CAACS,IAAI;QACzF;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASW,UAAaX,MAAS,EAAgB;IACpD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYO,UAAUP;IAC3C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