@discordeno/utils 19.0.0-next.40c19da → 19.0.0-next.40eaf17

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.github.io/discordeno/)
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
@@ -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. */
@@ -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,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;IA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cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
package/dist/bucket.js CHANGED
@@ -12,13 +12,24 @@ 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
+ 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
+ }
15
29
  /** Begin processing the queue. */ async processQueue() {
16
30
  logger.debug('[Gateway] Processing queue');
17
31
  // There is already a queue that is processing
18
- if (this.processing) {
19
- logger.debug('[Gateway] Queue is already processing.');
20
- return;
21
- }
32
+ if (this.processing) return logger.debug('[Gateway] Queue is already processing.');
22
33
  // Begin going through the queue.
23
34
  while(this.queue.length){
24
35
  if (this.remaining) {
@@ -31,11 +42,7 @@ export class LeakyBucket {
31
42
  if (!this.timeoutId) {
32
43
  logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`);
33
44
  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;
45
+ this.refillBucket();
39
46
  }, this.refillInterval);
40
47
  // Set the time for when this refill will occur.
41
48
  this.refillsAt = Date.now() + this.refillInterval;
@@ -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) {\n logger.debug('[Gateway] Queue is already processing.')\n return\n }\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 this.timeoutId = setTimeout(() => {\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\n // Reset the refillsAt timestamp since it just got refilled\n this.refillsAt = undefined\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","processQueue","debug","length","shift","timeoutId","setTimeout","refillsAt","undefined","Date","now","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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BACtG,MAAMpB,MAAM,IAAI,CAACiB,SAAS,GAAGG;oBAC7BrB,OAAOa,KAAK,CAAC,CAAC,gCAAgC,CAAC;gBACjD,CAAC;YACH,CAAC;QACH;QAEA,gEAAgE;QAChE,IAAI,CAACN,UAAU,GAAG,KAAK;IACzB;IAEA,oEAAoE,GACpE,MAAMe,QAAQC,YAAsB,EAAiB;QACnD,OAAO,MAAM,IAAIC,QAAQ,CAACC,UAAY;YACpC,6DAA6D;YAC7D,IAAIF,cAAc,IAAI,CAACjB,KAAK,CAACoB,OAAO,CAACD;iBAEhC,IAAI,CAACnB,KAAK,CAACqB,IAAI,CAACF;YAErB,0DAA0D;YAC1D,KAAK,IAAI,CAACb,YAAY;QACxB;IACF;AACF,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,IAAI,CAACJ,IAAI,GAAG,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACI,YAAY;QAC7E,2DAA2D;QAC3D,IAAI,CAACK,SAAS,GAAGC;QAEjB,IAAI,IAAI,CAACV,IAAI,GAAG,GAAG;YACjB,IAAI,IAAI,CAACW,SAAS,EAAEC,aAAa,IAAI,CAACD,SAAS;YAC/C,IAAI,CAACA,SAAS,GAAGE,WAAW,IAAM;gBAChC,IAAI,CAACN,YAAY;YACnB,GA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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,CAcrD;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"}
@@ -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[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,SAAaC,MAAS,EAAe;IACnD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,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,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","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, 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,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ACvB;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,IAAIA,UAAU,IAAI;AAElB;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,KAAc,EAAE;IAC9CF,UAAUE;AACZ,CAAC;AAED,0DAA0D,GAC1D,OAAO,SAASC,kBAA2B;IACzC,OAAOH;AACT,CAAC;AAED;;;;CAIC,GACD,SAASI,KAAKC,IAAc,EAAEC,KAAa,EAAQ;IACjD,OAAO;QACLD,MAAM,CAAC,KAAK,EAAEA,KAAKE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/BD,OAAO,CAAC,KAAK,EAAEA,MAAM,CAAC,CAAC;QACvBE,QAAQ,IAAIC,OAAO,CAAC,QAAQ,EAAEH,MAAM,CAAC,CAAC,EAAE;IAC1C;AACF;AAEA;;;;CAIC,GACD,SAASI,IAAIC,GAAW,EAAEP,IAAU,EAAU;IAC5C,OAAOJ,UAAU,CAAC,EAAEI,KAAKC,IAAI,CAAC,EAAEM,IAAIC,OAAO,CAACR,KAAKI,MAAM,EAAEJ,KAAKC,IAAI,EAAE,EAAED,KAAKE,KAAK,CAAC,CAAC,GAAGK,GAAG;AAC1F;AAEA;;;CAGC,GACD,OAAO,SAASE,MAAMF,GAAW,EAAU;IACzC,OAAOD,IAAIC,KAAKP,KAAK;QAAC;KAAE,EAAE;AAC5B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASU,KAAKH,GAAW,EAAU;IACxC,OAAOD,IAAIC,KAAKP,KAA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ection.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"}
@@ -0,0 +1,3 @@
1
+ import { type DiscordInteraction } from '@discordeno/types';
2
+ export declare function commandOptionsParser(interaction: DiscordInteraction, options?: NonNullable<DiscordInteraction['data']>['options']): Record<string, any>;
3
+ //# sourceMappingURL=interactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../src/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE1F,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAwCvJ"}
@@ -0,0 +1,41 @@
1
+ import { ApplicationCommandOptionTypes } from '@discordeno/types';
2
+ export function commandOptionsParser(interaction, options) {
3
+ if (!interaction.data) return {};
4
+ if (!options) options = interaction.data.options ?? [];
5
+ const args = {};
6
+ for (const option of options){
7
+ switch(option.type){
8
+ case ApplicationCommandOptionTypes.SubCommandGroup:
9
+ case ApplicationCommandOptionTypes.SubCommand:
10
+ args[option.name] = commandOptionsParser(interaction, option.options);
11
+ break;
12
+ case ApplicationCommandOptionTypes.Channel:
13
+ args[option.name] = interaction.data.resolved?.channels?.[option.value];
14
+ break;
15
+ case ApplicationCommandOptionTypes.Role:
16
+ args[option.name] = interaction.data.resolved?.roles?.[option.value];
17
+ break;
18
+ case ApplicationCommandOptionTypes.User:
19
+ args[option.name] = {
20
+ user: interaction.data.resolved?.users?.[option.value],
21
+ member: interaction.data.resolved?.members?.[option.value]
22
+ };
23
+ break;
24
+ case ApplicationCommandOptionTypes.Attachment:
25
+ args[option.name] = interaction.data.resolved?.attachments?.[option.value];
26
+ break;
27
+ case ApplicationCommandOptionTypes.Mentionable:
28
+ // Mentionable are roles or users
29
+ args[option.name] = interaction.data.resolved?.roles?.[option.value] ?? {
30
+ user: interaction.data.resolved?.users?.[option.value],
31
+ member: interaction.data.resolved?.members?.[option.value]
32
+ };
33
+ break;
34
+ default:
35
+ args[option.name] = option.value;
36
+ }
37
+ }
38
+ return args;
39
+ }
40
+
41
+ //# sourceMappingURL=interactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/interactions.ts"],"sourcesContent":["import { ApplicationCommandOptionTypes, type DiscordInteraction } from '@discordeno/types'\n\nexport function commandOptionsParser(interaction: DiscordInteraction, options?: NonNullable<DiscordInteraction['data']>['options']): Record<string, any> {\n if (!interaction.data) return {}\n if (!options) options = interaction.data.options ?? []\n\n const args: Record<string, any> = {}\n\n for (const option of options) {\n switch (option.type) {\n case ApplicationCommandOptionTypes.SubCommandGroup:\n case ApplicationCommandOptionTypes.SubCommand:\n args[option.name] = commandOptionsParser(interaction, option.options)\n break\n case ApplicationCommandOptionTypes.Channel:\n args[option.name] = interaction.data.resolved?.channels?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.Role:\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.User:\n args[option.name] = {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n case ApplicationCommandOptionTypes.Attachment:\n args[option.name] = interaction.data.resolved?.attachments?.[option.value as string]\n break;\n case ApplicationCommandOptionTypes.Mentionable:\n // Mentionable are roles or users\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string] ?? {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n default:\n args[option.name] = option.value\n }\n }\n\n return args\n}\n"],"names":["ApplicationCommandOptionTypes","commandOptionsParser","interaction","options","data","args","option","type","SubCommandGroup","SubCommand","name","Channel","resolved","channels","value","Role","roles","User","user","users","member","members","Attachment","attachments","Mentionable"],"mappings":"AAAA,SAASA,6BAA6B,QAAiC,oBAAmB;AAE1F,OAAO,SAASC,qBAAqBC,WAA+B,EAAEC,OAA4D,EAAuB;IACvJ,IAAI,CAACD,YAAYE,IAAI,EAAE,OAAO,CAAC;IAC/B,IAAI,CAACD,SAASA,UAAUD,YAAYE,IAAI,CAACD,OAAO,IAAI,EAA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ChEM,QAAQlB,YAAYE,IAAI,CAACQ,QAAQ,EAAES,SAAS,CAACf,OAAOQ,KAAK,CAAW;gBACtE;gBACA,KAAK;YACP;gBACET,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGJ,OAAOQ,KAAK;QACpC;IACF;IAEA,OAAOT;AACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discordeno/utils",
3
- "version": "19.0.0-next.40c19da",
3
+ "version": "19.0.0-next.40eaf17",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "test:test-type": "tsc --project tsconfig.test.json"
24
24
  },
25
25
  "dependencies": {
26
- "@discordeno/types": "19.0.0-next.40c19da",
26
+ "@discordeno/types": "19.0.0-next.40eaf17",
27
27
  "node-fetch": "^3.3.1",
28
28
  "tweetnacl": "^1.0.3"
29
29
  },
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"}