feat: export available colors as TS type

This commit is contained in:
Simen Bekkhus 2019-07-15 11:25:30 +02:00
parent 1f77953f1a
commit aefb21012d
No known key found for this signature in database
GPG key ID: 92B92EBAD80DE3CE
2 changed files with 74 additions and 0 deletions

69
index.d.ts vendored
View file

@ -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;

View file

@ -139,3 +139,8 @@ expectType<string>(chalk.bgWhiteBright`foo`);
// -- Complex --
expectType<string>(chalk.red.bgGreen.underline('foo'));
expectType<string>(chalk.underline.red.bgGreen('foo'));
// -- Color types ==
expectType<typeof chalk.Color>('red');
expectError<typeof chalk.Color>('hotpink');