@discordeno/utils 19.0.0-next.b6fec9c → 19.0.0-next.bccbc73

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.
Files changed (61) hide show
  1. package/README.md +6 -10
  2. package/dist/Collection.js +113 -2
  3. package/dist/Collection.js.map +1 -0
  4. package/dist/base64.js +262 -2
  5. package/dist/base64.js.map +1 -0
  6. package/dist/bucket.d.ts +36 -42
  7. package/dist/bucket.d.ts.map +1 -1
  8. package/dist/bucket.js +76 -2
  9. package/dist/bucket.js.map +1 -0
  10. package/dist/casing.d.ts +4 -2
  11. package/dist/casing.d.ts.map +1 -1
  12. package/dist/casing.js +51 -2
  13. package/dist/casing.js.map +1 -0
  14. package/dist/colors.d.ts +275 -0
  15. package/dist/colors.d.ts.map +1 -0
  16. package/dist/colors.js +467 -0
  17. package/dist/colors.js.map +1 -0
  18. package/dist/hash.d.ts.map +1 -1
  19. package/dist/hash.js +19 -2
  20. package/dist/hash.js.map +1 -0
  21. package/dist/images.d.ts +47 -2
  22. package/dist/images.d.ts.map +1 -1
  23. package/dist/images.js +66 -2
  24. package/dist/images.js.map +1 -0
  25. package/dist/index.d.ts +7 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +18 -2
  28. package/dist/index.js.map +1 -0
  29. package/dist/interactions.d.ts +3 -0
  30. package/dist/interactions.d.ts.map +1 -0
  31. package/dist/interactions.js +41 -0
  32. package/dist/interactions.js.map +1 -0
  33. package/dist/logger.d.ts +36 -0
  34. package/dist/logger.d.ts.map +1 -0
  35. package/dist/logger.js +130 -0
  36. package/dist/logger.js.map +1 -0
  37. package/dist/oauth2.d.ts +58 -0
  38. package/dist/oauth2.d.ts.map +1 -0
  39. package/dist/oauth2.js +16 -0
  40. package/dist/oauth2.js.map +1 -0
  41. package/dist/permissions.js +17 -2
  42. package/dist/permissions.js.map +1 -0
  43. package/dist/reactions.d.ts +3 -0
  44. package/dist/reactions.d.ts.map +1 -0
  45. package/dist/reactions.js +11 -0
  46. package/dist/reactions.js.map +1 -0
  47. package/dist/token.d.ts +1 -1
  48. package/dist/token.d.ts.map +1 -1
  49. package/dist/token.js +21 -2
  50. package/dist/token.js.map +1 -0
  51. package/dist/typeguards.d.ts +6 -0
  52. package/dist/typeguards.d.ts.map +1 -0
  53. package/dist/typeguards.js +15 -0
  54. package/dist/typeguards.js.map +1 -0
  55. package/dist/urlToBase64.js +9 -2
  56. package/dist/urlToBase64.js.map +1 -0
  57. package/dist/utils.d.ts +2 -3
  58. package/dist/utils.d.ts.map +1 -1
  59. package/dist/utils.js +15 -2
  60. package/dist/utils.js.map +1 -0
  61. package/package.json +12 -12
