@discordeno/utils 19.0.0-next.fe00a6f → 19.0.0
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/esm/Collection.js +112 -0
- package/dist/esm/base64.js +262 -0
- package/dist/esm/bucket.js +81 -0
- package/dist/esm/builders/embeds.js +290 -0
- package/dist/esm/builders.js +5 -0
- package/dist/esm/casing.js +55 -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 +20 -0
- package/dist/esm/typeguards.js +22 -0
- package/dist/esm/urlToBase64.js +9 -0
- package/dist/esm/urls.js +11 -0
- package/dist/esm/utils.js +12 -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/types/builders/embeds.d.ts +142 -0
- package/dist/types/builders/embeds.d.ts.map +1 -0
- package/dist/types/builders.d.ts +4 -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} +4 -1
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/oauth2.d.ts +69 -0
- 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/{token.d.ts → types/token.d.ts} +1 -1
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/typeguards.d.ts +8 -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 +5 -0
- package/dist/types/urls.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +30 -26
- 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 -74
- package/dist/bucket.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 -16
- package/dist/index.js.map +0 -1
- package/dist/interactions.d.ts +0 -3
- package/dist/interactions.d.ts.map +0 -1
- package/dist/interactions.js +0 -41
- package/dist/interactions.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/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 -16
- package/dist/token.js.map +0 -1
- package/dist/typeguards.d.ts +0 -6
- package/dist/typeguards.d.ts.map +0 -1
- package/dist/typeguards.js +0 -15
- 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/{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/{urlToBase64.d.ts → types/urlToBase64.d.ts} +0 -0
- /package/dist/{utils.d.ts → types/utils.d.ts} +0 -0
package/dist/colors.js
DELETED
|
@@ -1,467 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
|
|
3
|
-
// on npm.
|
|
4
|
-
// https://deno.land/std@0.153.0/fmt/colors.ts?source
|
|
5
|
-
let enabled = true;
|
|
6
|
-
/**
|
|
7
|
-
* Set changing text color to enabled or disabled
|
|
8
|
-
* @param value
|
|
9
|
-
*/ export function setColorEnabled(value) {
|
|
10
|
-
enabled = value;
|
|
11
|
-
}
|
|
12
|
-
/** Get whether text color change is enabled or disabled. */ export function getColorEnabled() {
|
|
13
|
-
return enabled;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Builds color code
|
|
17
|
-
* @param open
|
|
18
|
-
* @param close
|
|
19
|
-
*/ function code(open, close) {
|
|
20
|
-
return {
|
|
21
|
-
open: `\x1b[${open.join(';')}m`,
|
|
22
|
-
close: `\x1b[${close}m`,
|
|
23
|
-
regexp: new RegExp(`\\x1b\\[${close}m`, 'g')
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Applies color and background based on color code and its associated text
|
|
28
|
-
* @param str text to apply color settings to
|
|
29
|
-
* @param code color code to apply
|
|
30
|
-
*/ function run(str, code) {
|
|
31
|
-
return enabled ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}` : str;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Reset the text modified
|
|
35
|
-
* @param str text to reset
|
|
36
|
-
*/ export function reset(str) {
|
|
37
|
-
return run(str, code([
|
|
38
|
-
0
|
|
39
|
-
], 0));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Make the text bold.
|
|
43
|
-
* @param str text to make bold
|
|
44
|
-
*/ export function bold(str) {
|
|
45
|
-
return run(str, code([
|
|
46
|
-
1
|
|
47
|
-
], 22));
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The text emits only a small amount of light.
|
|
51
|
-
* @param str text to dim
|
|
52
|
-
*/ export function dim(str) {
|
|
53
|
-
return run(str, code([
|
|
54
|
-
2
|
|
55
|
-
], 22));
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Make the text italic.
|
|
59
|
-
* @param str text to make italic
|
|
60
|
-
*/ export function italic(str) {
|
|
61
|
-
return run(str, code([
|
|
62
|
-
3
|
|
63
|
-
], 23));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Make the text underline.
|
|
67
|
-
* @param str text to underline
|
|
68
|
-
*/ export function underline(str) {
|
|
69
|
-
return run(str, code([
|
|
70
|
-
4
|
|
71
|
-
], 24));
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Invert background color and text color.
|
|
75
|
-
* @param str text to invert its color
|
|
76
|
-
*/ export function inverse(str) {
|
|
77
|
-
return run(str, code([
|
|
78
|
-
7
|
|
79
|
-
], 27));
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Make the text hidden.
|
|
83
|
-
* @param str text to hide
|
|
84
|
-
*/ export function hidden(str) {
|
|
85
|
-
return run(str, code([
|
|
86
|
-
8
|
|
87
|
-
], 28));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Put horizontal line through the center of the text.
|
|
91
|
-
* @param str text to strike through
|
|
92
|
-
*/ export function strikethrough(str) {
|
|
93
|
-
return run(str, code([
|
|
94
|
-
9
|
|
95
|
-
], 29));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Set text color to black.
|
|
99
|
-
* @param str text to make black
|
|
100
|
-
*/ export function black(str) {
|
|
101
|
-
return run(str, code([
|
|
102
|
-
30
|
|
103
|
-
], 39));
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Set text color to red.
|
|
107
|
-
* @param str text to make red
|
|
108
|
-
*/ export function red(str) {
|
|
109
|
-
return run(str, code([
|
|
110
|
-
31
|
|
111
|
-
], 39));
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Set text color to green.
|
|
115
|
-
* @param str text to make green
|
|
116
|
-
*/ export function green(str) {
|
|
117
|
-
return run(str, code([
|
|
118
|
-
32
|
|
119
|
-
], 39));
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Set text color to yellow.
|
|
123
|
-
* @param str text to make yellow
|
|
124
|
-
*/ export function yellow(str) {
|
|
125
|
-
return run(str, code([
|
|
126
|
-
33
|
|
127
|
-
], 39));
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Set text color to blue.
|
|
131
|
-
* @param str text to make blue
|
|
132
|
-
*/ export function blue(str) {
|
|
133
|
-
return run(str, code([
|
|
134
|
-
34
|
|
135
|
-
], 39));
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Set text color to magenta.
|
|
139
|
-
* @param str text to make magenta
|
|
140
|
-
*/ export function magenta(str) {
|
|
141
|
-
return run(str, code([
|
|
142
|
-
35
|
|
143
|
-
], 39));
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Set text color to cyan.
|
|
147
|
-
* @param str text to make cyan
|
|
148
|
-
*/ export function cyan(str) {
|
|
149
|
-
return run(str, code([
|
|
150
|
-
36
|
|
151
|
-
], 39));
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Set text color to white.
|
|
155
|
-
* @param str text to make white
|
|
156
|
-
*/ export function white(str) {
|
|
157
|
-
return run(str, code([
|
|
158
|
-
37
|
|
159
|
-
], 39));
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Set text color to gray.
|
|
163
|
-
* @param str text to make gray
|
|
164
|
-
*/ export function gray(str) {
|
|
165
|
-
return brightBlack(str);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Set text color to bright black.
|
|
169
|
-
* @param str text to make bright-black
|
|
170
|
-
*/ export function brightBlack(str) {
|
|
171
|
-
return run(str, code([
|
|
172
|
-
90
|
|
173
|
-
], 39));
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Set text color to bright red.
|
|
177
|
-
* @param str text to make bright-red
|
|
178
|
-
*/ export function brightRed(str) {
|
|
179
|
-
return run(str, code([
|
|
180
|
-
91
|
|
181
|
-
], 39));
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Set text color to bright green.
|
|
185
|
-
* @param str text to make bright-green
|
|
186
|
-
*/ export function brightGreen(str) {
|
|
187
|
-
return run(str, code([
|
|
188
|
-
92
|
|
189
|
-
], 39));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Set text color to bright yellow.
|
|
193
|
-
* @param str text to make bright-yellow
|
|
194
|
-
*/ export function brightYellow(str) {
|
|
195
|
-
return run(str, code([
|
|
196
|
-
93
|
|
197
|
-
], 39));
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Set text color to bright blue.
|
|
201
|
-
* @param str text to make bright-blue
|
|
202
|
-
*/ export function brightBlue(str) {
|
|
203
|
-
return run(str, code([
|
|
204
|
-
94
|
|
205
|
-
], 39));
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Set text color to bright magenta.
|
|
209
|
-
* @param str text to make bright-magenta
|
|
210
|
-
*/ export function brightMagenta(str) {
|
|
211
|
-
return run(str, code([
|
|
212
|
-
95
|
|
213
|
-
], 39));
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Set text color to bright cyan.
|
|
217
|
-
* @param str text to make bright-cyan
|
|
218
|
-
*/ export function brightCyan(str) {
|
|
219
|
-
return run(str, code([
|
|
220
|
-
96
|
|
221
|
-
], 39));
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Set text color to bright white.
|
|
225
|
-
* @param str text to make bright-white
|
|
226
|
-
*/ export function brightWhite(str) {
|
|
227
|
-
return run(str, code([
|
|
228
|
-
97
|
|
229
|
-
], 39));
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Set background color to black.
|
|
233
|
-
* @param str text to make its background black
|
|
234
|
-
*/ export function bgBlack(str) {
|
|
235
|
-
return run(str, code([
|
|
236
|
-
40
|
|
237
|
-
], 49));
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Set background color to red.
|
|
241
|
-
* @param str text to make its background red
|
|
242
|
-
*/ export function bgRed(str) {
|
|
243
|
-
return run(str, code([
|
|
244
|
-
41
|
|
245
|
-
], 49));
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Set background color to green.
|
|
249
|
-
* @param str text to make its background green
|
|
250
|
-
*/ export function bgGreen(str) {
|
|
251
|
-
return run(str, code([
|
|
252
|
-
42
|
|
253
|
-
], 49));
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Set background color to yellow.
|
|
257
|
-
* @param str text to make its background yellow
|
|
258
|
-
*/ export function bgYellow(str) {
|
|
259
|
-
return run(str, code([
|
|
260
|
-
43
|
|
261
|
-
], 49));
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Set background color to blue.
|
|
265
|
-
* @param str text to make its background blue
|
|
266
|
-
*/ export function bgBlue(str) {
|
|
267
|
-
return run(str, code([
|
|
268
|
-
44
|
|
269
|
-
], 49));
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Set background color to magenta.
|
|
273
|
-
* @param str text to make its background magenta
|
|
274
|
-
*/ export function bgMagenta(str) {
|
|
275
|
-
return run(str, code([
|
|
276
|
-
45
|
|
277
|
-
], 49));
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Set background color to cyan.
|
|
281
|
-
* @param str text to make its background cyan
|
|
282
|
-
*/ export function bgCyan(str) {
|
|
283
|
-
return run(str, code([
|
|
284
|
-
46
|
|
285
|
-
], 49));
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Set background color to white.
|
|
289
|
-
* @param str text to make its background white
|
|
290
|
-
*/ export function bgWhite(str) {
|
|
291
|
-
return run(str, code([
|
|
292
|
-
47
|
|
293
|
-
], 49));
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Set background color to bright black.
|
|
297
|
-
* @param str text to make its background bright-black
|
|
298
|
-
*/ export function bgBrightBlack(str) {
|
|
299
|
-
return run(str, code([
|
|
300
|
-
100
|
|
301
|
-
], 49));
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Set background color to bright red.
|
|
305
|
-
* @param str text to make its background bright-red
|
|
306
|
-
*/ export function bgBrightRed(str) {
|
|
307
|
-
return run(str, code([
|
|
308
|
-
101
|
|
309
|
-
], 49));
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Set background color to bright green.
|
|
313
|
-
* @param str text to make its background bright-green
|
|
314
|
-
*/ export function bgBrightGreen(str) {
|
|
315
|
-
return run(str, code([
|
|
316
|
-
102
|
|
317
|
-
], 49));
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Set background color to bright yellow.
|
|
321
|
-
* @param str text to make its background bright-yellow
|
|
322
|
-
*/ export function bgBrightYellow(str) {
|
|
323
|
-
return run(str, code([
|
|
324
|
-
103
|
|
325
|
-
], 49));
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Set background color to bright blue.
|
|
329
|
-
* @param str text to make its background bright-blue
|
|
330
|
-
*/ export function bgBrightBlue(str) {
|
|
331
|
-
return run(str, code([
|
|
332
|
-
104
|
|
333
|
-
], 49));
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Set background color to bright magenta.
|
|
337
|
-
* @param str text to make its background bright-magenta
|
|
338
|
-
*/ export function bgBrightMagenta(str) {
|
|
339
|
-
return run(str, code([
|
|
340
|
-
105
|
|
341
|
-
], 49));
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Set background color to bright cyan.
|
|
345
|
-
* @param str text to make its background bright-cyan
|
|
346
|
-
*/ export function bgBrightCyan(str) {
|
|
347
|
-
return run(str, code([
|
|
348
|
-
106
|
|
349
|
-
], 49));
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Set background color to bright white.
|
|
353
|
-
* @param str text to make its background bright-white
|
|
354
|
-
*/ export function bgBrightWhite(str) {
|
|
355
|
-
return run(str, code([
|
|
356
|
-
107
|
|
357
|
-
], 49));
|
|
358
|
-
}
|
|
359
|
-
/* Special Color Sequences */ /**
|
|
360
|
-
* Clam and truncate color codes
|
|
361
|
-
* @param n
|
|
362
|
-
* @param max number to truncate to
|
|
363
|
-
* @param min number to truncate from
|
|
364
|
-
*/ function clampAndTruncate(n, max = 255, min = 0) {
|
|
365
|
-
return Math.trunc(Math.max(Math.min(n, max), min));
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Set text color using paletted 8bit colors.
|
|
369
|
-
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
370
|
-
* @param str text color to apply paletted 8bit colors to
|
|
371
|
-
* @param color code
|
|
372
|
-
*/ export function rgb8(str, color) {
|
|
373
|
-
return run(str, code([
|
|
374
|
-
38,
|
|
375
|
-
5,
|
|
376
|
-
clampAndTruncate(color)
|
|
377
|
-
], 39));
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Set background color using paletted 8bit colors.
|
|
381
|
-
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
382
|
-
* @param str text color to apply paletted 8bit background colors to
|
|
383
|
-
* @param color code
|
|
384
|
-
*/ export function bgRgb8(str, color) {
|
|
385
|
-
return run(str, code([
|
|
386
|
-
48,
|
|
387
|
-
5,
|
|
388
|
-
clampAndTruncate(color)
|
|
389
|
-
], 49));
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Set text color using 24bit rgb.
|
|
393
|
-
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
394
|
-
* an `Rgb`.
|
|
395
|
-
*
|
|
396
|
-
* To produce the color magenta:
|
|
397
|
-
*
|
|
398
|
-
* ```ts
|
|
399
|
-
* import { rgb24 } from "./colors.ts";
|
|
400
|
-
* rgb24("foo", 0xff00ff);
|
|
401
|
-
* rgb24("foo", {r: 255, g: 0, b: 255});
|
|
402
|
-
* ```
|
|
403
|
-
* @param str text color to apply 24bit rgb to
|
|
404
|
-
* @param color code
|
|
405
|
-
*/ export function rgb24(str, color) {
|
|
406
|
-
if (typeof color === 'number') {
|
|
407
|
-
return run(str, code([
|
|
408
|
-
38,
|
|
409
|
-
2,
|
|
410
|
-
color >> 16 & 0xff,
|
|
411
|
-
color >> 8 & 0xff,
|
|
412
|
-
color & 0xff
|
|
413
|
-
], 39));
|
|
414
|
-
}
|
|
415
|
-
return run(str, code([
|
|
416
|
-
38,
|
|
417
|
-
2,
|
|
418
|
-
clampAndTruncate(color.r),
|
|
419
|
-
clampAndTruncate(color.g),
|
|
420
|
-
clampAndTruncate(color.b)
|
|
421
|
-
], 39));
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Set background color using 24bit rgb.
|
|
425
|
-
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
426
|
-
* an `Rgb`.
|
|
427
|
-
*
|
|
428
|
-
* To produce the color magenta:
|
|
429
|
-
*
|
|
430
|
-
* ```ts
|
|
431
|
-
* import { bgRgb24 } from "./colors.ts";
|
|
432
|
-
* bgRgb24("foo", 0xff00ff);
|
|
433
|
-
* bgRgb24("foo", {r: 255, g: 0, b: 255});
|
|
434
|
-
* ```
|
|
435
|
-
* @param str text color to apply 24bit rgb to
|
|
436
|
-
* @param color code
|
|
437
|
-
*/ export function bgRgb24(str, color) {
|
|
438
|
-
if (typeof color === 'number') {
|
|
439
|
-
return run(str, code([
|
|
440
|
-
48,
|
|
441
|
-
2,
|
|
442
|
-
color >> 16 & 0xff,
|
|
443
|
-
color >> 8 & 0xff,
|
|
444
|
-
color & 0xff
|
|
445
|
-
], 49));
|
|
446
|
-
}
|
|
447
|
-
return run(str, code([
|
|
448
|
-
48,
|
|
449
|
-
2,
|
|
450
|
-
clampAndTruncate(color.r),
|
|
451
|
-
clampAndTruncate(color.g),
|
|
452
|
-
clampAndTruncate(color.b)
|
|
453
|
-
], 49));
|
|
454
|
-
}
|
|
455
|
-
// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
|
|
456
|
-
const ANSI_PATTERN = new RegExp([
|
|
457
|
-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
458
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
|
|
459
|
-
].join('|'), 'g');
|
|
460
|
-
/**
|
|
461
|
-
* Remove ANSI escape codes from the string.
|
|
462
|
-
* @param string to remove ANSI escape codes from
|
|
463
|
-
*/ export function stripColor(string) {
|
|
464
|
-
return string.replace(ANSI_PATTERN, '');
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
//# sourceMappingURL=colors.js.map
|
package/dist/colors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/colors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\n// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.\n// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors\n// on npm.\n// https://deno.land/std@0.153.0/fmt/colors.ts?source\n\nexport interface Code {\n open: string\n close: string\n regexp: RegExp\n}\n\n/** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */\nexport interface Rgb {\n r: number\n g: number\n b: number\n}\n\nlet enabled = true\n\n/**\n * Set changing text color to enabled or disabled\n * @param value\n */\nexport function setColorEnabled(value: boolean) {\n enabled = value\n}\n\n/** Get whether text color change is enabled or disabled. */\nexport function getColorEnabled(): boolean {\n return enabled\n}\n\n/**\n * Builds color code\n * @param open\n * @param close\n */\nfunction code(open: number[], close: number): Code {\n return {\n open: `\\x1b[${open.join(';')}m`,\n close: `\\x1b[${close}m`,\n regexp: new RegExp(`\\\\x1b\\\\[${close}m`, 'g'),\n }\n}\n\n/**\n * Applies color and background based on color code and its associated text\n * @param str text to apply color settings to\n * @param code color code to apply\n */\nfunction run(str: string, code: Code): string {\n return enabled ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}` : str\n}\n\n/**\n * Reset the text modified\n * @param str text to reset\n */\nexport function reset(str: string): string {\n return run(str, code([0], 0))\n}\n\n/**\n * Make the text bold.\n * @param str text to make bold\n */\nexport function bold(str: string): string {\n return run(str, code([1], 22))\n}\n\n/**\n * The text emits only a small amount of light.\n * @param str text to dim\n */\nexport function dim(str: string): string {\n return run(str, code([2], 22))\n}\n\n/**\n * Make the text italic.\n * @param str text to make italic\n */\nexport function italic(str: string): string {\n return run(str, code([3], 23))\n}\n\n/**\n * Make the text underline.\n * @param str text to underline\n */\nexport function underline(str: string): string {\n return run(str, code([4], 24))\n}\n\n/**\n * Invert background color and text color.\n * @param str text to invert its color\n */\nexport function inverse(str: string): string {\n return run(str, code([7], 27))\n}\n\n/**\n * Make the text hidden.\n * @param str text to hide\n */\nexport function hidden(str: string): string {\n return run(str, code([8], 28))\n}\n\n/**\n * Put horizontal line through the center of the text.\n * @param str text to strike through\n */\nexport function strikethrough(str: string): string {\n return run(str, code([9], 29))\n}\n\n/**\n * Set text color to black.\n * @param str text to make black\n */\nexport function black(str: string): string {\n return run(str, code([30], 39))\n}\n\n/**\n * Set text color to red.\n * @param str text to make red\n */\nexport function red(str: string): string {\n return run(str, code([31], 39))\n}\n\n/**\n * Set text color to green.\n * @param str text to make green\n */\nexport function green(str: string): string {\n return run(str, code([32], 39))\n}\n\n/**\n * Set text color to yellow.\n * @param str text to make yellow\n */\nexport function yellow(str: string): string {\n return run(str, code([33], 39))\n}\n\n/**\n * Set text color to blue.\n * @param str text to make blue\n */\nexport function blue(str: string): string {\n return run(str, code([34], 39))\n}\n\n/**\n * Set text color to magenta.\n * @param str text to make magenta\n */\nexport function magenta(str: string): string {\n return run(str, code([35], 39))\n}\n\n/**\n * Set text color to cyan.\n * @param str text to make cyan\n */\nexport function cyan(str: string): string {\n return run(str, code([36], 39))\n}\n\n/**\n * Set text color to white.\n * @param str text to make white\n */\nexport function white(str: string): string {\n return run(str, code([37], 39))\n}\n\n/**\n * Set text color to gray.\n * @param str text to make gray\n */\nexport function gray(str: string): string {\n return brightBlack(str)\n}\n\n/**\n * Set text color to bright black.\n * @param str text to make bright-black\n */\nexport function brightBlack(str: string): string {\n return run(str, code([90], 39))\n}\n\n/**\n * Set text color to bright red.\n * @param str text to make bright-red\n */\nexport function brightRed(str: string): string {\n return run(str, code([91], 39))\n}\n\n/**\n * Set text color to bright green.\n * @param str text to make bright-green\n */\nexport function brightGreen(str: string): string {\n return run(str, code([92], 39))\n}\n\n/**\n * Set text color to bright yellow.\n * @param str text to make bright-yellow\n */\nexport function brightYellow(str: string): string {\n return run(str, code([93], 39))\n}\n\n/**\n * Set text color to bright blue.\n * @param str text to make bright-blue\n */\nexport function brightBlue(str: string): string {\n return run(str, code([94], 39))\n}\n\n/**\n * Set text color to bright magenta.\n * @param str text to make bright-magenta\n */\nexport function brightMagenta(str: string): string {\n return run(str, code([95], 39))\n}\n\n/**\n * Set text color to bright cyan.\n * @param str text to make bright-cyan\n */\nexport function brightCyan(str: string): string {\n return run(str, code([96], 39))\n}\n\n/**\n * Set text color to bright white.\n * @param str text to make bright-white\n */\nexport function brightWhite(str: string): string {\n return run(str, code([97], 39))\n}\n\n/**\n * Set background color to black.\n * @param str text to make its background black\n */\nexport function bgBlack(str: string): string {\n return run(str, code([40], 49))\n}\n\n/**\n * Set background color to red.\n * @param str text to make its background red\n */\nexport function bgRed(str: string): string {\n return run(str, code([41], 49))\n}\n\n/**\n * Set background color to green.\n * @param str text to make its background green\n */\nexport function bgGreen(str: string): string {\n return run(str, code([42], 49))\n}\n\n/**\n * Set background color to yellow.\n * @param str text to make its background yellow\n */\nexport function bgYellow(str: string): string {\n return run(str, code([43], 49))\n}\n\n/**\n * Set background color to blue.\n * @param str text to make its background blue\n */\nexport function bgBlue(str: string): string {\n return run(str, code([44], 49))\n}\n\n/**\n * Set background color to magenta.\n * @param str text to make its background magenta\n */\nexport function bgMagenta(str: string): string {\n return run(str, code([45], 49))\n}\n\n/**\n * Set background color to cyan.\n * @param str text to make its background cyan\n */\nexport function bgCyan(str: string): string {\n return run(str, code([46], 49))\n}\n\n/**\n * Set background color to white.\n * @param str text to make its background white\n */\nexport function bgWhite(str: string): string {\n return run(str, code([47], 49))\n}\n\n/**\n * Set background color to bright black.\n * @param str text to make its background bright-black\n */\nexport function bgBrightBlack(str: string): string {\n return run(str, code([100], 49))\n}\n\n/**\n * Set background color to bright red.\n * @param str text to make its background bright-red\n */\nexport function bgBrightRed(str: string): string {\n return run(str, code([101], 49))\n}\n\n/**\n * Set background color to bright green.\n * @param str text to make its background bright-green\n */\nexport function bgBrightGreen(str: string): string {\n return run(str, code([102], 49))\n}\n\n/**\n * Set background color to bright yellow.\n * @param str text to make its background bright-yellow\n */\nexport function bgBrightYellow(str: string): string {\n return run(str, code([103], 49))\n}\n\n/**\n * Set background color to bright blue.\n * @param str text to make its background bright-blue\n */\nexport function bgBrightBlue(str: string): string {\n return run(str, code([104], 49))\n}\n\n/**\n * Set background color to bright magenta.\n * @param str text to make its background bright-magenta\n */\nexport function bgBrightMagenta(str: string): string {\n return run(str, code([105], 49))\n}\n\n/**\n * Set background color to bright cyan.\n * @param str text to make its background bright-cyan\n */\nexport function bgBrightCyan(str: string): string {\n return run(str, code([106], 49))\n}\n\n/**\n * Set background color to bright white.\n * @param str text to make its background bright-white\n */\nexport function bgBrightWhite(str: string): string {\n return run(str, code([107], 49))\n}\n\n/* Special Color Sequences */\n\n/**\n * Clam and truncate color codes\n * @param n\n * @param max number to truncate to\n * @param min number to truncate from\n */\nfunction clampAndTruncate(n: number, max = 255, min = 0): number {\n return Math.trunc(Math.max(Math.min(n, max), min))\n}\n\n/**\n * Set text color using paletted 8bit colors.\n * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit\n * @param str text color to apply paletted 8bit colors to\n * @param color code\n */\nexport function rgb8(str: string, color: number): string {\n return run(str, code([38, 5, clampAndTruncate(color)], 39))\n}\n\n/**\n * Set background color using paletted 8bit colors.\n * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit\n * @param str text color to apply paletted 8bit background colors to\n * @param color code\n */\nexport function bgRgb8(str: string, color: number): string {\n return run(str, code([48, 5, clampAndTruncate(color)], 49))\n}\n\n/**\n * Set text color using 24bit rgb.\n * `color` can be a number in range `0x000000` to `0xffffff` or\n * an `Rgb`.\n *\n * To produce the color magenta:\n *\n * ```ts\n * import { rgb24 } from \"./colors.ts\";\n * rgb24(\"foo\", 0xff00ff);\n * rgb24(\"foo\", {r: 255, g: 0, b: 255});\n * ```\n * @param str text color to apply 24bit rgb to\n * @param color code\n */\nexport function rgb24(str: string, color: number | Rgb): string {\n if (typeof color === 'number') {\n return run(str, code([38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 39))\n }\n return run(str, code([38, 2, clampAndTruncate(color.r), clampAndTruncate(color.g), clampAndTruncate(color.b)], 39))\n}\n\n/**\n * Set background color using 24bit rgb.\n * `color` can be a number in range `0x000000` to `0xffffff` or\n * an `Rgb`.\n *\n * To produce the color magenta:\n *\n * ```ts\n * import { bgRgb24 } from \"./colors.ts\";\n * bgRgb24(\"foo\", 0xff00ff);\n * bgRgb24(\"foo\", {r: 255, g: 0, b: 255});\n * ```\n * @param str text color to apply 24bit rgb to\n * @param color code\n */\nexport function bgRgb24(str: string, color: number | Rgb): string {\n if (typeof color === 'number') {\n return run(str, code([48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 49))\n }\n return run(str, code([48, 2, clampAndTruncate(color.r), clampAndTruncate(color.g), clampAndTruncate(color.b)], 49))\n}\n\n// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js\nconst ANSI_PATTERN = new RegExp(\n [\n '[\\\\u001B\\\\u009B][[\\\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]+)*|[a-zA-Z\\\\d]+(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*)?\\\\u0007)',\n '(?:(?:\\\\d{1,4}(?:;\\\\d{0,4})*)?[\\\\dA-PR-TZcf-nq-uy=><~]))',\n ].join('|'),\n 'g',\n)\n\n/**\n * Remove ANSI escape codes from the string.\n * @param string to remove ANSI escape codes from\n */\nexport function stripColor(string: string): string {\n return string.replace(ANSI_PATTERN, '')\n}\n"],"names":["enabled","setColorEnabled","value","getColorEnabled","code","open","close","join","regexp","RegExp","run","str","replace","reset","bold","dim","italic","underline","inverse","hidden","strikethrough","black","red","green","yellow","blue","magenta","cyan","white","gray","brightBlack","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgBrightBlack","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite","clampAndTruncate","n","max","min","Math","trunc","rgb8","color","bgRgb8","rgb24","r","g","b","bgRgb24","ANSI_PATTERN","stripColor","string"],"mappings":"AAAA,mEAAmE,GAEnE,0EAA0E;AAC1E,+EAA+E;AAC/E,UAAU;AACV,qDAAqD;AAerD,IAAIA,UAAU,IAAI;AAElB;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,KAAc,EAAE;IAC9CF,UAAUE;AACZ,CAAC;AAED,0DAA0D,GAC1D,OAAO,SAASC,kBAA2B;IACzC,OAAOH;AACT,CAAC;AAED;;;;CAIC,GACD,SAASI,KAAKC,IAAc,EAAEC,KAAa,EAAQ;IACjD,OAAO;QACLD,MAAM,CAAC,KAAK,EAAEA,KAAKE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/BD,OAAO,CAAC,KAAK,EAAEA,MAAM,CAAC,CAAC;QACvBE,QAAQ,IAAIC,OAAO,CAAC,QAAQ,EAAEH,MAAM,CAAC,CAAC,EAAE;IAC1C;AACF;AAEA;;;;CAIC,GACD,SAASI,IAAIC,GAAW,EAAEP,IAAU,EAAU;IAC5C,OAAOJ,UAAU,CAAC,EAAEI,KAAKC,IAAI,CAAC,EAAEM,IAAIC,OAAO,CAACR,KAAKI,MAAM,EAAEJ,KAAKC,IAAI,EAAE,EAAED,KAAKE,KAAK,CAAC,CAAC,GAAGK,GAAG;AAC1F;AAEA;;;CAGC,GACD,OAAO,SAASE,MAAMF,GAAW,EAAU;IACzC,OAAOD,IAAIC,KAAKP,KAAK;QAAC;KAAE,EAAE;AAC5B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASU,KAAKH,GAAW,EAAU;IACxC,OAAOD,IAAIC,KAAKP,KAAK;QAAC;KAAE,EAAE;AAC5B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASW,IAAIJ,GAAW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E,MAAM,GAAG,MAAM,CAWrD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrD"}
|
package/dist/hash.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function iconHashToBigInt(hash) {
|
|
2
|
-
// The icon is animated so it needs special handling
|
|
3
|
-
if (hash.startsWith('a_')) {
|
|
4
|
-
// Change the `a_` to just be `a`
|
|
5
|
-
hash = `a${hash.substring(2)}`;
|
|
6
|
-
} else {
|
|
7
|
-
// The icon is not animated but it could be that it starts with a 0 so we just put a `b` in front so nothing breaks
|
|
8
|
-
hash = `b${hash}`;
|
|
9
|
-
}
|
|
10
|
-
return BigInt(`0x${hash}`);
|
|
11
|
-
}
|
|
12
|
-
export function iconBigintToHash(icon) {
|
|
13
|
-
// Convert the bigint back to a hash
|
|
14
|
-
const hash = icon.toString(16);
|
|
15
|
-
// Hashes starting with a are animated and with b are not so need to handle that
|
|
16
|
-
return hash.startsWith('a') ? `a_${hash.substring(1)}` : hash.substring(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hash.ts"],"sourcesContent":["export function iconHashToBigInt(hash: string): bigint {\n // The icon is animated so it needs special handling\n if (hash.startsWith('a_')) {\n // Change the `a_` to just be `a`\n hash = `a${hash.substring(2)}`\n } else {\n // The icon is not animated but it could be that it starts with a 0 so we just put a `b` in front so nothing breaks\n hash = `b${hash}`\n }\n\n return BigInt(`0x${hash}`)\n}\n\nexport function iconBigintToHash(icon: bigint): string {\n // Convert the bigint back to a hash\n const hash = icon.toString(16)\n // Hashes starting with a are animated and with b are not so need to handle that\n return hash.startsWith('a') ? `a_${hash.substring(1)}` : hash.substring(1)\n}\n"],"names":["iconHashToBigInt","hash","startsWith","substring","BigInt","iconBigintToHash","icon","toString"],"mappings":"AAAA,OAAO,SAASA,iBAAiBC,IAAY,EAAU;IACrD,oDAAoD;IACpD,IAAIA,KAAKC,UAAU,CAAC,OAAO;QACzB,iCAAiC;QACjCD,OAAO,CAAC,CAAC,EAAEA,KAAKE,SAAS,CAAC,GAAG,CAAC;IAChC,OAAO;QACL,mHAAmH;QACnHF,OAAO,CAAC,CAAC,EAAEA,KAAK,CAAC;IACnB,CAAC;IAED,OAAOG,OAAO,CAAC,EAAE,EAAEH,KAAK,CAAC;AAC3B,CAAC;AAED,OAAO,SAASI,iBAAiBC,IAAY,EAAU;IACrD,oCAAoC;IACpC,MAAML,OAAOK,KAAKC,QAAQ,CAAC;IAC3B,gFAAgF;IAChF,OAAON,KAAKC,UAAU,CAAC,OAAO,CAAC,EAAE,EAAED,KAAKE,SAAS,CAAC,GAAG,CAAC,GAAGF,KAAKE,SAAS,CAAC,EAAE;AAC5E,CAAC"}
|
package/dist/images.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { BigString, GetGuildWidgetImageQuery, ImageFormat, ImageSize } from '@discordeno/types';
|
|
2
|
-
/** Help format an image url. */
|
|
3
|
-
export declare function formatImageUrl(url: string, size?: ImageSize, format?: ImageFormat): string;
|
|
4
|
-
/**
|
|
5
|
-
* Get the url for an emoji.
|
|
6
|
-
*
|
|
7
|
-
* @param emojiId The id of the emoji
|
|
8
|
-
* @param animated Whether or not the emoji is animated
|
|
9
|
-
* @returns string
|
|
10
|
-
*/
|
|
11
|
-
export declare function emojiUrl(emojiId: BigString, animated?: boolean): string;
|
|
12
|
-
/**
|
|
13
|
-
* Builds a URL to a user's avatar stored in the Discord CDN.
|
|
14
|
-
*
|
|
15
|
-
* @param userId - The ID of the user to get the avatar of.
|
|
16
|
-
* @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)
|
|
17
|
-
* @param options - The parameters for the building of the URL.
|
|
18
|
-
* @returns The link to the resource.
|
|
19
|
-
*/
|
|
20
|
-
export declare function avatarUrl(userId: BigString, discriminator: string, options?: {
|
|
21
|
-
avatar: BigString | undefined;
|
|
22
|
-
size?: ImageSize;
|
|
23
|
-
format?: ImageFormat;
|
|
24
|
-
}): string;
|
|
25
|
-
/**
|
|
26
|
-
* Builds a URL to the guild banner stored in the Discord CDN.
|
|
27
|
-
*
|
|
28
|
-
* @param guildId - The ID of the guild to get the link to the banner for.
|
|
29
|
-
* @param options - The parameters for the building of the URL.
|
|
30
|
-
* @returns The link to the resource or `undefined` if no banner has been set.
|
|
31
|
-
*/
|
|
32
|
-
export declare function guildBannerUrl(guildId: BigString, options: {
|
|
33
|
-
banner?: string | bigint;
|
|
34
|
-
size?: ImageSize;
|
|
35
|
-
format?: ImageFormat;
|
|
36
|
-
}): string | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Builds a URL to the guild icon stored in the Discord CDN.
|
|
39
|
-
*
|
|
40
|
-
* @param guildId - The ID of the guild to get the link to the banner for.
|
|
41
|
-
* @param options - The parameters for the building of the URL.
|
|
42
|
-
* @returns The link to the resource or `undefined` if no banner has been set.
|
|
43
|
-
*/
|
|
44
|
-
export declare function guildIconUrl(guildId: BigString, imageHash: BigString | undefined, options?: {
|
|
45
|
-
size?: ImageSize;
|
|
46
|
-
format?: ImageFormat;
|
|
47
|
-
}): string | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Builds the URL to a guild splash stored in the Discord CDN.
|
|
50
|
-
*
|
|
51
|
-
* @param guildId - The ID of the guild to get the splash of.
|
|
52
|
-
* @param imageHash - The hash identifying the splash image.
|
|
53
|
-
* @param options - The parameters for the building of the URL.
|
|
54
|
-
* @returns The link to the resource or `undefined` if the guild does not have a splash image set.
|
|
55
|
-
*/
|
|
56
|
-
export declare function guildSplashUrl(guildId: BigString, imageHash: BigString | undefined, options?: {
|
|
57
|
-
size?: ImageSize;
|
|
58
|
-
format?: ImageFormat;
|
|
59
|
-
}): string | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* Builds a URL to the guild widget image stored in the Discord CDN.
|
|
62
|
-
*
|
|
63
|
-
* @param guildId - The ID of the guild to get the link to the widget image for.
|
|
64
|
-
* @param options - The parameters for the building of the URL.
|
|
65
|
-
* @returns The link to the resource.
|
|
66
|
-
*/
|
|
67
|
-
export declare function getWidgetImageUrl(guildId: BigString, options?: GetGuildWidgetImageQuery): string;
|
|
68
|
-
//# sourceMappingURL=images.d.ts.map
|
package/dist/images.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../src/images.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAwB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGpG,gCAAgC;AAChC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,SAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAE/F;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAErE;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,EACjB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;IACR,MAAM,EAAE,SAAS,GAAG,SAAS,CAAA;IAC7B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GACA,MAAM,CAQR;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GACA,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,EAClB,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GACA,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,EAClB,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GACA,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAQhG"}
|
package/dist/images.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { iconBigintToHash } from './hash.js';
|
|
2
|
-
/** Help format an image url. */ export function formatImageUrl(url, size = 128, format) {
|
|
3
|
-
return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Get the url for an emoji.
|
|
7
|
-
*
|
|
8
|
-
* @param emojiId The id of the emoji
|
|
9
|
-
* @param animated Whether or not the emoji is animated
|
|
10
|
-
* @returns string
|
|
11
|
-
*/ export function emojiUrl(emojiId, animated = false) {
|
|
12
|
-
return `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'png'}`;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Builds a URL to a user's avatar stored in the Discord CDN.
|
|
16
|
-
*
|
|
17
|
-
* @param userId - The ID of the user to get the avatar of.
|
|
18
|
-
* @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)
|
|
19
|
-
* @param options - The parameters for the building of the URL.
|
|
20
|
-
* @returns The link to the resource.
|
|
21
|
-
*/ export function avatarUrl(userId, discriminator, options) {
|
|
22
|
-
return options?.avatar ? formatImageUrl(`https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`, options?.size ?? 128, options?.format) : `https://cdn.discordapp.com/embed/avatars/${discriminator === '0' ? (BigInt(userId) >> BigInt(22)) % BigInt(6) : Number(discriminator) % 5}.png`;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Builds a URL to the guild banner stored in the Discord CDN.
|
|
26
|
-
*
|
|
27
|
-
* @param guildId - The ID of the guild to get the link to the banner for.
|
|
28
|
-
* @param options - The parameters for the building of the URL.
|
|
29
|
-
* @returns The link to the resource or `undefined` if no banner has been set.
|
|
30
|
-
*/ export function guildBannerUrl(guildId, options) {
|
|
31
|
-
return options.banner ? formatImageUrl(`https://cdn.discordapp.com/banners/${guildId}/${typeof options.banner === 'string' ? options.banner : iconBigintToHash(options.banner)}`, options.size ?? 128, options.format) : undefined;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Builds a URL to the guild icon stored in the Discord CDN.
|
|
35
|
-
*
|
|
36
|
-
* @param guildId - The ID of the guild to get the link to the banner for.
|
|
37
|
-
* @param options - The parameters for the building of the URL.
|
|
38
|
-
* @returns The link to the resource or `undefined` if no banner has been set.
|
|
39
|
-
*/ export function guildIconUrl(guildId, imageHash, options) {
|
|
40
|
-
return imageHash ? formatImageUrl(`https://cdn.discordapp.com/icons/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`, options?.size ?? 128, options?.format) : undefined;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Builds the URL to a guild splash stored in the Discord CDN.
|
|
44
|
-
*
|
|
45
|
-
* @param guildId - The ID of the guild to get the splash of.
|
|
46
|
-
* @param imageHash - The hash identifying the splash image.
|
|
47
|
-
* @param options - The parameters for the building of the URL.
|
|
48
|
-
* @returns The link to the resource or `undefined` if the guild does not have a splash image set.
|
|
49
|
-
*/ export function guildSplashUrl(guildId, imageHash, options) {
|
|
50
|
-
return imageHash ? formatImageUrl(`https://cdn.discordapp.com/splashes/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`, options?.size ?? 128, options?.format) : undefined;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Builds a URL to the guild widget image stored in the Discord CDN.
|
|
54
|
-
*
|
|
55
|
-
* @param guildId - The ID of the guild to get the link to the widget image for.
|
|
56
|
-
* @param options - The parameters for the building of the URL.
|
|
57
|
-
* @returns The link to the resource.
|
|
58
|
-
*/ export function getWidgetImageUrl(guildId, options) {
|
|
59
|
-
let url = `https://discordapp.com/api/guilds/${guildId}/widget.png`;
|
|
60
|
-
if (options?.style) {
|
|
61
|
-
url += `?style=${options.style}`;
|
|
62
|
-
}
|
|
63
|
-
return url;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=images.js.map
|