@discordeno/utils 19.0.0-next.fc13bdf → 19.0.0-next.fd357ae

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 CHANGED
@@ -149,6 +149,6 @@ and unofficial templates:
149
149
 
150
150
  ## Links
151
151
 
152
- - [Website](https://discordeno.mod.land)
152
+ - [Website](https://discordeno.js.org/)
153
153
  - [Documentation](https://doc.deno.land/https/deno.land/x/discordeno/mod.ts)
154
154
  - [Discord](https://discord.com/invite/5vBgXk3UcZ)
package/dist/bucket.d.ts CHANGED
@@ -1,55 +1,43 @@
1
- import type { PickPartial } from '@discordeno/types';
2
- /** A Leaky Bucket.
3
- * Useful for rate limiting purposes.
4
- * This uses `performance.now()` instead of `Date.now()` for higher accuracy.
5
- *
6
- * NOTE: This bucket is lazy, means it only updates when a related method is called.
7
- */
8
- export interface LeakyBucket {
9
- /** How many tokens this bucket can hold. */
1
+ /// <reference types="node" />
2
+ export declare class LeakyBucket implements LeakyBucketOptions {
10
3
  max: number;
11
- /** Amount of tokens gained per interval.
12
- * If bigger than `max` it will be pressed to `max`.
13
- */
14
- refillAmount: number;
15
- /** Interval at which the bucket gains tokens. */
16
4
  refillInterval: number;
17
- /** Acquire tokens from the bucket.
18
- * Resolves when the tokens are acquired and available.
19
- * @param {boolean} [highPriority=false] Whether this acquire is should be done asap.
20
- */
21
- acquire: (amount: number, highPriority?: boolean) => Promise<void>;
22
- /** Returns the number of milliseconds until the next refill. */
23
- nextRefill: () => number;
24
- /** Current tokens in the bucket. */
25
- tokens: () => number;
26
- /** @private Internal track of when the last refill of tokens was.
27
- * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P
28
- */
29
- lastRefill: number;
30
- /** @private Internal state of whether currently it is allowed to acquire tokens.
31
- * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P
5
+ refillAmount: number;
6
+ /** The amount of requests that have been used up already. */
7
+ used: number;
8
+ /** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */
9
+ queue: Array<(value: void | PromiseLike<void>) => void>;
10
+ /** Whether or not the queue is already processing. */
11
+ processing: boolean;
12
+ /** The timeout id for the timer to reduce the used amount by the refill amount. */
13
+ timeoutId?: NodeJS.Timeout;
14
+ /** The timestamp in milliseconds when the next refill is scheduled. */
15
+ refillsAt?: number;
16
+ constructor(options?: LeakyBucketOptions);
17
+ /** The amount of requests that still remain. */
18
+ get remaining(): number;
19
+ /** Refills the bucket as needed. */
20
+ refillBucket(): void;
21
+ /** Begin processing the queue. */
22
+ processQueue(): Promise<void>;
23
+ /** Pauses the execution until the request is available to be made. */
24
+ acquire(highPriority?: boolean): Promise<void>;
25
+ }
26
+ export interface LeakyBucketOptions {
27
+ /**
28
+ * Max requests allowed at once.
29
+ * @default 1
32
30
  */
33
- allowAcquire: boolean;
34
- /** @private Internal number of currently available tokens.
35
- * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P
31
+ max?: number;
32
+ /**
33
+ * Interval in milliseconds between refills.
34
+ * @default 5000
36
35
  */
37
- tokensState: number;
38
- /** @private Internal array of promises necessary to guarantee no race conditions.
39
- * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P
36
+ refillInterval?: number;
37
+ /**
38
+ * Amount of requests to refill at each interval.
39
+ * @default 1
40
40
  */
41
- waiting: Array<(_?: unknown) => void>;
41
+ refillAmount?: number;
42
42
  }
43
- export declare function createLeakyBucket({ max, refillInterval, refillAmount, tokens, waiting, ...rest }: Omit<PickPartial<LeakyBucket, 'max' | 'refillInterval' | 'refillAmount'>, 'tokens'> & {
44
- /** Current tokens in the bucket.
45
- * @default max
46
- */
47
- tokens?: number;
48
- }): LeakyBucket;
49
- /** Update the tokens of that bucket.
50
- * @returns {number} The amount of current available tokens.
51
- */
52
- export declare function updateTokens(bucket: LeakyBucket): number;
53
- export declare function nextRefill(bucket: LeakyBucket): number;
54
- export declare function acquire(bucket: LeakyBucket, amount: number, highPriority?: boolean): Promise<void>;
55
43
  //# sourceMappingURL=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,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+CtG"}
1
+ {"version":3,"file":"bucket.d.ts","sourceRoot":"","sources":["../src/bucket.ts"],"names":[],"mappings":";AAGA,qBAAa,WAAY,YAAW,kBAAkB;IACpD,GAAG,EAAE,MAAM,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IAEpB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAI;IAChB,4FAA4F;IAC5F,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAK;IAC5D,sDAAsD;IACtD,UAAU,EAAE,OAAO,CAAQ;IAC3B,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;IAC1B,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAA;gBAEN,OAAO,CAAC,EAAE,kBAAkB;IAMxC,gDAAgD;IAChD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,oCAAoC;IACpC,YAAY,IAAI,IAAI;IAgBpB,kCAAkC;IAC5B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IA0CnC,sEAAsE;IAChE,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAWrD;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
package/dist/bucket.js CHANGED
@@ -1,80 +1,74 @@
1
+ import logger from './logger.js';
1
2
  import { delay } from './utils.js';
2
- export function createLeakyBucket({ max , refillInterval , refillAmount , tokens , waiting , ...rest }) {
3
- return {
4
- max,
5
- refillInterval,
6
- refillAmount: refillAmount > max ? max : refillAmount,
7
- lastRefill: performance.now(),
8
- allowAcquire: true,
9
- nextRefill: function() {
10
- return nextRefill(this);
11
- },
12
- tokens: function() {
13
- return updateTokens(this);
14
- },
15
- acquire: async function(amount, highPriority) {
16
- return await acquire(this, amount, highPriority);
17
- },
18
- tokensState: tokens ?? max,
19
- waiting: waiting ?? [],
20
- ...rest
21
- };
22
- }
23
- /** Update the tokens of that bucket.
24
- * @returns {number} The amount of current available tokens.
25
- */ export function updateTokens(bucket) {
26
- const timePassed = performance.now() - bucket.lastRefill;
27
- const missedRefills = Math.floor(timePassed / bucket.refillInterval);
28
- // The refill shall not exceed the max amount of tokens.
29
- bucket.tokensState = Math.min(bucket.tokensState + bucket.refillAmount * missedRefills, bucket.max);
30
- bucket.lastRefill += bucket.refillInterval * missedRefills;
31
- return bucket.tokensState;
32
- }
33
- export function nextRefill(bucket) {
34
- // Since this bucket is lazy update the tokens before calculating the next refill.
35
- updateTokens(bucket);
36
- return performance.now() - bucket.lastRefill + bucket.refillInterval;
37
- }
38
- export async function acquire(bucket, amount, highPriority = false) {
39
- // To prevent the race condition of 2 acquires happening at once,
40
- // check whether its currently allowed to acquire.
41
- if (!bucket.allowAcquire) {
42
- // create, push, and wait until the current running acquiring is finished.
43
- await new Promise((resolve)=>{
44
- if (highPriority) {
45
- bucket.waiting.unshift(resolve);
46
- } else {
47
- bucket.waiting.push(resolve);
3
+ export class LeakyBucket {
4
+ constructor(options){
5
+ /** The amount of requests that have been used up already. */ this.used = 0;
6
+ /** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */ this.queue = [];
7
+ /** Whether or not the queue is already processing. */ this.processing = false;
8
+ this.max = options?.max ?? 1;
9
+ this.refillAmount = options?.refillAmount ? options.refillAmount > this.max ? this.max : options.refillAmount : 1;
10
+ this.refillInterval = options?.refillInterval ?? 5000;
11
+ }
12
+ /** The amount of requests that still remain. */ get remaining() {
13
+ return this.max < this.used ? 0 : this.max - this.used;
14
+ }
15
+ /** Refills the bucket as needed. */ refillBucket() {
16
+ logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`);
17
+ // Lower the used amount by the refill amount
18
+ this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
19
+ // Reset the refillsAt timestamp since it just got refilled
20
+ this.refillsAt = undefined;
21
+ if (this.used > 0) {
22
+ if (this.timeoutId) clearTimeout(this.timeoutId);
23
+ this.timeoutId = setTimeout(()=>{
24
+ this.refillBucket();
25
+ }, this.refillInterval);
26
+ this.refillsAt = Date.now() + this.refillInterval;
27
+ }
28
+ }
29
+ /** Begin processing the queue. */ async processQueue() {
30
+ logger.debug('[Gateway] Processing queue');
31
+ // There is already a queue that is processing
32
+ if (this.processing) return logger.debug('[Gateway] Queue is already processing.');
33
+ // Begin going through the queue.
34
+ while(this.queue.length){
35
+ if (this.remaining) {
36
+ logger.debug(`[LeakyBucket] Processing queue. Remaining: ${this.remaining} Length: ${this.queue.length}`);
37
+ // Resolves the promise allowing the paused execution of this request to resolve and continue.
38
+ this.queue.shift()?.();
39
+ // A request can be made
40
+ this.used++;
41
+ // Create a new timeout for this request if none exists.
42
+ if (!this.timeoutId) {
43
+ logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`);
44
+ this.timeoutId = setTimeout(()=>{
45
+ this.refillBucket();
46
+ }, this.refillInterval);
47
+ // Set the time for when this refill will occur.
48
+ this.refillsAt = Date.now() + this.refillInterval;
49
+ }
50
+ } else if (this.refillsAt) {
51
+ const now = Date.now();
52
+ // If there is time left until next refill, just delay execution.
53
+ if (this.refillsAt > now) {
54
+ logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for ${this.refillsAt - now}ms`);
55
+ await delay(this.refillsAt - now);
56
+ logger.debug(`[LeakyBucket] Resuming execution`);
57
+ }
48
58
  }
49
- });
50
- // Somehow another acquire has started,
51
- // so need to wait again.
52
- if (!bucket.allowAcquire) {
53
- return await acquire(bucket, amount);
54
59
  }
60
+ // Loop has ended mark false so it can restart later when needed
61
+ this.processing = false;
55
62
  }
56
- bucket.allowAcquire = false;
57
- // Since the bucket is lazy update the tokens now,
58
- // and also get the current amount of available tokens
59
- const currentTokens = updateTokens(bucket);
60
- // It's possible that more than available tokens have been acquired,
61
- // so calculate the amount of milliseconds to wait until this acquire is good to go.
62
- if (currentTokens < amount) {
63
- const tokensNeeded = amount - currentTokens;
64
- const refillsNeeded = Math.ceil(tokensNeeded / bucket.refillAmount);
65
- const waitTime = bucket.refillInterval * refillsNeeded;
66
- await delay(waitTime);
67
- // Update the tokens again to ensure nothing has been missed.
68
- updateTokens(bucket);
63
+ /** Pauses the execution until the request is available to be made. */ async acquire(highPriority) {
64
+ return await new Promise((resolve)=>{
65
+ // High priority requests get added to the start of the queue
66
+ if (highPriority) this.queue.unshift(resolve);
67
+ else this.queue.push(resolve);
68
+ // Each request should trigger the queue to be processesd.
69
+ void this.processQueue();
70
+ });
69
71
  }
70
- // In order to not subtract too much from the tokens,
71
- // calculate what is actually needed to subtract.
72
- const toSubtract = (amount % bucket.refillAmount) ?? amount;
73
- bucket.tokensState -= toSubtract;
74
- // Allow the next acquire to happen.
75
- bucket.allowAcquire = true;
76
- // If there is an acquire waiting, let it continue.
77
- bucket.waiting.shift()?.();
78
72
  }
79
73
 
80
74
  //# sourceMappingURL=bucket.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bucket.ts"],"sourcesContent":["import type { PickPartial } from '@discordeno/types'\nimport { delay } from './utils.js'\n\n/** A Leaky Bucket.\n * Useful for rate limiting purposes.\n * This uses `performance.now()` instead of `Date.now()` for higher accuracy.\n *\n * NOTE: This bucket is lazy, means it only updates when a related method is called.\n */\nexport interface LeakyBucket {\n /** How many tokens this bucket can hold. */\n max: number\n /** Amount of tokens gained per interval.\n * If bigger than `max` it will be pressed to `max`.\n */\n refillAmount: number\n /** Interval at which the bucket gains tokens. */\n refillInterval: number\n\n /** Acquire tokens from the bucket.\n * Resolves when the tokens are acquired and available.\n * @param {boolean} [highPriority=false] Whether this acquire is should be done asap.\n */\n acquire: (amount: number, highPriority?: boolean) => Promise<void>\n\n /** Returns the number of milliseconds until the next refill. */\n nextRefill: () => number\n\n /** Current tokens in the bucket. */\n tokens: () => number\n\n /** @private Internal track of when the last refill of tokens was.\n * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P\n */\n lastRefill: number\n\n /** @private Internal state of whether currently it is allowed to acquire tokens.\n * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P\n */\n allowAcquire: boolean\n\n /** @private Internal number of currently available tokens.\n * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P\n */\n tokensState: number\n\n /** @private Internal array of promises necessary to guarantee no race conditions.\n * DO NOT TOUCH THIS! Unless you know what you are doing ofc :P\n */\n waiting: Array<(_?: unknown) => void>\n}\n\nexport function createLeakyBucket({\n max,\n refillInterval,\n refillAmount,\n tokens,\n waiting,\n ...rest\n}: Omit<PickPartial<LeakyBucket, 'max' | 'refillInterval' | 'refillAmount'>, 'tokens'> & {\n /** Current tokens in the bucket.\n * @default max\n */\n tokens?: number\n}): LeakyBucket {\n return {\n max,\n refillInterval,\n refillAmount: refillAmount > max ? max : refillAmount,\n lastRefill: performance.now(),\n allowAcquire: true,\n\n nextRefill: function () {\n return nextRefill(this)\n },\n\n tokens: function () {\n return updateTokens(this)\n },\n\n acquire: async function (amount, highPriority) {\n return await acquire(this, amount, highPriority)\n },\n\n tokensState: tokens ?? max,\n waiting: waiting ?? [],\n\n ...rest,\n }\n}\n\n/** Update the tokens of that bucket.\n * @returns {number} The amount of current available tokens.\n */\nexport function updateTokens(bucket: LeakyBucket): number {\n const timePassed = performance.now() - bucket.lastRefill\n const missedRefills = Math.floor(timePassed / bucket.refillInterval)\n\n // The refill shall not exceed the max amount of tokens.\n bucket.tokensState = Math.min(bucket.tokensState + bucket.refillAmount * missedRefills, bucket.max)\n bucket.lastRefill += bucket.refillInterval * missedRefills\n\n return bucket.tokensState\n}\n\nexport function nextRefill(bucket: LeakyBucket): number {\n // Since this bucket is lazy update the tokens before calculating the next refill.\n updateTokens(bucket)\n\n return performance.now() - bucket.lastRefill + bucket.refillInterval\n}\n\nexport async function acquire(bucket: LeakyBucket, amount: number, highPriority = false): Promise<void> {\n // To prevent the race condition of 2 acquires happening at once,\n // check whether its currently allowed to acquire.\n if (!bucket.allowAcquire) {\n // create, push, and wait until the current running acquiring is finished.\n await new Promise((resolve) => {\n if (highPriority) {\n bucket.waiting.unshift(resolve)\n } else {\n bucket.waiting.push(resolve)\n }\n })\n\n // Somehow another acquire has started,\n // so need to wait again.\n if (!bucket.allowAcquire) {\n return await acquire(bucket, amount)\n }\n }\n\n bucket.allowAcquire = false\n // Since the bucket is lazy update the tokens now,\n // and also get the current amount of available tokens\n const currentTokens = updateTokens(bucket)\n\n // It's possible that more than available tokens have been acquired,\n // so calculate the amount of milliseconds to wait until this acquire is good to go.\n if (currentTokens < amount) {\n const tokensNeeded = amount - currentTokens\n const refillsNeeded = Math.ceil(tokensNeeded / bucket.refillAmount)\n\n const waitTime = bucket.refillInterval * refillsNeeded\n await delay(waitTime)\n\n // Update the tokens again to ensure nothing has been missed.\n updateTokens(bucket)\n }\n\n // In order to not subtract too much from the tokens,\n // calculate what is actually needed to subtract.\n const toSubtract = amount % bucket.refillAmount ?? amount\n bucket.tokensState -= toSubtract\n\n // Allow the next acquire to happen.\n bucket.allowAcquire = true\n // If there is an acquire waiting, let it continue.\n bucket.waiting.shift()?.()\n}\n"],"names":["delay","createLeakyBucket","max","refillInterval","refillAmount","tokens","waiting","rest","lastRefill","performance","now","allowAcquire","nextRefill","updateTokens","acquire","amount","highPriority","tokensState","bucket","timePassed","missedRefills","Math","floor","min","Promise","resolve","unshift","push","currentTokens","tokensNeeded","refillsNeeded","ceil","waitTime","toSubtract","shift"],"mappings":"AACA,SAASA,KAAK,QAAQ,aAAY;AAmDlC,OAAO,SAASC,kBAAkB,EAChCC,IAAG,EACHC,eAAc,EACdC,aAAY,EACZC,OAAM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OAAO;gBACLP,OAAOZ,OAAO,CAACqB,IAAI,CAACF;YACtB,CAAC;QACH;QAEA,uCAAuC;QACvC,yBAAyB;QACzB,IAAI,CAACP,OAAOP,YAAY,EAAE;YACxB,OAAO,MAAMG,QAAQI,QAAQH;QAC/B,CAAC;IACH,CAAC;IAEDG,OAAOP,YAAY,GAAG,KAAK;IAC3B,kDAAkD;IAClD,sDAAsD;IACtD,MAAMiB,gBAAgBf,aAAaK;IAEnC,oEAAoE;IACpE,oFAAoF;IACpF,IAAIU,gBAAgBb,QAAQ;QAC1B,MAAMc,eAAed,SAASa;QAC9B,MAAME,gBAAgBT,KAAKU,IAAI,CAACF,eAAeX,OAAOd,YAAY;QAElE,MAAM4B,WAAWd,OAAOf,cAAc,GAAG2B;QACzC,MAAM9B,MAAMgC;QAEZ,6DAA6D;QAC7DnB,aAAaK;IACf,CAAC;IAED,qDAAqD;IACrD,iDAAiD;IACjD,MAAMe,aAAalB,CAAAA,SAASG,OAAOd,YAAY,AAAD,KAAKW;IACnDG,OAAOD,WAAW,IAAIgB;IAEtB,oCAAoC;IACpCf,OAAOP,YAAY,GAAG,IAAI;IAC1B,mDAAmD;IACnDO,OAAOZ,OAAO,CAAC4B,KAAK;AACtB,CAAC"}
1
+ {"version":3,"sources":["../src/bucket.ts"],"sourcesContent":["import logger from './logger.js'\nimport { delay } from './utils.js'\n\nexport class LeakyBucket implements LeakyBucketOptions {\n max: number\n refillInterval: number\n refillAmount: number\n\n /** The amount of requests that have been used up already. */\n used: number = 0\n /** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */\n queue: Array<(value: void | PromiseLike<void>) => void> = []\n /** Whether or not the queue is already processing. */\n processing: boolean = false\n /** The timeout id for the timer to reduce the used amount by the refill amount. */\n timeoutId?: NodeJS.Timeout\n /** The timestamp in milliseconds when the next refill is scheduled. */\n refillsAt?: number\n\n constructor(options?: LeakyBucketOptions) {\n this.max = options?.max ?? 1\n this.refillAmount = options?.refillAmount ? (options.refillAmount > this.max ? this.max : options.refillAmount) : 1\n this.refillInterval = options?.refillInterval ?? 5000\n }\n\n /** The amount of requests that still remain. */\n get remaining(): number {\n return this.max < this.used ? 0 : this.max - this.used\n }\n\n /** Refills the bucket as needed. */\n refillBucket(): void {\n logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`)\n // Lower the used amount by the refill amount\n this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount\n // Reset the refillsAt timestamp since it just got refilled\n this.refillsAt = undefined\n\n if (this.used > 0) {\n if (this.timeoutId) clearTimeout(this.timeoutId)\n this.timeoutId = setTimeout(() => {\n this.refillBucket()\n }, this.refillInterval)\n this.refillsAt = Date.now() + this.refillInterval\n }\n }\n\n /** Begin processing the queue. */\n async processQueue(): Promise<void> {\n logger.debug('[Gateway] Processing queue')\n // There is already a queue that is processing\n if (this.processing) return logger.debug('[Gateway] Queue is already processing.')\n\n // Begin going through the queue.\n while (this.queue.length) {\n if (this.remaining) {\n logger.debug(`[LeakyBucket] Processing queue. Remaining: ${this.remaining} Length: ${this.queue.length}`)\n // Resolves the promise allowing the paused execution of this request to resolve and continue.\n this.queue.shift()?.()\n // A request can be made\n this.used++\n\n // Create a new timeout for this request if none exists.\n if (!this.timeoutId) {\n logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`)\n\n this.timeoutId = setTimeout(() => {\n this.refillBucket()\n }, this.refillInterval)\n // Set the time for when this refill will occur.\n this.refillsAt = Date.now() + this.refillInterval\n }\n }\n\n // Check if a refill is scheduled, since we have used up all available requests\n else if (this.refillsAt) {\n const now = Date.now()\n // If there is time left until next refill, just delay execution.\n if (this.refillsAt > now) {\n logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for ${this.refillsAt - now}ms`)\n await delay(this.refillsAt - now)\n logger.debug(`[LeakyBucket] Resuming execution`)\n }\n }\n }\n\n // Loop has ended mark false so it can restart later when needed\n this.processing = false\n }\n\n /** Pauses the execution until the request is available to be made. */\n async acquire(highPriority?: boolean): Promise<void> {\n return await new Promise((resolve) => {\n // High priority requests get added to the start of the queue\n if (highPriority) this.queue.unshift(resolve)\n // All other requests get pushed to the end.\n else this.queue.push(resolve)\n\n // Each request should trigger the queue to be processesd.\n void this.processQueue()\n })\n }\n}\n\nexport interface LeakyBucketOptions {\n /**\n * Max requests allowed at once.\n * @default 1\n */\n max?: number\n /**\n * Interval in milliseconds between refills.\n * @default 5000\n */\n refillInterval?: number\n /**\n * Amount of requests to refill at each interval.\n * @default 1\n */\n refillAmount?: number\n}\n"],"names":["logger","delay","LeakyBucket","constructor","options","used","queue","processing","max","refillAmount","refillInterval","remaining","refillBucket","debug","refillsAt","undefined","timeoutId","clearTimeout","setTimeout","Date","now","processQueue","length","shift","acquire","highPriority","Promise","resolve","unshift","push"],"mappings":"AAAA,OAAOA,YAAY,cAAa;AAChC,SAASC,KAAK,QAAQ,aAAY;AAElC,OAAO,MAAMC;IAgBXC,YAAYC,OAA4B,CAAE;QAX1C,2DAA2D,QAC3DC,OAAe;QACf,0FAA0F,QAC1FC,QAA0D,EAAE;QAC5D,oDAAoD,QACpDC,aAAsB,KAAK;QAOzB,IAAI,CAACC,GAAG,GAAGJ,SAASI,OAAO;QAC3B,IAAI,CAACC,YAAY,GAAGL,SAASK,eAAgBL,QAAQK,YAAY,GAAG,IAAI,CAACD,GAAG,GAAG,IAAI,CAACA,GAAG,GAAGJ,QAAQK,YAAY,GAAI,CAAC;QACnH,IAAI,CAACC,cAAc,GAAGN,SAASM,kBAAkB;IACnD;IAEA,8CAA8C,GAC9C,IAAIC,YAAoB;QACtB,OAAO,IAAI,CAACH,GAAG,GAAG,IAAI,CAACH,IAAI,GAAG,IAAI,IAAI,CAACG,GAAG,GAAG,IAAI,CAACH,IAAI;IACxD;IAEA,kCAAkC,GAClCO,eAAqB;QACnBZ,OAAOa,KAAK,CAAC,CAAC,2EAA2E,CAAC;QAC1F,6CAA6C;QAC7C,IAAI,CAACR,IAAI,GAAG,IAAI,CAACI,YAAY,GAAG,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B,MAAMM,MAAMD,KAAKC,GAAG;gBACpB,iEAAiE;gBACjE,IAAI,IAAI,CAACN,SAAS,GAAGM,KAAK;oBACxBpB,OAAOa,KAAK,CAAC,CAAC,8DAA8D,EAAE,IAAI,CAACC,SAAS,GAAGM,IAAI,EAAE,CAAC;oBACtG,MAAMnB,MAAM,IAAI,CAACa,SAAS,GAAGM;oBAC7BpB,OAAOa,KAAK,CAAC,CAAC,gCAAgC,CAAC;gBACjD,CAAC;YACH,CAAC;QACH;QAEA,gEAAgE;QAChE,IAAI,CAACN,UAAU,GAAG,KAAK;IACzB;IAEA,oEAAoE,GACpE,MAAMiB,QAAQC,YAAsB,EAAiB;QACnD,OAAO,MAAM,IAAIC,QAAQ,CAACC,UAAY;YACpC,6DAA6D;YAC7D,IAAIF,cAAc,IAAI,CAACnB,KAAK,CAACsB,OAAO,CAACD;iBAEhC,IAAI,CAACrB,KAAK,CAACuB,IAAI,CAACF;YAErB,0DAA0D;YAC1D,KAAK,IAAI,CAACN,YAAY;QACxB;IACF;AACF,CAAC"}
@@ -1 +1 @@
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,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAcnD;AAED,wBAAgB,SAAS,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAerD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAepD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAapD"}
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 CHANGED
@@ -5,7 +5,7 @@ export function camelize(object) {
5
5
  if (typeof object === 'object' && object !== null) {
6
6
  const obj = {};
7
7
  Object.keys(object).forEach((key)=>{
8
- obj[typeof key === 'string' ? snakeToCamelCase(key) : key] = camelize(object[key]);
8
+ obj[snakeToCamelCase(key)] = camelize(object[key]);
9
9
  });
10
10
  return obj;
11
11
  }
@@ -18,7 +18,7 @@ export function snakelize(object) {
18
18
  if (typeof object === 'object' && object !== null) {
19
19
  const obj = {};
20
20
  Object.keys(object).forEach((key)=>{
21
- obj[typeof key === 'string' ? camelToSnakeCase(key) : key] = snakelize(object[key]);
21
+ obj[camelToSnakeCase(key)] = snakelize(object[key]);
22
22
  });
23
23
  return obj;
24
24
  }
@@ -1 +1 @@
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[typeof key === 'string' ? snakeToCamelCase(key) : 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\n ;(obj[typeof key === 'string' ? camelToSnakeCase(key) : 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,SAAaC,MAAS,EAAe;IACnD,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,CAAC,OAAOI,QAAQ,WAAWC,iBAAiBD,OAAOA,GAAG,CAAC,GAAuCV,SAASC,MAAM,CAACS,IAAI;QACzH;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASW,UAAcX,MAAS,EAAgB;IACrD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYO,UAAUP;IAC3C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAGtDJ,GAAG,CAAC,OAAOI,QAAQ,WAAWG,iBAAiBH,OAAOA,GAAG,CAAC,GAAwCE,UAAUX,MAAM,CAACS,IAAI;QAC3H;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASU,iBAAiBG,GAAW,EAAU;IACpD,IAAI,CAACA,IAAIC,QAAQ,CAAC,MAAM,OAAOD;IAE/B,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,KAAK,KAAK;YAClBD,UAAUF,GAAG,CAAC,EAAEG,EAAE,CAACG,WAAW;YAE9B,QAAQ;QACV,CAAC;QAEDJ,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC;AAED,OAAO,SAASH,iBAAiBC,GAAW,EAAU;IACpD,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,IAAI,OAAOH,GAAG,CAACG,EAAE,IAAI,KAAK;YAClCD,UAAU,CAAC,CAAC,EAAEF,GAAG,CAACG,EAAE,CAACI,WAAW,GAAG,CAAC;YAEpC,QAAQ;QACV,CAAC;QAEDL,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC"}
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,KA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AAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAcD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAK9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAKhE;AAWD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
package/dist/colors.js CHANGED
@@ -2,15 +2,11 @@
2
2
  // A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
3
3
  // on npm.
4
4
  // https://deno.land/std@0.153.0/fmt/colors.ts?source
5
- const noColor = false;
6
- let enabled = !noColor;
5
+ let enabled = true;
7
6
  /**
8
7
  * Set changing text color to enabled or disabled
9
8
  * @param value
10
9
  */ export function setColorEnabled(value) {
11
- if (noColor) {
12
- return;
13
- }
14
10
  enabled = value;
15
11
  }
16
12
  /** Get whether text color change is enabled or disabled. */ export function getColorEnabled() {
@@ -1 +1 @@
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\nconst noColor = false\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 = !noColor\n\n/**\n * Set changing text color to enabled or disabled\n * @param value\n */\nexport function setColorEnabled(value: boolean) {\n if (noColor) {\n return\n }\n\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":["noColor","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,MAAMA,UAAU,KAAK;AAerB,IAAIC,UAAU,CAACD;AAEf;;;CAGC,GACD,OAAO,SAASE,gBAAgBC,KAAc,EAAE;IAC9C,IAAIH,SAAS;QACX;IACF,CAAC;IAEDC,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,EAAU;IACvC,OAAOD,IAAIC,KAAKP,KAAK;QAAC;KAAE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iBO;KAAO,EAAE;AACzD,CAAC;AAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASE,MAAMpD,GAAW,EAAEkD,KAAmB,EAAU;IAC9D,IAAI,OAAOA,UAAU,UAAU;QAC7B,OAAOnD,IAAIC,KAAKP,KAAK;YAAC;YAAI;YAAIyD,SAAS,KAAM;YAAOA,SAAS,IAAK;YAAMA,QAAQ;SAAK,EAAE;IACzF,CAAC;IACD,OAAOnD,IAAIC,KAAKP,KAAK;QAAC;QAAI;QAAGkD,iBAAiBO,MAAMG,CAAC;QAAGV,iBAAiBO,MAAMI,CAAC;QAAGX,iBAAiBO,MAAMK,CAAC;KAAE,EAAE;AACjH,CAAC;AAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,QAAQxD,GAAW,EAAEkD,KAAmB,EAAU;IAChE,IAAI,OAAOA,UAAU,UAAU;QAC7B,OAAOnD,IAAIC,KAAKP,KAAK;YAAC;YAAI;YAAIyD,SAAS,KAAM;YAAOA,SAAS,IAAK;YAAMA,QAAQ;SAAK,EAAE;IACzF,CAAC;IACD,OAAOnD,IAAIC,KAAKP,KAAK;QAAC;QAAI;QAAGkD,iBAAiBO,MAAMG,CAAC;QAAGV,iBAAiBO,MAAMI,CAAC;QAAGX,iBAAiBO,MAAMK,CAAC;KAAE,EAAE;AACjH,CAAC;AAED,6FAA6F;AAC7F,MAAME,eAAe,IAAI3D,OACvB;IACE;IACA;CACD,CAACF,IAAI,CAAC,MACP;AAGF;;;CAGC,GACD,OAAO,SAAS8D,WAAWC,MAAc,EAAU;IACjD,OAAOA,OAAO1D,OAAO,CAACwD,cAAc;AACtC,CAAC"}
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,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,QAAQ;SAAK,EAAE;IACzF,CAAC;IACD,OAAOnD,IAAIC,KAAKP,KAAK;QAAC;QAAI;QAAGkD,iBAAiBO,MAAMG,CAAC;QAAGV,iBAAiBO,MAAMI,CAAC;QAAGX,iBAAiBO,MAAMK,CAAC;KAAE,EAAE;AACjH,CAAC;AAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,QAAQxD,GAAW,EAAEkD,KAAmB,EAAU;IAChE,IAAI,OAAOA,UAAU,UAAU;QAC7B,OAAOnD,IAAIC,KAAKP,KAAK;YAAC;YAAI;YAAIyD,SAAS,KAAM;YAAOA,SAAS,IAAK;YAAMA,QAAQ;SAAK,EAAE;IACzF,CAAC;IACD,OAAOnD,IAAIC,KAAKP,KAAK;QAAC;QAAI;QAAGkD,iBAAiBO,MAAMG,CAAC;QAAGV,iBAAiBO,MAAMI,CAAC;QAAGX,iBAAiBO,MAAMK,CAAC;KAAE,EAAE;AACjH,CAAC;AAED,6FAA6F;AAC7F,MAAME,eAAe,IAAI3D,OACvB;IACE;IACA;CACD,CAACF,IAAI,CAAC,MACP;AAGF;;;CAGC,GACD,OAAO,SAAS8D,WAAWC,MAAc,EAAU;IACjD,OAAOA,OAAO1D,OAAO,CAACwD,cAAc;AACtC,CAAC"}
package/dist/images.js CHANGED
@@ -19,7 +19,7 @@
19
19
  * @param options - The parameters for the building of the URL.
20
20
  * @returns The link to the resource.
21
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/${Number(discriminator) % 5}.png`;
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/${Number(discriminator) % 5}.png`;
23
23
  }
24
24
  /**
25
25
  * Builds a URL to the guild banner stored in the Discord CDN.
@@ -56,7 +56,7 @@
56
56
  * @param options - The parameters for the building of the URL.
57
57
  * @returns The link to the resource.
58
58
  */ export function getWidgetImageUrl(guildId, options) {
59
- let url = `https://cdn.discordapp.com/guilds/${guildId}/widget.png`;
59
+ let url = `https://discordapp.com/api/guilds/${guildId}/widget.png`;
60
60
  if (options?.style) {
61
61
  url += `?style=${options.style}`;
62
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/images.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { BigString, GetGuildWidgetImageQuery, ImageFormat, ImageSize } from '@discordeno/types'\nimport { iconBigintToHash } from './hash.js'\n\n/** Help format an image url. */\nexport function formatImageUrl(url: string, size: ImageSize = 128, format?: ImageFormat): string {\n return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`\n}\n\n/**\n * Get the url for an emoji.\n *\n * @param emojiId The id of the emoji\n * @param animated Whether or not the emoji is animated\n * @returns string\n */\nexport function emojiUrl(emojiId: BigString, animated = false): string {\n return `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'png'}`\n}\n\n/**\n * Builds a URL to a user's avatar stored in the Discord CDN.\n *\n * @param userId - The ID of the user to get the avatar of.\n * @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function avatarUrl(\n userId: BigString,\n discriminator: string,\n options?: {\n avatar: BigString | undefined\n size?: ImageSize\n format?: ImageFormat\n },\n): string {\n return options?.avatar\n ? formatImageUrl(\n `https://cdn.discordapp.com/avatars/${userId}/${typeof options?.avatar === 'string' ? options.avatar : iconBigintToHash(options?.avatar)}`,\n options?.size ?? 128,\n options?.format,\n )\n : `https://cdn.discordapp.com/embed/avatars/${Number(discriminator) % 5}.png`\n}\n\n/**\n * Builds a URL to the guild banner stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildBannerUrl(\n guildId: BigString,\n options: {\n banner?: string | bigint\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return options.banner\n ? formatImageUrl(\n `https://cdn.discordapp.com/banners/${guildId}/${typeof options.banner === 'string' ? options.banner : iconBigintToHash(options.banner)}`,\n options.size ?? 128,\n options.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild icon stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildIconUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/icons/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds the URL to a guild splash stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the splash of.\n * @param imageHash - The hash identifying the splash image.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if the guild does not have a splash image set.\n */\nexport function guildSplashUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/splashes/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild widget image stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the widget image for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function getWidgetImageUrl(guildId: BigString, options?: GetGuildWidgetImageQuery): string {\n let url = `https://cdn.discordapp.com/guilds/${guildId}/widget.png`\n\n if (options?.style) {\n url += `?style=${options.style}`\n }\n\n return url\n}\n"],"names":["iconBigintToHash","formatImageUrl","url","size","format","includes","emojiUrl","emojiId","animated","avatarUrl","userId","discriminator","options","avatar","Number","guildBannerUrl","guildId","banner","undefined","guildIconUrl","imageHash","guildSplashUrl","getWidgetImageUrl","style"],"mappings":"AAAA,mEAAmE,GACnE,AACA,SAASA,gBAAgB,QAAQ,YAAW;AAE5C,8BAA8B,GAC9B,OAAO,SAASC,eAAeC,GAAW,EAAEC,OAAkB,GAAG,EAAEC,MAAoB,EAAU;IAC/F,OAAO,CAAC,EAAEF,IAAI,CAAC,EAAEE,UAAWF,CAAAA,IAAIG,QAAQ,CAAC,SAAS,QAAQ,KAAK,AAAD,EAAG,MAAM,EAAEF,KAAK,CAAC;AACjF,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASG,SAASC,OAAkB,EAAEC,WAAW,KAAK,EAAU;IACrE,OAAO,CAAC,kCAAkC,EAAED,QAAQ,CAAC,EAAEC,WAAW,QAAQ,KAAK,CAAC,CAAC;AACnF,CAAC;AAED;;;;;;;CAOC,GACD,OAAO,SAASC,UACdC,MAAiB,EACjBC,aAAqB,EACrBC,OAIC,EACO;IACR,OAAOA,SAASC,SACZZ,eACE,CAAC,mCAAmC,EAAES,OAAO,CAAC,EAAE,OAAOE,SAASC,WAAW,WAAWD,QAAQC,MAAM,GAAGb,iBAAiBY,SAASC,OAAO,CAAC,CAAC,EAC1ID,SAAST,QAAQ,KACjBS,SAASR,UAEX,CAAC,yCAAyC,EAAEU,OAAOH,iBAAiB,EAAE,IAAI,CAAC;AACjF,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASI,eACdC,OAAkB,EAClBJ,OAIC,EACmB;IACpB,OAAOA,QAAQK,MAAM,GACjBhB,eACE,CAAC,mCAAmC,EAAEe,QAAQ,CAAC,EAAE,OAAOJ,QAAQK,MAAM,KAAK,WAAWL,QAAQK,MAAM,GAAGjB,iBAAiBY,QAAQK,MAAM,CAAC,CAAC,CAAC,EACzIL,QAAQT,IAAI,IAAI,KAChBS,QAAQR,MAAM,IAEhBc,SAAS;AACf,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASC,aACdH,OAAkB,EAClBI,SAAgC,EAChCR,OAGC,EACmB;IACpB,OAAOQ,YACHnB,eACE,CAAC,iCAAiC,EAAEe,QAAQ,CAAC,EAAE,OAAOI,cAAc,WAAWA,YAAYpB,iBAAiBoB,UAAU,CAAC,CAAC,EACxHR,SAAST,QAAQ,KACjBS,SAASR,UAEXc,SAAS;AACf,CAAC;AAED;;;;;;;CAOC,GACD,OAAO,SAASG,eACdL,OAAkB,EAClBI,SAAgC,EAChCR,OAGC,EACmB;IACpB,OAAOQ,YACHnB,eACE,CAAC,oCAAoC,EAAEe,QAAQ,CAAC,EAAE,OAAOI,cAAc,WAAWA,YAAYpB,iBAAiBoB,UAAU,CAAC,CAAC,EAC3HR,SAAST,QAAQ,KACjBS,SAASR,UAEXc,SAAS;AACf,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASI,kBAAkBN,OAAkB,EAAEJ,OAAkC,EAAU;IAChG,IAAIV,MAAM,CAAC,kCAAkC,EAAEc,QAAQ,WAAW,CAAC;IAEnE,IAAIJ,SAASW,OAAO;QAClBrB,OAAO,CAAC,OAAO,EAAEU,QAAQW,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAOrB;AACT,CAAC"}
1
+ {"version":3,"sources":["../src/images.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { BigString, GetGuildWidgetImageQuery, ImageFormat, ImageSize } from '@discordeno/types'\nimport { iconBigintToHash } from './hash.js'\n\n/** Help format an image url. */\nexport function formatImageUrl(url: string, size: ImageSize = 128, format?: ImageFormat): string {\n return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`\n}\n\n/**\n * Get the url for an emoji.\n *\n * @param emojiId The id of the emoji\n * @param animated Whether or not the emoji is animated\n * @returns string\n */\nexport function emojiUrl(emojiId: BigString, animated = false): string {\n return `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'png'}`\n}\n\n/**\n * Builds a URL to a user's avatar stored in the Discord CDN.\n *\n * @param userId - The ID of the user to get the avatar of.\n * @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function avatarUrl(\n userId: BigString,\n discriminator: string,\n options?: {\n avatar: BigString | undefined\n size?: ImageSize\n format?: ImageFormat\n },\n): string {\n return options?.avatar\n ? formatImageUrl(\n `https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`,\n options?.size ?? 128,\n options?.format,\n )\n : `https://cdn.discordapp.com/embed/avatars/${Number(discriminator) % 5}.png`\n}\n\n/**\n * Builds a URL to the guild banner stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildBannerUrl(\n guildId: BigString,\n options: {\n banner?: string | bigint\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return options.banner\n ? formatImageUrl(\n `https://cdn.discordapp.com/banners/${guildId}/${typeof options.banner === 'string' ? options.banner : iconBigintToHash(options.banner)}`,\n options.size ?? 128,\n options.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild icon stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildIconUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/icons/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds the URL to a guild splash stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the splash of.\n * @param imageHash - The hash identifying the splash image.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if the guild does not have a splash image set.\n */\nexport function guildSplashUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/splashes/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild widget image stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the widget image for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function getWidgetImageUrl(guildId: BigString, options?: GetGuildWidgetImageQuery): string {\n let url = `https://discordapp.com/api/guilds/${guildId}/widget.png`\n\n if (options?.style) {\n url += `?style=${options.style}`\n }\n\n return url\n}\n"],"names":["iconBigintToHash","formatImageUrl","url","size","format","includes","emojiUrl","emojiId","animated","avatarUrl","userId","discriminator","options","avatar","Number","guildBannerUrl","guildId","banner","undefined","guildIconUrl","imageHash","guildSplashUrl","getWidgetImageUrl","style"],"mappings":"AAAA,mEAAmE,GAEnE,SAASA,gBAAgB,QAAQ,YAAW;AAE5C,8BAA8B,GAC9B,OAAO,SAASC,eAAeC,GAAW,EAAEC,OAAkB,GAAG,EAAEC,MAAoB,EAAU;IAC/F,OAAO,CAAC,EAAEF,IAAI,CAAC,EAAEE,UAAWF,CAAAA,IAAIG,QAAQ,CAAC,SAAS,QAAQ,KAAK,AAAD,EAAG,MAAM,EAAEF,KAAK,CAAC;AACjF,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASG,SAASC,OAAkB,EAAEC,WAAW,KAAK,EAAU;IACrE,OAAO,CAAC,kCAAkC,EA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S,SAASR,UAEXc,SAAS;AACf,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASI,kBAAkBN,OAAkB,EAAEJ,OAAkC,EAAU;IAChG,IAAIV,MAAM,CAAC,kCAAkC,EAAEc,QAAQ,WAAW,CAAC;IAEnE,IAAIJ,SAASW,OAAO;QAClBrB,OAAO,CAAC,OAAO,EAAEU,QAAQW,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAOrB;AACT,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export * from './bucket.js';
3
3
  export * from './casing.js';
4
4
  export * from './Collection.js';
5
5
  export * from './colors.js';
6
- export * from './files.js';
7
6
  export * from './hash.js';
8
7
  export * from './images.js';
9
8
  export * from './logger.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@ export * from './bucket.js';
3
3
  export * from './casing.js';
4
4
  export * from './Collection.js';
5
5
  export * from './colors.js';
6
- export * from './files.js';
7
6
  export * from './hash.js';
8
7
  export * from './images.js';
9
8
  export * from './logger.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './Collection.js'\nexport * from './colors.js'\nexport * from './files.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './logger.js'\nexport * from './permissions.js'\nexport * from './reactions.js'\nexport * from './token.js'\nexport * from './typeguards.js'\nexport * from './urlToBase64.js'\nexport * from './utils.js'\n"],"names":[],"mappings":"AAAA,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,aAAY;AAC1B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './Collection.js'\nexport * from './colors.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './logger.js'\nexport * from './permissions.js'\nexport * from './reactions.js'\nexport * from './token.js'\nexport * from './typeguards.js'\nexport * from './urlToBase64.js'\nexport * from './utils.js'\n"],"names":[],"mappings":"AAAA,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA,oBAAY,SAAS;IACnB,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,KAAK,IAAA;CACN;AAED,oBAAY,QAAQ;IAClB,OAAO,IAAA;IACP,IAAI,IAAA;CACL;AAmBD,wBAAgB,YAAY,CAAC,EAC3B,QAAyB,EACzB,IAAI,GACL,GAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;CACT;iBAGgB,SAAS,WAAW,GAAG,EAAE;sBAkCpB,QAAQ;sBAJR,SAAS;qBAQV,GAAG,EAAE;oBAKN,GAAG,EAAE;oBAKL,GAAG,EAAE;qBAKJ,GAAG,EAAE;qBAKL,GAAG,EAAE;EAe9B;AAED,eAAO,MAAM,MAAM;iBA3EG,SAAS,WAAW,GAAG,EAAE;sBAkCpB,QAAQ;sBAJR,SAAS;qBAQV,GAAG,EAAE;oBAKN,GAAG,EAAE;oBAKL,GAAG,EAAE;qBAKJ,GAAG,EAAE;qBAKL,GAAG,EAAE;CAiB2B,CAAA;AAC1D,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAIA,oBAAY,SAAS;IACnB,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,KAAK,IAAA;CACN;AAED,oBAAY,QAAQ;IAClB,OAAO,IAAA;IACP,IAAI,IAAA;CACL;AAmBD,wBAAgB,YAAY,CAAC,EAC3B,QAAyB,EACzB,IAAI,GACL,GAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;CACT;iBAGgB,SAAS,WAAW,GAAG,EAAE;sBAkCpB,QAAQ;sBAJR,SAAS;qBAQV,GAAG,EAAE;oBAKN,GAAG,EAAE;oBAKL,GAAG,EAAE;qBAKJ,GAAG,EAAE;qBAKL,GAAG,EAAE;EAe9B;AAED,eAAO,MAAM,MAAM;iBA3EG,SAAS,WAAW,GAAG,EAAE;sBAkCpB,QAAQ;sBAJR,SAAS;qBAQV,GAAG,EAAE;oBAKN,GAAG,EAAE;oBAKL,GAAG,EAAE;qBAKJ,GAAG,EAAE;qBAKL,GAAG,EAAE;CAiB2B,CAAA;AAC1D,eAAe,MAAM,CAAA"}
package/dist/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { bgBrightMagenta, black, bold, cyan, gray, italic, red, yellow } from './colors.js';
1
+ /* eslint-disable @typescript-eslint/no-confusing-void-expression */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { bgBrightMagenta, black, bold, cyan, gray, italic, red, yellow } from './colors.js';
2
2
  export var LogLevels;
3
3
  (function(LogLevels) {
4
4
  LogLevels[LogLevels["Debug"] = 0] = "Debug";
@@ -64,7 +64,7 @@ export function createLogger({ logLevel =1 , name } = {}) {
64
64
  let color = colorFunctions.get(level);
65
65
  if (!color) color = noColor;
66
66
  const date = new Date();
67
- const log = [
67
+ const log1 = [
68
68
  bgBrightMagenta(black(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)),
69
69
  color(prefixes.get(level) ?? 'DEBUG'),
70
70
  name ? `${name} >` : '>',
@@ -72,17 +72,17 @@ export function createLogger({ logLevel =1 , name } = {}) {
72
72
  ];
73
73
  switch(level){
74
74
  case 0:
75
- return console.debug(...log);
75
+ return console.debug(...log1);
76
76
  case 1:
77
- return console.info(...log);
77
+ return console.info(...log1);
78
78
  case 2:
79
- return console.warn(...log);
79
+ return console.warn(...log1);
80
80
  case 3:
81
- return console.error(...log);
81
+ return console.error(...log1);
82
82
  case 4:
83
- return console.error(...log);
83
+ return console.error(...log1);
84
84
  default:
85
- return console.log(...log);
85
+ return console.log(...log1);
86
86
  }
87
87
  }
88
88
  function setLevel(level) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { bgBrightMagenta, black, bold, cyan, gray, italic, red, yellow } from './colors.js'\n\nexport enum LogLevels {\n Debug,\n Info,\n Warn,\n Error,\n Fatal,\n}\n\nexport enum LogDepth {\n Minimal,\n Full,\n}\n\nconst prefixes = new Map<LogLevels, string>([\n [LogLevels.Debug, 'DEBUG'],\n [LogLevels.Info, 'INFO'],\n [LogLevels.Warn, 'WARN'],\n [LogLevels.Error, 'ERROR'],\n [LogLevels.Fatal, 'FATAL'],\n])\n\nconst noColor: (str: string) => string = (msg) => msg\nconst colorFunctions = new Map<LogLevels, (str: string) => string>([\n [LogLevels.Debug, gray],\n [LogLevels.Info, cyan],\n [LogLevels.Warn, yellow],\n [LogLevels.Error, (str: string) => red(str)],\n [LogLevels.Fatal, (str: string) => red(bold(italic(str)))],\n])\n\nexport function createLogger({\n logLevel = LogLevels.Info,\n name,\n}: {\n logLevel?: LogLevels\n name?: string\n} = {}) {\n let depth = LogDepth.Minimal\n\n function log(level: LogLevels, ...args: any[]) {\n if (level < logLevel) return\n\n let color = colorFunctions.get(level)\n if (!color) color = noColor\n\n const date = new Date()\n const log = [\n bgBrightMagenta(black(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)),\n color(prefixes.get(level) ?? 'DEBUG'),\n name ? `${name} >` : '>',\n ...args,\n ]\n\n switch (level) {\n case LogLevels.Debug:\n return console.debug(...log)\n case LogLevels.Info:\n return console.info(...log)\n case LogLevels.Warn:\n return console.warn(...log)\n case LogLevels.Error:\n return console.error(...log)\n case LogLevels.Fatal:\n return console.error(...log)\n default:\n return console.log(...log)\n }\n }\n\n function setLevel(level: LogLevels) {\n logLevel = level\n }\n\n function setDepth(level: LogDepth) {\n depth = level\n }\n\n function debug(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Debug, args[0])\n else log(LogLevels.Debug, ...args)\n }\n\n function info(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Info, args[0])\n else log(LogLevels.Info, ...args)\n }\n\n function warn(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Warn, args[0])\n else log(LogLevels.Warn, ...args)\n }\n\n function error(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Error, args[0])\n else log(LogLevels.Error, ...args)\n }\n\n function fatal(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Fatal, args[0])\n else log(LogLevels.Fatal, ...args)\n }\n\n return {\n log,\n setDepth,\n setLevel,\n debug,\n info,\n warn,\n error,\n fatal,\n }\n}\n\nexport const logger = createLogger({ name: 'Discordeno' })\nexport default logger\n"],"names":["bgBrightMagenta","black","bold","cyan","gray","italic","red","yellow","LogLevels","Debug","Info","Warn","Error","Fatal","LogDepth","Minimal","Full","prefixes","Map","noColor","msg","colorFunctions","str","createLogger","logLevel","name","depth","log","level","args","color","get","date","Date","toLocaleDateString","toLocaleTimeString","console","debug","info","warn","error","setLevel","setDepth","fatal","logger"],"mappings":"AAAA,mEAAmE,GACnE,SAASA,eAAe,EAAEC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,QAAQ,cAAa;WAEpF;UAAKC,SAAS;IAATA,UAAAA,UACVC,WAAAA,KAAAA;IADUD,UAAAA,UAEVE,UAAAA,KAAAA;IAFUF,UAAAA,UAGVG,UAAAA,KAAAA;IAHUH,UAAAA,UAIVI,WAAAA,KAAAA;IAJU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AC1D,eAAemB,OAAM"}
1
+ {"version":3,"sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-confusing-void-expression */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { bgBrightMagenta, black, bold, cyan, gray, italic, red, yellow } from './colors.js'\n\nexport enum LogLevels {\n Debug,\n Info,\n Warn,\n Error,\n Fatal,\n}\n\nexport enum LogDepth {\n Minimal,\n Full,\n}\n\nconst prefixes = new Map<LogLevels, string>([\n [LogLevels.Debug, 'DEBUG'],\n [LogLevels.Info, 'INFO'],\n [LogLevels.Warn, 'WARN'],\n [LogLevels.Error, 'ERROR'],\n [LogLevels.Fatal, 'FATAL'],\n])\n\nconst noColor: (str: string) => string = (msg) => msg\nconst colorFunctions = new Map<LogLevels, (str: string) => string>([\n [LogLevels.Debug, gray],\n [LogLevels.Info, cyan],\n [LogLevels.Warn, yellow],\n [LogLevels.Error, (str: string) => red(str)],\n [LogLevels.Fatal, (str: string) => red(bold(italic(str)))],\n])\n\nexport function createLogger({\n logLevel = LogLevels.Info,\n name,\n}: {\n logLevel?: LogLevels\n name?: string\n} = {}) {\n let depth = LogDepth.Minimal\n\n function log(level: LogLevels, ...args: any[]) {\n if (level < logLevel) return\n\n let color = colorFunctions.get(level)\n if (!color) color = noColor\n\n const date = new Date()\n const log = [\n bgBrightMagenta(black(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)),\n color(prefixes.get(level) ?? 'DEBUG'),\n name ? `${name} >` : '>',\n ...args,\n ]\n\n switch (level) {\n case LogLevels.Debug:\n return console.debug(...log)\n case LogLevels.Info:\n return console.info(...log)\n case LogLevels.Warn:\n return console.warn(...log)\n case LogLevels.Error:\n return console.error(...log)\n case LogLevels.Fatal:\n return console.error(...log)\n default:\n return console.log(...log)\n }\n }\n\n function setLevel(level: LogLevels) {\n logLevel = level\n }\n\n function setDepth(level: LogDepth) {\n depth = level\n }\n\n function debug(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Debug, args[0])\n else log(LogLevels.Debug, ...args)\n }\n\n function info(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Info, args[0])\n else log(LogLevels.Info, ...args)\n }\n\n function warn(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Warn, args[0])\n else log(LogLevels.Warn, ...args)\n }\n\n function error(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Error, args[0])\n else log(LogLevels.Error, ...args)\n }\n\n function fatal(...args: any[]) {\n if (LogDepth.Minimal === depth) log(LogLevels.Fatal, args[0])\n else log(LogLevels.Fatal, ...args)\n }\n\n return {\n log,\n setDepth,\n setLevel,\n debug,\n info,\n warn,\n error,\n fatal,\n }\n}\n\nexport const logger = createLogger({ name: 'Discordeno' })\nexport default logger\n"],"names":["bgBrightMagenta","black","bold","cyan","gray","italic","red","yellow","LogLevels","Debug","Info","Warn","Error","Fatal","LogDepth","Minimal","Full","prefixes","Map","noColor","msg","colorFunctions","str","createLogger","logLevel","name","depth","log","level","args","color","get","date","Date","toLocaleDateString","toLocaleTimeString","console","debug","info","warn","error","setLevel","setDepth","fatal","logger"],"mappings":"AAAA,kEAAkE,GAClE,mEAAmE,GACnE,SAASA,eAAe,EAAEC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,QAAQ,cAAa;WAEpF;UAAKC,SAAS;IAATA,UAAAA,UACVC,WAAAA,KAAAA;IADUD,UAAAA,UAEVE,UAAAA,KAAAA;IAFUF,UAAAA,UAGVG,UAAAA,KAAAA;IAHUH,UAAAA,UAIVI,WAAAA,KAAAA;IAJUJ,UAAAA,UAKVK,WAAAA,KAAAA;GALUL,cAAAA;WAQL;UAAKM,QAAQ;IAARA,SAAAA,SACVC,aAAAA,KAAAA;IADUD,SAAAA,SAEVE,UAAAA,KAAAA;GAFUF,aAAAA;AAKZ,MAAMG,WAAW,IAAIC,IAAuB;IAC1C;QAbAT;QA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CAK9D"}
1
+ {"version":3,"file":"urlToBase64.d.ts","sourceRoot":"","sources":["../src/urlToBase64.ts"],"names":[],"mappings":"AAGA,uFAAuF;AACvF,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9D"}
@@ -1,3 +1,4 @@
1
+ import fetch from 'node-fetch';
1
2
  import { encode } from './base64.js';
2
3
  /** Converts a url to base 64. Useful for example, uploading/creating server emojis. */ export async function urlToBase64(url) {
3
4
  const buffer = await fetch(url).then(async (res)=>await res.arrayBuffer());
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/urlToBase64.ts"],"sourcesContent":["import { encode } from './base64.js'\n\n/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */\nexport async function urlToBase64(url: string): Promise<string> {\n const buffer = await fetch(url).then(async (res) => await res.arrayBuffer())\n const imageStr = encode(buffer)\n const type = url.substring(url.lastIndexOf('.') + 1)\n return `data:image/${type};base64,${imageStr}`\n}\n"],"names":["encode","urlToBase64","url","buffer","fetch","then","res","arrayBuffer","imageStr","type","substring","lastIndexOf"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAa;AAEpC,qFAAqF,GACrF,OAAO,eAAeC,YAAYC,GAAW,EAAmB;IAC9D,MAAMC,SAAS,MAAMC,MAAMF,KAAKG,IAAI,CAAC,OAAOC,MAAQ,MAAMA,IAAIC,WAAW;IACzE,MAAMC,WAAWR,OAAOG;IACxB,MAAMM,OAAOP,IAAIQ,SAAS,CAACR,IAAIS,WAAW,CAAC,OAAO;IAClD,OAAO,CAAC,WAAW,EAAEF,KAAK,QAAQ,EAAED,SAAS,CAAC;AAChD,CAAC"}
1
+ {"version":3,"sources":["../src/urlToBase64.ts"],"sourcesContent":["import fetch from 'node-fetch'\nimport { encode } from './base64.js'\n\n/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */\nexport async function urlToBase64(url: string): Promise<string> {\n const buffer = await fetch(url).then(async (res) => await res.arrayBuffer())\n const imageStr = encode(buffer)\n const type = url.substring(url.lastIndexOf('.') + 1)\n return `data:image/${type};base64,${imageStr}`\n}\n"],"names":["fetch","encode","urlToBase64","url","buffer","then","res","arrayBuffer","imageStr","type","substring","lastIndexOf"],"mappings":"AAAA,OAAOA,WAAW,aAAY;AAC9B,SAASC,MAAM,QAAQ,cAAa;AAEpC,qFAAqF,GACrF,OAAO,eAAeC,YAAYC,GAAW,EAAmB;IAC9D,MAAMC,SAAS,MAAMJ,MAAMG,KAAKE,IAAI,CAAC,OAAOC,MAAQ,MAAMA,IAAIC,WAAW;IACzE,MAAMC,WAAWP,OAAOG;IACxB,MAAMK,OAAON,IAAIO,SAAS,CAACP,IAAIQ,WAAW,CAAC,OAAO;IAClD,OAAO,CAAC,WAAW,EAAEF,KAAK,QAAQ,EAAED,SAAS,CAAC;AAChD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQrD;AAID,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,WAAW,GAAG,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAGxH"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQrD;AAID,6DAA6D;AAE7D,wBAAgB,WAAW,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,WAAW,GAAG,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAGxH"}
package/dist/utils.js CHANGED
@@ -6,7 +6,8 @@
6
6
  }
7
7
  // Typescript is not so good as we developers so we need this little utility function to help it out
8
8
  // Taken from https://fettblog.eu/typescript-hasownproperty/
9
- /** TS save way to check if a property exists in an object */ export function hasProperty(obj, prop) {
9
+ /** TS save way to check if a property exists in an object */ // eslint-disable-next-line @typescript-eslint/ban-types
10
+ export function hasProperty(obj, prop) {
10
11
  // eslint-disable-next-line no-prototype-builtins
11
12
  return obj.hasOwnProperty(prop);
12
13
  }
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/** Pause the execution for a given amount of milliseconds. */\nexport async function delay(ms: number): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/return-await\n return new Promise(\n (resolve): NodeJS.Timeout =>\n setTimeout((): void => {\n resolve()\n }, ms),\n )\n}\n\n// Typescript is not so good as we developers so we need this little utility function to help it out\n// Taken from https://fettblog.eu/typescript-hasownproperty/\n/** TS save way to check if a property exists in an object */\nexport function hasProperty<T extends {}, Y extends PropertyKey = string>(obj: T, prop: Y): obj is T & Record<Y, unknown> {\n // eslint-disable-next-line no-prototype-builtins\n return obj.hasOwnProperty(prop)\n}\n"],"names":["delay","ms","Promise","resolve","setTimeout","hasProperty","obj","prop","hasOwnProperty"],"mappings":"AAAA,4DAA4D,GAC5D,OAAO,eAAeA,MAAMC,EAAU,EAAiB;IACrD,2DAA2D;IAC3D,OAAO,IAAIC,QACT,CAACC,UACCC,WAAW,IAAY;YACrBD;QACF,GAAGF;AAET,CAAC;AAED,oGAAoG;AACpG,4DAA4D;AAC5D,2DAA2D,GAC3D,OAAO,SAASI,YAA0DC,GAAM,EAAEC,IAAO,EAAiC;IACxH,iDAAiD;IACjD,OAAOD,IAAIE,cAAc,CAACD;AAC5B,CAAC"}
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/** Pause the execution for a given amount of milliseconds. */\nexport async function delay(ms: number): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/return-await\n return new Promise(\n (resolve): NodeJS.Timeout =>\n setTimeout((): void => {\n resolve()\n }, ms),\n )\n}\n\n// Typescript is not so good as we developers so we need this little utility function to help it out\n// Taken from https://fettblog.eu/typescript-hasownproperty/\n/** TS save way to check if a property exists in an object */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasProperty<T extends {}, Y extends PropertyKey = string>(obj: T, prop: Y): obj is T & Record<Y, unknown> {\n // eslint-disable-next-line no-prototype-builtins\n return obj.hasOwnProperty(prop)\n}\n"],"names":["delay","ms","Promise","resolve","setTimeout","hasProperty","obj","prop","hasOwnProperty"],"mappings":"AAAA,4DAA4D,GAC5D,OAAO,eAAeA,MAAMC,EAAU,EAAiB;IACrD,2DAA2D;IAC3D,OAAO,IAAIC,QACT,CAACC,UACCC,WAAW,IAAY;YACrBD;QACF,GAAGF;AAET,CAAC;AAED,oGAAoG;AACpG,4DAA4D;AAC5D,2DAA2D,GAC3D,wDAAwD;AACxD,OAAO,SAASI,YAA0DC,GAAM,EAAEC,IAAO,EAAiC;IACxH,iDAAiD;IACjD,OAAOD,IAAIE,cAAc,CAACD;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discordeno/utils",
3
- "version": "19.0.0-next.fc13bdf",
3
+ "version": "19.0.0-next.fd357ae",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -23,24 +23,25 @@
23
23
  "test:test-type": "tsc --project tsconfig.test.json"
24
24
  },
25
25
  "dependencies": {
26
- "@discordeno/types": "19.0.0-next.fc13bdf",
26
+ "@discordeno/types": "19.0.0-next.fd357ae",
27
+ "node-fetch": "^3.3.1",
27
28
  "tweetnacl": "^1.0.3"
28
29
  },
29
30
  "devDependencies": {
30
- "@swc/cli": "^0.1.57",
31
- "@swc/core": "^1.3.21",
32
- "@types/chai": "^4",
33
- "@types/mocha": "^10",
34
- "@types/node": "^18.11.15",
31
+ "@swc/cli": "^0.1.62",
32
+ "@swc/core": "^1.3.40",
33
+ "@types/chai": "^4.3.4",
34
+ "@types/mocha": "^10.0.1",
35
+ "@types/node": "^18.15.3",
35
36
  "@types/sinon": "^10.0.13",
36
- "c8": "^7.12.0",
37
+ "c8": "^7.13.0",
37
38
  "chai": "^4.3.7",
38
- "eslint": "^8.0.1",
39
+ "eslint": "^8.36.0",
39
40
  "eslint-config-discordeno": "*",
40
- "mocha": "^10.1.0",
41
- "sinon": "^15.0.0",
41
+ "mocha": "^10.2.0",
42
+ "sinon": "^15.0.2",
42
43
  "ts-node": "^10.9.1",
43
44
  "tsconfig": "*",
44
- "typescript": "^4.9.3"
45
+ "typescript": "^4.9.5"
45
46
  }
46
47
  }
package/dist/files.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { FileContent } from '@discordeno/types';
2
- export declare function findFiles(file: unknown): FileContent[];
3
- export declare function coerceToFileContent(value: unknown): value is FileContent;
4
- //# sourceMappingURL=files.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,EAAE,CAOtD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAyBxE"}
package/dist/files.js DELETED
@@ -1,41 +0,0 @@
1
- import { decode } from './base64.js';
2
- export function findFiles(file) {
3
- if (!file) {
4
- return [];
5
- }
6
- const files = Array.isArray(file) ? file : [
7
- file
8
- ];
9
- return files.filter(coerceToFileContent);
10
- }
11
- export function coerceToFileContent(value) {
12
- if (!value || typeof value !== 'object') {
13
- return false;
14
- }
15
- const file = value;
16
- if (typeof file.name !== 'string') {
17
- return false;
18
- }
19
- switch(typeof file.blob){
20
- case 'string':
21
- {
22
- const match = file.blob.match(/^data:(?<mimeType>[a-zA-Z0-9/]*);base64,(?<content>.*)$/);
23
- if (match?.groups === undefined) {
24
- return false;
25
- }
26
- const { mimeType , content } = match.groups;
27
- file.blob = new Blob([
28
- decode(content)
29
- ], {
30
- type: mimeType
31
- });
32
- return true;
33
- }
34
- case 'object':
35
- return file.blob instanceof Blob;
36
- default:
37
- return false;
38
- }
39
- }
40
-
41
- //# sourceMappingURL=files.js.map
package/dist/files.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/files.ts"],"sourcesContent":["import type { FileContent } from '@discordeno/types'\nimport { decode } from './base64.js'\n\nexport function findFiles(file: unknown): FileContent[] {\n if (!file) {\n return []\n }\n\n const files: unknown[] = Array.isArray(file) ? file : [file]\n return files.filter(coerceToFileContent)\n}\n\nexport function coerceToFileContent(value: unknown): value is FileContent {\n if (!value || typeof value !== 'object') {\n return false\n }\n\n const file = value as Record<string, unknown>\n if (typeof file.name !== 'string') {\n return false\n }\n\n switch (typeof file.blob) {\n case 'string': {\n const match = file.blob.match(/^data:(?<mimeType>[a-zA-Z0-9/]*);base64,(?<content>.*)$/)\n if (match?.groups === undefined) {\n return false\n }\n const { mimeType, content } = match.groups\n file.blob = new Blob([decode(content)], { type: mimeType })\n return true\n }\n case 'object':\n return file.blob instanceof Blob\n default:\n return false\n }\n}\n"],"names":["decode","findFiles","file","files","Array","isArray","filter","coerceToFileContent","value","name","blob","match","groups","undefined","mimeType","content","Blob","type"],"mappings":"AACA,SAASA,MAAM,QAAQ,cAAa;AAEpC,OAAO,SAASC,UAAUC,IAAa,EAAiB;IACtD,IAAI,CAACA,MAAM;QACT,OAAO,EAAE;IACX,CAAC;IAED,MAAMC,QAAmBC,MAAMC,OAAO,CAACH,QAAQA,OAAO;QAACA;KAAK;IAC5D,OAAOC,MAAMG,MAAM,CAACC;AACtB,CAAC;AAED,OAAO,SAASA,oBAAoBC,KAAc,EAAwB;IACxE,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAO,KAAK;IACd,CAAC;IAED,MAAMN,OAAOM;IACb,IAAI,OAAON,KAAKO,IAAI,KAAK,UAAU;QACjC,OAAO,KAAK;IACd,CAAC;IAED,OAAQ,OAAOP,KAAKQ,IAAI;QACtB,KAAK;YAAU;gBACb,MAAMC,QAAQT,KAAKQ,IAAI,CAACC,KAAK,CAAC;gBAC9B,IAAIA,OAAOC,WAAWC,WAAW;oBAC/B,OAAO,KAAK;gBACd,CAAC;gBACD,MAAM,EAAEC,SAAQ,EAAEC,QAAO,EAAE,GAAGJ,MAAMC,MAAM;gBAC1CV,KAAKQ,IAAI,GAAG,IAAIM,KAAK;oBAAChB,OAAOe;iBAAS,EAAE;oBAAEE,MAAMH;gBAAS;gBACzD,OAAO,IAAI;YACb;QACA,KAAK;YACH,OAAOZ,KAAKQ,IAAI,YAAYM;QAC9B;YACE,OAAO,KAAK;IAChB;AACF,CAAC"}