@discordeno/utils 19.0.0-next.f15ef49 → 19.0.0-next.f2b6590
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/dist/bucket.d.ts +2 -0
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +18 -14
- package/dist/bucket.js.map +1 -1
- package/dist/images.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +8 -8
- package/dist/logger.js.map +1 -1
- package/dist/urlToBase64.d.ts.map +1 -1
- package/dist/urlToBase64.js +1 -0
- package/dist/urlToBase64.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/package.json +14 -13
package/dist/bucket.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export declare class LeakyBucket implements LeakyBucketOptions {
|
|
|
16
16
|
constructor(options?: LeakyBucketOptions);
|
|
17
17
|
/** The amount of requests that still remain. */
|
|
18
18
|
get remaining(): number;
|
|
19
|
+
/** Refills the bucket as needed. */
|
|
20
|
+
refillBucket(): void;
|
|
19
21
|
/** Begin processing the queue. */
|
|
20
22
|
processQueue(): Promise<void>;
|
|
21
23
|
/** Pauses the execution until the request is available to be made. */
|
package/dist/bucket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,E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YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
package/dist/bucket.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import logger from './logger.js';
|
|
2
2
|
import { delay } from './utils.js';
|
|
3
3
|
export class LeakyBucket {
|
|
4
|
-
/** The amount of requests that have been used up already. */ used = 0;
|
|
5
|
-
/** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */ queue = [];
|
|
6
|
-
/** Whether or not the queue is already processing. */ processing = false;
|
|
7
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
8
|
this.max = options?.max ?? 1;
|
|
9
9
|
this.refillAmount = options?.refillAmount ? options.refillAmount > this.max ? this.max : options.refillAmount : 1;
|
|
10
10
|
this.refillInterval = options?.refillInterval ?? 5000;
|
|
@@ -12,13 +12,23 @@ export class LeakyBucket {
|
|
|
12
12
|
/** The amount of requests that still remain. */ get remaining() {
|
|
13
13
|
return this.max < this.used ? 0 : this.max - this.used;
|
|
14
14
|
}
|
|
15
|
+
/** Refills the bucket as needed. */ refillBucket() {
|
|
16
|
+
console.log('refilling bucket');
|
|
17
|
+
logger.info(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`);
|
|
18
|
+
// Lower the used amount by the refill amount
|
|
19
|
+
this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
|
|
20
|
+
// Reset the refillsAt timestamp since it just got refilled
|
|
21
|
+
this.refillsAt = undefined;
|
|
22
|
+
if (this.used > 0) {
|
|
23
|
+
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
24
|
+
this.timeoutId = setTimeout(()=>this.refillBucket, this.refillInterval);
|
|
25
|
+
this.refillsAt = Date.now() + this.refillInterval;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
/** Begin processing the queue. */ async processQueue() {
|
|
16
29
|
logger.debug('[Gateway] Processing queue');
|
|
17
30
|
// There is already a queue that is processing
|
|
18
|
-
if (this.processing)
|
|
19
|
-
logger.debug('[Gateway] Queue is already processing.');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
31
|
+
if (this.processing) return logger.debug('[Gateway] Queue is already processing.');
|
|
22
32
|
// Begin going through the queue.
|
|
23
33
|
while(this.queue.length){
|
|
24
34
|
if (this.remaining) {
|
|
@@ -30,13 +40,7 @@ export class LeakyBucket {
|
|
|
30
40
|
// Create a new timeout for this request if none exists.
|
|
31
41
|
if (!this.timeoutId) {
|
|
32
42
|
logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`);
|
|
33
|
-
this.timeoutId = setTimeout(()=>
|
|
34
|
-
logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`);
|
|
35
|
-
// Lower the used amount by the refill amount
|
|
36
|
-
this.used -= this.refillAmount;
|
|
37
|
-
// Reset the refillsAt timestamp since it just got refilled
|
|
38
|
-
this.refillsAt = undefined;
|
|
39
|
-
}, this.refillInterval);
|
|
43
|
+
this.timeoutId = setTimeout(()=>this.refillBucket, this.refillInterval);
|
|
40
44
|
// Set the time for when this refill will occur.
|
|
41
45
|
this.refillsAt = Date.now() + this.refillInterval;
|
|
42
46
|
}
|
package/dist/bucket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 /** 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)
|
|
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 console.log('refilling bucket');\n logger.info(`[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(() => this.refillBucket, 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(() => this.refillBucket, 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","console","log","info","refillsAt","undefined","timeoutId","clearTimeout","setTimeout","Date","now","processQueue","deb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IAAIC,QAAQ,CAACC,UAAY;YACpC,6DAA6D;YAC7D,IAAIF,cAAc,IAAI,CAACtB,KAAK,CAACyB,OAAO,CAACD;iBAEhC,IAAI,CAACxB,KAAK,CAAC0B,IAAI,CAACF;YAErB,0DAA0D;YAC1D,KAAK,IAAI,CAACP,YAAY;QACxB;IACF;AACF,CAAC"}
|
package/dist/images.js.map
CHANGED
|
@@ -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://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,
|
|
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,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,QAAQC,MAAM,KAAK,WAAWD,QAAQC,MAAM,GAAGb,iBAAiBY,QAAQC,MAAM,CAAC,CAAC,CAAC,EACxID,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"}
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
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
|
|
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(...
|
|
75
|
+
return console.debug(...log1);
|
|
76
76
|
case 1:
|
|
77
|
-
return console.info(...
|
|
77
|
+
return console.info(...log1);
|
|
78
78
|
case 2:
|
|
79
|
-
return console.warn(...
|
|
79
|
+
return console.warn(...log1);
|
|
80
80
|
case 3:
|
|
81
|
-
return console.error(...
|
|
81
|
+
return console.error(...log1);
|
|
82
82
|
case 4:
|
|
83
|
-
return console.error(...
|
|
83
|
+
return console.error(...log1);
|
|
84
84
|
default:
|
|
85
|
-
return console.log(...
|
|
85
|
+
return console.log(...log1);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
function setLevel(level) {
|
package/dist/logger.js.map
CHANGED
|
@@ -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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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;QAakB;KAAQ;IAC1B;QAbAC;QAaiB;KAAO;IACxB;QAbAC;QAaiB;KAAO;IACxB;QAbAC;QAakB;K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J,WAAWI;IACb;IAEA,SAASc,SAASd,KAAe,EAAE;QACjCF,QAAQE;IACV;IAEA,SAASS,MAAM,GAAGR,IAAW,EAAE;QAC7B,IAAIf,AArENC,MAqE2BW,OAAOC,IA7ElClB,GA6EuDoB,IAAI,CAAC,EAAE;aACvDF,IA9EPlB,MA8E+BoB;IAC/B;IAEA,SAASS,KAAK,GAAGT,IAAW,EAAE;QAC5B,IAAIf,AA1ENC,MA0E2BW,OAAOC,IAjFlCjB,GAiFsDmB,IAAI,CAAC,EAAE;aACtDF,IAlFPjB,MAkF8BmB;IAC9B;IAEA,SAASU,KAAK,GAAGV,IAAW,EAAE;QAC5B,IAAIf,AA/ENC,MA+E2BW,OAAOC,IArFlChB,GAqFsDkB,IAAI,CAAC,EAAE;aACtDF,IAtFPhB,MAsF8BkB;IAC9B;IAEA,SAASW,MAAM,GAAGX,IAAW,EAAE;QAC7B,IAAIf,AApFNC,MAoF2BW,OAAOC,IAzFlCf,GAyFuDiB,IAAI,CAAC,EAAE;aACvDF,IA1FPf,MA0F+BiB;IAC/B;IAEA,SAASc,MAAM,GAAGd,IAAW,EAAE;QAC7B,IAAIf,AAzFNC,MAyF2BW,OAAOC,IA7FlCd,GA6FuDgB,IAAI,CAAC,EAAE;aACvDF,IA9FPd,MA8F+BgB;IAC/B;IAEA,OAAO;QACLF;QACAe;QACAD;QACAJ;QACAC;QACAC;QACAC;QACAG;IACF;AACF,CAAC;AAED,OAAO,MAAMC,SAASrB,aAAa;IAAEE,MAAM;AAAa,GAAE;AAC1D,eAAemB,OAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlToBase64.d.ts","sourceRoot":"","sources":["../src/urlToBase64.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/urlToBase64.js
CHANGED
|
@@ -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());
|
package/dist/urlToBase64.js.map
CHANGED
|
@@ -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","
|
|
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"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -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;
|
|
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 */
|
|
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.
|
|
3
|
+
"version": "19.0.0-next.f2b6590",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -16,31 +16,32 @@
|
|
|
16
16
|
"fmt": "eslint --fix \"src/**/*.ts*\"",
|
|
17
17
|
"lint": "eslint \"src/**/*.ts*\"",
|
|
18
18
|
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
|
|
19
|
-
"test:unit": "c8 --r lcov mocha --no-warnings 'tests
|
|
19
|
+
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/bucket.spec.ts' && node ../../scripts/coveragePathFixing.js utils",
|
|
20
20
|
"test:deno-unit": "swc tests --delete-dir-on-start -C jsc.minify.mangle=false --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
|
|
21
21
|
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
|
|
22
22
|
"test:type": "tsc --noEmit",
|
|
23
23
|
"test:test-type": "tsc --project tsconfig.test.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@discordeno/types": "19.0.0-next.
|
|
26
|
+
"@discordeno/types": "19.0.0-next.f2b6590",
|
|
27
|
+
"node-fetch": "^3.3.1",
|
|
27
28
|
"tweetnacl": "^1.0.3"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@swc/cli": "^0.1.
|
|
31
|
-
"@swc/core": "^1.3.
|
|
32
|
-
"@types/chai": "^4",
|
|
33
|
-
"@types/mocha": "^10",
|
|
34
|
-
"@types/node": "^18.
|
|
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.
|
|
37
|
+
"c8": "^7.13.0",
|
|
37
38
|
"chai": "^4.3.7",
|
|
38
|
-
"eslint": "^8.0
|
|
39
|
+
"eslint": "^8.36.0",
|
|
39
40
|
"eslint-config-discordeno": "*",
|
|
40
|
-
"mocha": "^10.
|
|
41
|
-
"sinon": "^15.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.
|
|
45
|
+
"typescript": "^4.9.5"
|
|
45
46
|
}
|
|
46
47
|
}
|