Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export TypeScript types for colors and modifiers #357

Merged
merged 5 commits into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions index.d.ts
Expand Up @@ -20,6 +20,71 @@ declare const enum LevelEnum {
TrueColor = 3
}

/**
Available foreground colors.
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
*/
declare type ForegroundColor =
| "black"
SimenB marked this conversation as resolved.
Show resolved Hide resolved
| "red"
| "green"
| "yellow"
| "blue"
| "magenta"
| "cyan"
| "white"
| "gray"
| "grey"
| "blackBright"
| "redBright"
| "greenBright"
| "yellowBright"
| "blueBright"
| "magentaBright"
| "cyanBright"
| "whiteBright";

/**
Available background colors.
*/
declare type BackgroundColor =
| "bgBlack"
| "bgRed"
| "bgGreen"
| "bgYellow"
| "bgBlue"
| "bgMagenta"
| "bgCyan"
| "bgWhite"
| "bgGray"
| "bgGrey"
| "bgBlackBright"
| "bgRedBright"
| "bgGreenBright"
| "bgYellowBright"
| "bgBlueBright"
| "bgMagentaBright"
| "bgCyanBright"
| "bgWhiteBright";

/**
Available colors.
*/
declare type Color = ForegroundColor | BackgroundColor;

/**
Available modifiers.
*/
declare type Modifiers =
| "reset"
| "bold"
| "dim"
| "italic"
| "underline"
| "inverse"
| "hidden"
| "strikethrough"
| "visible";

declare namespace chalk {
type Level = LevelEnum;

Expand Down Expand Up @@ -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;
Color: Color;
ForegroundColor: ForegroundColor;
BackgroundColor: BackgroundColor;
Modifiers: Modifiers;
};

export = chalk;
5 changes: 5 additions & 0 deletions index.test-d.ts
Expand Up @@ -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');