@prostojs/dye
Version:
Easy and light console styling tool
60 lines • 3.22 kB
text/typescript
//#region src/index.d.ts
declare const DyeColors: readonly ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"];
declare const DyeGrayscale: readonly ["gray01", "gray02", "gray03", "gray04", "gray05", "gray06", "gray07", "gray08", "gray09", "gray10", "gray11", "gray12", "gray13", "gray14", "gray15", "gray16", "gray17", "gray18", "gray19", "gray20", "gray21", "gray22"];
type TDyeColor = (typeof DyeColors)[number];
type TDyeGrayscale = (typeof DyeGrayscale)[number];
type TDyeColorBright = `${TDyeColor}-bright`;
type TDyeColorAll = TDyeColor | TDyeColorBright;
type TDyeBgColor = `bg-${TDyeColorAll}`;
type TDyeBgGrayscale = `bg-${TDyeGrayscale}`;
declare const DyeModifier: readonly ["bold", "dim", "italic", "underscore", "inverse", "hidden", "crossed"];
type TDyeModifier = (typeof DyeModifier)[number];
type TRGBHEX = `#${string}`;
type TRGBHEXBG = `bg#${string}`;
type TRGBHEXTypes = TRGBHEX | TRGBHEXBG;
type TRGB = `${number},${number},${number}`;
type TBgRGB = `bg${number},${number},${number}`;
type TRGB256 = `*${number},${number},${number}`;
type TBgRGB256 = `bg*${number},${number},${number}`;
type TRGBTypes = TRGB | TBgRGB | TRGB256 | TBgRGB256;
type TDyeAll = TDyeColorAll | TDyeBgColor | TDyeModifier | TRGBTypes | TRGBHEXTypes | TDyeGrayscale | TDyeBgGrayscale;
interface TDyeStylist<Format extends unknown[] = TConsoleArgument> {
(...texts: Format): string;
open: string;
close: string;
format: (cb: (...texts: Format) => string) => TDyeStylist<Format>;
prefix: (v: string | ((...texts: Format) => string)) => TDyeStylist<Format>;
suffix: (v: string | ((...texts: Format) => string)) => TDyeStylist<Format>;
attachConsole: (...args: [] | [TConsoleMethodName] | [TConsoleMethodName, TConsoleInterface] | [(...args: Format) => void]) => TDyeStylistConsole<Format>;
}
interface TDyeStylistConsole<Format extends unknown[] = TConsoleArgument> {
(...args: Format): void;
enable: (v?: boolean) => void;
disable: () => void;
asStylist: () => TDyeStylist<Format>;
}
type TConsoleMethodName = 'info' | 'log' | 'warn' | 'error' | 'debug';
type TConsoleArgument = Array<string | number | Error | Record<string, unknown> | unknown>;
interface TConsoleInterface {
log: (...args: TConsoleArgument) => void;
info: (...args: TConsoleArgument) => void;
debug: (...args: TConsoleArgument) => void;
warn: (...args: TConsoleArgument) => void;
error: (...args: TConsoleArgument) => void;
}
type DyeFunction<Format extends unknown[] = TConsoleArgument> = (<F extends unknown[] = Format>(...args: TDyeAll[]) => TDyeStylist<F>) & {
strip: (coloredText: string) => string;
reset: string;
bold_off: string;
dim_off: string;
italic_off: string;
underscore_off: string;
blink_slow_off: string;
blink_rapid_off: string;
inverse_off: string;
reveal: string;
crossed_off: string;
};
declare const dye: DyeFunction;
//#endregion
export { DyeColors, DyeGrayscale, DyeModifier, TBgRGB, TBgRGB256, TConsoleArgument, TConsoleInterface, TConsoleMethodName, TDyeAll, TDyeBgColor, TDyeBgGrayscale, TDyeColor, TDyeColorAll, TDyeColorBright, TDyeGrayscale, TDyeModifier, TDyeStylist, TDyeStylistConsole, TRGB, TRGB256, TRGBHEX, TRGBHEXBG, TRGBHEXTypes, TRGBTypes, dye };