@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.
- package/README.md +6 -10
- package/dist/Collection.js +113 -2
- package/dist/Collection.js.map +1 -0
- package/dist/base64.js +262 -2
- package/dist/base64.js.map +1 -0
- package/dist/bucket.d.ts +36 -42
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +76 -2
- package/dist/bucket.js.map +1 -0
- package/dist/casing.d.ts +4 -2
- package/dist/casing.d.ts.map +1 -1
- package/dist/casing.js +51 -2
- package/dist/casing.js.map +1 -0
- package/dist/colors.d.ts +275 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +467 -0
- package/dist/colors.js.map +1 -0
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +19 -2
- package/dist/hash.js.map +1 -0
- package/dist/images.d.ts +47 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +66 -2
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -0
- package/dist/interactions.d.ts +3 -0
- package/dist/interactions.d.ts.map +1 -0
- package/dist/interactions.js +41 -0
- package/dist/interactions.js.map +1 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +130 -0
- package/dist/logger.js.map +1 -0
- package/dist/oauth2.d.ts +58 -0
- package/dist/oauth2.d.ts.map +1 -0
- package/dist/oauth2.js +16 -0
- package/dist/oauth2.js.map +1 -0
- package/dist/permissions.js +17 -2
- package/dist/permissions.js.map +1 -0
- package/dist/reactions.d.ts +3 -0
- package/dist/reactions.d.ts.map +1 -0
- package/dist/reactions.js +11 -0
- package/dist/reactions.js.map +1 -0
- package/dist/token.d.ts +1 -1
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +21 -2
- package/dist/token.js.map +1 -0
- package/dist/typeguards.d.ts +6 -0
- package/dist/typeguards.d.ts.map +1 -0
- package/dist/typeguards.js +15 -0
- package/dist/typeguards.js.map +1 -0
- package/dist/urlToBase64.js +9 -2
- package/dist/urlToBase64.js.map +1 -0
- package/dist/utils.d.ts +2 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +15 -2
- package/dist/utils.js.map +1 -0
- package/package.json +12 -12
package/dist/bucket.js
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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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ACC,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
|
|
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
|
package/dist/casing.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
|
2
|
-
|
|
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,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AAOH,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"}
|
package/dist/colors.d.ts
ADDED
|
@@ -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,GA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