package/dist/bucket.js CHANGED
@@ -1,2 +1,76 @@
1
- import{delay as t}from"./utils.js";export function createLeakyBucket({max:t,refillInterval:l,refillAmount:n,tokens:a,waiting:r,...o}){return{max:t,refillInterval:l,refillAmount:n>t?t:n,lastRefill:performance.now(),allowAcquire:!0,nextRefill:function(){return e(this),performance.now()-this.lastRefill+this.refillInterval},tokens:function(){return e(this)},acquire:async function(t,e){return await i(this,t,e)},tokensState:a??t,waiting:r??[],...o}}function e(t){let e=performance.now()-t.lastRefill,i=Math.floor(e/t.refillInterval);return t.tokensState=Math.min(t.tokensState+t.refillAmount*i,t.max),t.lastRefill+=t.refillInterval*i,t.tokensState}async function i(l,n,a=!1){if(!l.allowAcquire&&(await new Promise(t=>{a?l.waiting.unshift(t):l.waiting.push(t)}),!l.allowAcquire))return await i(l,n);l.allowAcquire=!1;let r=e(l);if(r<n){let o=Math.ceil((n-r)/l.refillAmount),f=l.refillInterval*o;await t(f),e(l)}let u=(n%l.refillAmount)??n;l.tokensState-=u,l.allowAcquire=!0,l.waiting.shift()?.()}
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9idWNrZXQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBQaWNrUGFydGl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BT0ksV0FBVyxBQUMzQixDQVNBLGVBQWVILEVBQVNELENBQW1CLENBQUVFLENBQWMsQ0FBRUMsRUFBZSxDQUFBLENBQUssQ0FBaUIsQ0FHaEcsR0FBSSxDQUFDSCxFQUFPSCxZQUFZLEdBRXRCLE1BQU0sSUFBSWEsUUFBUSxBQUFDQyxHQUFZLENBQ3pCUixFQUNGSCxFQUFPUixPQUFPLENBQUNvQixPQUFPLENBQUNELEdBRXZCWCxFQUFPUixPQUFPLENBQUNxQixJQUFJLENBQUNGLEVBRXhCLEdBSUksQ0FBQ1gsRUFBT0gsWUFBWSxFQUN0QixPQUFPLE1BQU1JLEVBQVFELEVBQVFFLEVBRWhDLEFBRURGLENBQUFBLEVBQU9ILFlBQVksQ0FBRyxDQUFBLEVBR3RCLElBQU1pQixFQUFnQmYsRUFBYUMsR0FJbkMsR0FBSWMsRUFBZ0JaLEVBQVEsQ0FFMUIsSUFBTWEsRUFBZ0JSLEtBQUtTLElBQUksQ0FBQ0MsQUFEWGYsQ0FBQUEsRUFBU1ksQ0FBWSxFQUNLZCxFQUFPVixZQUFZLEVBRTVENEIsRUFBV2xCLEVBQU9YLGNBQWMsQ0FBRzBCLENBQ3pDLE9BQU03QixFQUFNZ0MsR0FHWm5CLEVBQWFDLEVBQ2YsQ0FBQyxBQUlELElBQU1tQixFQUFhakIsQ0FBQUEsRUFBU0YsRUFBT1YsWUFBWSxBQUFELEdBQUtZLENBQ25ERixDQUFBQSxFQUFPSSxXQUFXLEVBQUllLEVBR3RCbkIsRUFBT0gsWUFBWSxDQUFHLENBQUEsRUFFdEJHLEVBQU9SLE9BQU8sQ0FBQzRCLEtBQUssTUFDdEIifQ==
1
+ import logger from './logger.js';
2
+ import { delay } from './utils.js';
3
+ export class LeakyBucket {
4
+ constructor(options){
5
+ /** The amount of requests that have been used up already. */ this.used = 0;
6
+ /** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */ this.queue = [];
7
+ /** Whether or not the queue is already processing. */ this.processing = false;
8
+ this.max = options?.max ?? 1;
9
+ this.refillAmount = options?.refillAmount ? options.refillAmount > this.max ? this.max : options.refillAmount : 1;
10
+ this.refillInterval = options?.refillInterval ?? 5000;
11
+ }
12
+ /** The amount of requests that still remain. */ get remaining() {
13
+ return this.max < this.used ? 0 : this.max - this.used;
14
+ }
15
+ /** Refills the bucket as needed. */ refillBucket() {
16
+ logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`);
17
+ // Lower the used amount by the refill amount
18
+ this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
19
+ // Reset the refillsAt timestamp since it just got refilled
20
+ this.refillsAt = undefined;
21
+ // Reset the timeoutId
22
+ clearTimeout(this.timeoutId);
23
+ this.timeoutId = undefined;
24
+ if (this.used > 0) {
25
+ this.timeoutId = setTimeout(()=>{
26
+ this.refillBucket();
27
+ }, this.refillInterval);
28
+ this.refillsAt = Date.now() + this.refillInterval;
29
+ }
30
+ }
31
+ /** Begin processing the queue. */ async processQueue() {
32
+ logger.debug('[Gateway] Processing queue');
33
+ // There is already a queue that is processing
34
+ if (this.processing) return logger.debug('[Gateway] Queue is already processing.');
35
+ // Begin going through the queue.
36
+ while(this.queue.length){
37
+ if (this.remaining) {
38
+ logger.debug(`[LeakyBucket] Processing queue. Remaining: ${this.remaining} Length: ${this.queue.length}`);
39
+ // Resolves the promise allowing the paused execution of this request to resolve and continue.
40
+ this.queue.shift()?.();
41
+ // A request can be made
42
+ this.used++;
43
+ // Create a new timeout for this request if none exists.
44
+ if (!this.timeoutId) {
45
+ logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`);
46
+ this.timeoutId = setTimeout(()=>{
47
+ this.refillBucket();
48
+ }, this.refillInterval);
49
+ // Set the time for when this refill will occur.
50
+ this.refillsAt = Date.now() + this.refillInterval;
51
+ }
52
+ } else if (this.refillsAt) {
53
+ const now = Date.now();
54
+ // If there is time left until next refill, just delay execution.
55
+ if (this.refillsAt > now) {
56
+ logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for ${this.refillsAt - now}ms`);
57
+ await delay(this.refillsAt - now);
58
+ logger.debug(`[LeakyBucket] Resuming execution`);
59
+ }
60
+ }
61
+ }
62
+ // Loop has ended mark false so it can restart later when needed
63
+ this.processing = false;
64
+ }
65
+ /** Pauses the execution until the request is available to be made. */ async acquire(highPriority) {
66
+ return await new Promise((resolve)=>{
67
+ // High priority requests get added to the start of the queue
68
+ if (highPriority) this.queue.unshift(resolve);
69
+ else this.queue.push(resolve);
70
+ // Each request should trigger the queue to be processesd.
71
+ void this.processQueue();
72
+ });
73
+ }
74
+ }
75
+
76
+ //# sourceMappingURL=bucket.js.map
@@ -0,0 +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 /** 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 // Reset the timeoutId\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined;\n\n if (this.used > 0) {\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","clearTimeout","timeoutId","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;QACjB,sBAAsB;QACtBC,aAAa,IAAI,CAACC,SAAS;QAC3B,IAAI,CAACA,SAAS,GAAGF;QAEjB,IAAI,IAAI,CAACV,IAAI,GAAG,GAAG;YACjB,IAAI,CAACY,SAAS,GAAGC,WAAW,IAAM;gBAChC,IAAI,CAACN,YAAY;YACnB,GAAG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H;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"}
package/dist/casing.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { Camelize } from '@discordeno/types';
2
- export declare const camelize: <T>(object: T) => Camelize<T>;
1
+ import type { Camelize, Snakelize } from '@discordeno/types';
2
+ export declare function camelize<T>(object: T): Camelize<T>;
3
+ export declare function snakelize<T>(object: T): Snakelize<T>;
3
4
  export declare function snakeToCamelCase(str: string): string;
5
+ export declare function camelToSnakeCase(str: string): string;
4
6
  //# sourceMappingURL=casing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../src/casing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,eAAO,MAAM,QAAQ,+BAcpB,CAAA;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAepD"}
1
+ {"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../src/casing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE5D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAclD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAcpD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAepD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAapD"}
package/dist/casing.js CHANGED
@@ -1,2 +1,51 @@
1
- export const camelize=e=>{if(Array.isArray(e))return e.map(e=>camelize(e));if("object"==typeof e&&null!==e){let r={};return Object.keys(e).forEach(t=>{r["string"==typeof t?snakeToCamelCase(t):t]=camelize(e[t])}),r}return e};export function snakeToCamelCase(e){if(!e.includes("_"))return e;let r="";for(let t=0,n=e.length;t<n;++t){if("_"===e[t]){r+=e[++t].toUpperCase();continue}r+=e[t]}return r}
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jYXNpbmcudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBDYW1lbGl6ZSB9IGZyb20gJ0BkaXNjb3JkZW5vL3R5cGVzJ1xuXG5leHBvcnQgY29uc3QgY2FtZWxpemUgPSA8VD4ob2JqZWN0OiBUKTogQ2FtZWxpemU8VD4gPT4ge1xuICBpZiAoQXJyYXkuaXNBcnJheShvYmplY3QpKSB7XG4gICAgcmV0dXJuIG9iamVjdC5tYXAoKGVsZW1lbnQpID0+IGNhbWVsaXplKGVsZW1lbnQpKSBhcyBDYW1lbGl6ZTxUPlxuICB9XG5cbiAgaWYgKHR5cGVvZiBvYmplY3QgPT09ICdvYmplY3QnICYmIG9iamVjdCAhPT0gbnVsbCkge1xuICAgIGNvbnN0IG9iaiA9IHt9IGFzIENhbWVsaXplPFQ+XG4gICAgOyhPYmplY3Qua2V5cyhvYmplY3QpIGFzIEFycmF5PGtleW9mIFQ+KS5mb3JFYWNoKChrZXkpID0+IHtcbiAgICAgIC8vIEB0cy1leHBlY3QtZXJyb3JcbiAgICAgIDsob2JqW3R5cGVvZiBrZXkgPT09ICdzdHJpbmcnID8gc25ha2VUb0NhbWVsQ2FzZShrZXkpIDo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UIsQ0FDakQsSUFBTUssRUFBTSxDQUFDLEVBS2IsT0FKQyxBQUFDQyxPQUFPQyxJQUFJLENBQUNQLEdBQTJCUSxPQUFPLENBQUMsQUFBQ0MsR0FBUSxDQUV0REosQ0FBRyxDQUFDLEFBQWUsVUFBZixPQUFPSSxFQUFtQkMsaUJBQWlCRCxHQUFPQSxDQUFHLENBQUMsQ0FBdUNWLFNBQVNDLENBQU0sQ0FBQ1MsRUFBSSxDQUN6SCxHQUNPSixDQUNULENBQUMsQUFDRCxPQUFPTCxDQUNULENBQUMsQUFFRCxRQUFPLFNBQVNVLGlCQUFpQkMsQ0FBVyxDQUFVLENBQ3BELEdBQUksQ0FBQ0EsRUFBSUMsUUFBUSxDQUFDLEtBQU0sT0FBT0QsQ0FBRyxDQUVsQyxJQUFJRSxFQUFTLEdBQ2IsSUFBSyxJQUFJQyxFQUFJLEVBQUdDLEVBQU1KLEVBQUlLLE1BQU0sQ0FBRUYsRUFBSUMsRUFBSyxFQUFFRCxFQUFHLENBQzlDLEdBQUlILEFBQVcsTUFBWEEsQ0FBRyxDQUFDRyxFQUFFLENBQVUsQ0FDbEJELEdBQVVGLENBQUcsQ0FBQyxFQUFFRyxFQUFFLENBQUNHLFdBQVcsR0FFOUIsUUFBUSxBQUNWLENBQUMsQUFFREosR0FBVUYsQ0FBRyxDQUFDRyxFQUFFLEFBQ2xCLENBRUEsT0FBT0QsQ0FDVCxDQUFDIn0=
1
+ export function camelize(object) {
2
+ if (Array.isArray(object)) {
3
+ return object.map((element)=>camelize(element));
4
+ }
5
+ if (typeof object === 'object' && object !== null) {
6
+ const obj = {};
7
+ Object.keys(object).forEach((key)=>{
8
+ obj[snakeToCamelCase(key)] = camelize(object[key]);
9
+ });
10
+ return obj;
11
+ }
12
+ return object;
13
+ }
14
+ export function snakelize(object) {
15
+ if (Array.isArray(object)) {
16
+ return object.map((element)=>snakelize(element));
17
+ }
18
+ if (typeof object === 'object' && object !== null) {
19
+ const obj = {};
20
+ Object.keys(object).forEach((key)=>{
21
+ obj[camelToSnakeCase(key)] = snakelize(object[key]);
22
+ });
23
+ return obj;
24
+ }
25
+ return object;
26
+ }
27
+ export function snakeToCamelCase(str) {
28
+ if (!str.includes('_')) return str;
29
+ let result = '';
30
+ for(let i = 0, len = str.length; i < len; ++i){
31
+ if (str[i] === '_') {
32
+ result += str[++i].toUpperCase();
33
+ continue;
34
+ }
35
+ result += str[i];
36
+ }
37
+ return result;
38
+ }
39
+ export function camelToSnakeCase(str) {
40
+ let result = '';
41
+ for(let i = 0, len = str.length; i < len; ++i){
42
+ if (str[i] >= 'A' && str[i] <= 'Z') {
43
+ result += `_${str[i].toLowerCase()}`;
44
+ continue;
45
+ }
46
+ result += str[i];
47
+ }
48
+ return result;
49
+ }
50
+
51
+ //# sourceMappingURL=casing.js.map
@@ -0,0 +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,SAAYC,MAAS,EAAe;IAClD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYL,SAASK;IAC1C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAEtDJ,GAAG,CAACK,iBAAiBD,KAAK,GAAuCV,SAASC,MAAM,CAACS,IAAI;QACzF;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASW,UAAaX,MAAS,EAAgB;IACpD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYO,UAAUP;IAC3C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAEtDJ,GAAG,CAACO,iBAAiBH,KAAK,GAAwCE,UAAUX,MAAM,CAACS,IAAI;QAC3F;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASU,iBAAiBG,GAAW,EAAU;IACpD,IAAI,CAACA,IAAIC,QAAQ,CAAC,MAAM,OAAOD;IAE/B,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,KAAK,KAAK;YAClBD,UAAUF,GAAG,CAAC,EAAEG,EAAE,CAACG,WAAW;YAE9B,QAAQ;QACV,CAAC;QAEDJ,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC;AAED,OAAO,SAASH,iBAAiBC,GAAW,EAAU;IACpD,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,IAAI,OAAOH,GAAG,CAACG,EAAE,IAAI,KAAK;YAClCD,UAAU,CAAC,CAAC,EAAEF,GAAG,CAACG,EAAE,CAACI,WAAW,GAAG,CAAC;YAEpC,QAAQ;QACV,CAAC;QAEDL,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC"}
@@ -0,0 +1,275 @@
1
+ export interface Code {
2
+ open: string;
3
+ close: string;
4
+ regexp: RegExp;
5
+ }
6
+ /** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */
7
+ export interface Rgb {
8
+ r: number;
9
+ g: number;
10
+ b: number;
11
+ }
12
+ /**
13
+ * Set changing text color to enabled or disabled
14
+ * @param value
15
+ */
16
+ export declare function setColorEnabled(value: boolean): void;
17
+ /** Get whether text color change is enabled or disabled. */
18
+ export declare function getColorEnabled(): boolean;
19
+ /**
20
+ * Reset the text modified
21
+ * @param str text to reset
22
+ */
23
+ export declare function reset(str: string): string;
24
+ /**
25
+ * Make the text bold.
26
+ * @param str text to make bold
27
+ */
28
+ export declare function bold(str: string): string;
29
+ /**
30
+ * The text emits only a small amount of light.
31
+ * @param str text to dim
32
+ */
33
+ export declare function dim(str: string): string;
34
+ /**
35
+ * Make the text italic.
36
+ * @param str text to make italic
37
+ */
38
+ export declare function italic(str: string): string;
39
+ /**
40
+ * Make the text underline.
41
+ * @param str text to underline
42
+ */
43
+ export declare function underline(str: string): string;
44
+ /**
45
+ * Invert background color and text color.
46
+ * @param str text to invert its color
47
+ */
48
+ export declare function inverse(str: string): string;
49
+ /**
50
+ * Make the text hidden.
51
+ * @param str text to hide
52
+ */
53
+ export declare function hidden(str: string): string;
54
+ /**
55
+ * Put horizontal line through the center of the text.
56
+ * @param str text to strike through
57
+ */
58
+ export declare function strikethrough(str: string): string;
59
+ /**
60
+ * Set text color to black.
61
+ * @param str text to make black
62
+ */
63
+ export declare function black(str: string): string;
64
+ /**
65
+ * Set text color to red.
66
+ * @param str text to make red
67
+ */
68
+ export declare function red(str: string): string;
69
+ /**
70
+ * Set text color to green.
71
+ * @param str text to make green
72
+ */
73
+ export declare function green(str: string): string;
74
+ /**
75
+ * Set text color to yellow.
76
+ * @param str text to make yellow
77
+ */
78
+ export declare function yellow(str: string): string;
79
+ /**
80
+ * Set text color to blue.
81
+ * @param str text to make blue
82
+ */
83
+ export declare function blue(str: string): string;
84
+ /**
85
+ * Set text color to magenta.
86
+ * @param str text to make magenta
87
+ */
88
+ export declare function magenta(str: string): string;
89
+ /**
90
+ * Set text color to cyan.
91
+ * @param str text to make cyan
92
+ */
93
+ export declare function cyan(str: string): string;
94
+ /**
95
+ * Set text color to white.
96
+ * @param str text to make white
97
+ */
98
+ export declare function white(str: string): string;
99
+ /**
100
+ * Set text color to gray.
101
+ * @param str text to make gray
102
+ */
103
+ export declare function gray(str: string): string;
104
+ /**
105
+ * Set text color to bright black.
106
+ * @param str text to make bright-black
107
+ */
108
+ export declare function brightBlack(str: string): string;
109
+ /**
110
+ * Set text color to bright red.
111
+ * @param str text to make bright-red
112
+ */
113
+ export declare function brightRed(str: string): string;
114
+ /**
115
+ * Set text color to bright green.
116
+ * @param str text to make bright-green
117
+ */
118
+ export declare function brightGreen(str: string): string;
119
+ /**
120
+ * Set text color to bright yellow.
121
+ * @param str text to make bright-yellow
122
+ */
123
+ export declare function brightYellow(str: string): string;
124
+ /**
125
+ * Set text color to bright blue.
126
+ * @param str text to make bright-blue
127
+ */
128
+ export declare function brightBlue(str: string): string;
129
+ /**
130
+ * Set text color to bright magenta.
131
+ * @param str text to make bright-magenta
132
+ */
133
+ export declare function brightMagenta(str: string): string;
134
+ /**
135
+ * Set text color to bright cyan.
136
+ * @param str text to make bright-cyan
137
+ */
138
+ export declare function brightCyan(str: string): string;
139
+ /**
140
+ * Set text color to bright white.
141
+ * @param str text to make bright-white
142
+ */
143
+ export declare function brightWhite(str: string): string;
144
+ /**
145
+ * Set background color to black.
146
+ * @param str text to make its background black
147
+ */
148
+ export declare function bgBlack(str: string): string;
149
+ /**
150
+ * Set background color to red.
151
+ * @param str text to make its background red
152
+ */
153
+ export declare function bgRed(str: string): string;
154
+ /**
155
+ * Set background color to green.
156
+ * @param str text to make its background green
157
+ */
158
+ export declare function bgGreen(str: string): string;
159
+ /**
160
+ * Set background color to yellow.
161
+ * @param str text to make its background yellow
162
+ */
163
+ export declare function bgYellow(str: string): string;
164
+ /**
165
+ * Set background color to blue.
166
+ * @param str text to make its background blue
167
+ */
168
+ export declare function bgBlue(str: string): string;
169
+ /**
170
+ * Set background color to magenta.
171
+ * @param str text to make its background magenta
172
+ */
173
+ export declare function bgMagenta(str: string): string;
174
+ /**
175
+ * Set background color to cyan.
176
+ * @param str text to make its background cyan
177
+ */
178
+ export declare function bgCyan(str: string): string;
179
+ /**
180
+ * Set background color to white.
181
+ * @param str text to make its background white
182
+ */
183
+ export declare function bgWhite(str: string): string;
184
+ /**
185
+ * Set background color to bright black.
186
+ * @param str text to make its background bright-black
187
+ */
188
+ export declare function bgBrightBlack(str: string): string;
189
+ /**
190
+ * Set background color to bright red.
191
+ * @param str text to make its background bright-red
192
+ */
193
+ export declare function bgBrightRed(str: string): string;
194
+ /**
195
+ * Set background color to bright green.
196
+ * @param str text to make its background bright-green
197
+ */
198
+ export declare function bgBrightGreen(str: string): string;
199
+ /**
200
+ * Set background color to bright yellow.
201
+ * @param str text to make its background bright-yellow
202
+ */
203
+ export declare function bgBrightYellow(str: string): string;
204
+ /**
205
+ * Set background color to bright blue.
206
+ * @param str text to make its background bright-blue
207
+ */
208
+ export declare function bgBrightBlue(str: string): string;
209
+ /**
210
+ * Set background color to bright magenta.
211
+ * @param str text to make its background bright-magenta
212
+ */
213
+ export declare function bgBrightMagenta(str: string): string;
214
+ /**
215
+ * Set background color to bright cyan.
216
+ * @param str text to make its background bright-cyan
217
+ */
218
+ export declare function bgBrightCyan(str: string): string;
219
+ /**
220
+ * Set background color to bright white.
221
+ * @param str text to make its background bright-white
222
+ */
223
+ export declare function bgBrightWhite(str: string): string;
224
+ /**
225
+ * Set text color using paletted 8bit colors.
226
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
227
+ * @param str text color to apply paletted 8bit colors to
228
+ * @param color code
229
+ */
230
+ export declare function rgb8(str: string, color: number): string;
231
+ /**
232
+ * Set background color using paletted 8bit colors.
233
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
234
+ * @param str text color to apply paletted 8bit background colors to
235
+ * @param color code
236
+ */
237
+ export declare function bgRgb8(str: string, color: number): string;
238
+ /**
239
+ * Set text color using 24bit rgb.
240
+ * `color` can be a number in range `0x000000` to `0xffffff` or
241
+ * an `Rgb`.
242
+ *
243
+ * To produce the color magenta:
244
+ *
245
+ * ```ts
246
+ * import { rgb24 } from "./colors.ts";
247
+ * rgb24("foo", 0xff00ff);
248
+ * rgb24("foo", {r: 255, g: 0, b: 255});
249
+ * ```
250
+ * @param str text color to apply 24bit rgb to
251
+ * @param color code
252
+ */
253
+ export declare function rgb24(str: string, color: number | Rgb): string;
254
+ /**
255
+ * Set background color using 24bit rgb.
256
+ * `color` can be a number in range `0x000000` to `0xffffff` or
257
+ * an `Rgb`.
258
+ *
259
+ * To produce the color magenta:
260
+ *
261
+ * ```ts
262
+ * import { bgRgb24 } from "./colors.ts";
263
+ * bgRgb24("foo", 0xff00ff);
264
+ * bgRgb24("foo", {r: 255, g: 0, b: 255});
265
+ * ```
266
+ * @param str text color to apply 24bit rgb to
267
+ * @param color code
268
+ */
269
+ export declare function bgRgb24(str: string, color: number | Rgb): string;
270
+ /**
271
+ * Remove ANSI escape codes from the string.
272
+ * @param string to remove ANSI escape codes from
273
+ */
274
+ export declare function stripColor(string: string): string;
275
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qEAAqE;AACrE,MAAM,WAAW,GAAG;IAClB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,QAE7C;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAwBD;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;GAGG;AACH,wBAAgB,MAAM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