Skip to content

Commit

Permalink
Use template literal types for simple color name transformations in t…
Browse files Browse the repository at this point in the history
…he TypeScript types (#564)
  • Loading branch information
m4ttsch committed Sep 25, 2022
1 parent ba5c385 commit c231162
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions source/index.d.ts
Expand Up @@ -2,55 +2,24 @@
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';

type BasicColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
type BrightColor = `${BasicColor}Bright`;
type Grey = 'gray' | 'grey';

/**
Basic foreground colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type ForegroundColor =
| 'black'
| 'red'
| 'green'
| 'yellow'
| 'blue'
| 'magenta'
| 'cyan'
| 'white'
| 'gray'
| 'grey'
| 'blackBright'
| 'redBright'
| 'greenBright'
| 'yellowBright'
| 'blueBright'
| 'magentaBright'
| 'cyanBright'
| 'whiteBright';

export type ForegroundColor = BasicColor | BrightColor | Grey;

/**
Basic background colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type BackgroundColor =
| 'bgBlack'
| 'bgRed'
| 'bgGreen'
| 'bgYellow'
| 'bgBlue'
| 'bgMagenta'
| 'bgCyan'
| 'bgWhite'
| 'bgGray'
| 'bgGrey'
| 'bgBlackBright'
| 'bgRedBright'
| 'bgGreenBright'
| 'bgYellowBright'
| 'bgBlueBright'
| 'bgMagentaBright'
| 'bgCyanBright'
| 'bgWhiteBright';
export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;

/**
Basic colors.
Expand Down

0 comments on commit c231162

Please sign in to comment.