From aefb21012dacfbd96de94850ede61796cf455378 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 15 Jul 2019 11:25:30 +0200 Subject: [PATCH] feat: export available colors as TS type --- index.d.ts | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ index.test-d.ts | 5 ++++ 2 files changed, 74 insertions(+) diff --git a/index.d.ts b/index.d.ts index 58da80e..4b7ca16 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,6 +20,71 @@ declare const enum LevelEnum { TrueColor = 3 } +/** + * Available foreground colors for use + */ +declare type ForegroundColor = + | "black" + | "red" + | "green" + | "yellow" + | "blue" + | "magenta" + | "cyan" + | "white" + | "gray" + | "grey" + | "blackBright" + | "redBright" + | "greenBright" + | "yellowBright" + | "blueBright" + | "magentaBright" + | "cyanBright" + | "whiteBright"; + +/** + * Available background colors for use + */ +declare type BackgroundColor = + | "bgBlack" + | "bgRed" + | "bgGreen" + | "bgYellow" + | "bgBlue" + | "bgMagenta" + | "bgCyan" + | "bgWhite" + | "bgGray" + | "bgGrey" + | "bgBlackBright" + | "bgRedBright" + | "bgGreenBright" + | "bgYellowBright" + | "bgBlueBright" + | "bgMagentaBright" + | "bgCyanBright" + | "bgWhiteBright"; + +/** + * Available colors for use + */ +declare type Color = BackgroundColor | ForegroundColor; + +/** + * Available modifiers for use + */ +declare type Modifiers = + | "reset" + | "bold" + | "dim" + | "italic" + | "underline" + | "inverse" + | "hidden" + | "strikethrough" + | "visible"; + declare namespace chalk { type Level = LevelEnum; @@ -306,6 +371,10 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`. declare const chalk: chalk.Chalk & chalk.ChalkFunction & { supportsColor: chalk.ColorSupport | false; Level: typeof LevelEnum; + BackgroundColor: BackgroundColor; + ForegroundColor: ForegroundColor; + Color: Color; + Modifiers: Modifiers; }; export = chalk; diff --git a/index.test-d.ts b/index.test-d.ts index 5ab486d..baec3d1 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -139,3 +139,8 @@ expectType(chalk.bgWhiteBright`foo`); // -- Complex -- expectType(chalk.red.bgGreen.underline('foo')); expectType(chalk.underline.red.bgGreen('foo')); + +// -- Color types == + +expectType('red'); +expectError('hotpink');