From aefb21012dacfbd96de94850ede61796cf455378 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 15 Jul 2019 11:25:30 +0200 Subject: [PATCH 1/5] 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'); From 3d5418fafc64cc0e8b27864b6cb370b57f11cd64 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 22 Aug 2019 00:54:12 +0200 Subject: [PATCH 2/5] Update index.d.ts --- index.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4b7ca16..afd382c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,8 +21,8 @@ declare const enum LevelEnum { } /** - * Available foreground colors for use - */ +Available foreground colors. +*/ declare type ForegroundColor = | "black" | "red" @@ -44,8 +44,8 @@ declare type ForegroundColor = | "whiteBright"; /** - * Available background colors for use - */ +Available background colors. +*/ declare type BackgroundColor = | "bgBlack" | "bgRed" @@ -67,13 +67,13 @@ declare type BackgroundColor = | "bgWhiteBright"; /** - * Available colors for use - */ -declare type Color = BackgroundColor | ForegroundColor; +Available colors. +*/ +declare type Color = ForegroundColor | BackgroundColor; /** - * Available modifiers for use - */ +Available modifiers. +*/ declare type Modifiers = | "reset" | "bold" @@ -371,9 +371,9 @@ 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; + ForegroundColor: ForegroundColor; + BackgroundColor: BackgroundColor; Modifiers: Modifiers; }; From fb2e1240b1c69eee9d5b735426ad8ffef4b98fe6 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 11:54:10 +0200 Subject: [PATCH 3/5] pr feedback --- index.d.ts | 94 +++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/index.d.ts b/index.d.ts index afd382c..81b6efc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,50 +21,50 @@ declare const enum LevelEnum { } /** -Available foreground colors. +Available builtin foreground colors. Other colors are also available: https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support */ declare type ForegroundColor = - | "black" - | "red" - | "green" - | "yellow" - | "blue" - | "magenta" - | "cyan" - | "white" - | "gray" - | "grey" - | "blackBright" - | "redBright" - | "greenBright" - | "yellowBright" - | "blueBright" - | "magentaBright" - | "cyanBright" - | "whiteBright"; + | 'black' + | 'red' + | 'green' + | 'yellow' + | 'blue' + | 'magenta' + | 'cyan' + | 'white' + | 'gray' + | 'grey' + | 'blackBright' + | 'redBright' + | 'greenBright' + | 'yellowBright' + | 'blueBright' + | 'magentaBright' + | 'cyanBright' + | 'whiteBright'; /** -Available background colors. +Available builtin background colors. Other colors are also available: https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support */ declare type BackgroundColor = - | "bgBlack" - | "bgRed" - | "bgGreen" - | "bgYellow" - | "bgBlue" - | "bgMagenta" - | "bgCyan" - | "bgWhite" - | "bgGray" - | "bgGrey" - | "bgBlackBright" - | "bgRedBright" - | "bgGreenBright" - | "bgYellowBright" - | "bgBlueBright" - | "bgMagentaBright" - | "bgCyanBright" - | "bgWhiteBright"; + | 'bgBlack' + | 'bgRed' + | 'bgGreen' + | 'bgYellow' + | 'bgBlue' + | 'bgMagenta' + | 'bgCyan' + | 'bgWhite' + | 'bgGray' + | 'bgGrey' + | 'bgBlackBright' + | 'bgRedBright' + | 'bgGreenBright' + | 'bgYellowBright' + | 'bgBlueBright' + | 'bgMagentaBright' + | 'bgCyanBright' + | 'bgWhiteBright'; /** Available colors. @@ -75,15 +75,15 @@ declare type Color = ForegroundColor | BackgroundColor; Available modifiers. */ declare type Modifiers = - | "reset" - | "bold" - | "dim" - | "italic" - | "underline" - | "inverse" - | "hidden" - | "strikethrough" - | "visible"; + | 'reset' + | 'bold' + | 'dim' + | 'italic' + | 'underline' + | 'inverse' + | 'hidden' + | 'strikethrough' + | 'visible'; declare namespace chalk { type Level = LevelEnum; From 62ef5784b80caa2ec8fab29324f50a731bb975a9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 22 Aug 2019 15:24:43 +0200 Subject: [PATCH 4/5] Update index.test-d.ts --- index.test-d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.test-d.ts b/index.test-d.ts index baec3d1..1d2df98 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -141,6 +141,5 @@ expectType(chalk.red.bgGreen.underline('foo')); expectType(chalk.underline.red.bgGreen('foo')); // -- Color types == - expectType('red'); expectError('hotpink'); From 5cb7939e861b396d330565544be3bb02796cb303 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 22 Aug 2019 15:27:48 +0200 Subject: [PATCH 5/5] Update index.d.ts --- index.d.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 81b6efc..c650eb9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,7 +21,9 @@ declare const enum LevelEnum { } /** -Available builtin foreground colors. Other colors are also available: https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support +Basic foreground colors. + +[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support) */ declare type ForegroundColor = | 'black' @@ -44,7 +46,9 @@ declare type ForegroundColor = | 'whiteBright'; /** -Available builtin background colors. Other colors are also available: https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support +Basic background colors. + +[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support) */ declare type BackgroundColor = | 'bgBlack' @@ -67,13 +71,12 @@ declare type BackgroundColor = | 'bgWhiteBright'; /** -Available colors. +Basic colors. + +[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support) */ declare type Color = ForegroundColor | BackgroundColor; -/** -Available modifiers. -*/ declare type Modifiers = | 'reset' | 'bold'