Use template literal types for simple color name transformations in the TypeScript types (#564)

This commit is contained in:
Matt Schlenker 2022-09-24 22:24:19 -07:00 committed by GitHub
parent ba5c385ecf
commit c2311622c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

45
source/index.d.ts vendored
View file

@ -2,55 +2,24 @@
// import {ColorInfo, ColorSupportLevel} from '#supports-color'; // import {ColorInfo, ColorSupportLevel} from '#supports-color';
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js'; 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. Basic foreground colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support) [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/ */
export type ForegroundColor =
| 'black' export type ForegroundColor = BasicColor | BrightColor | Grey;
| 'red'
| 'green'
| 'yellow'
| 'blue'
| 'magenta'
| 'cyan'
| 'white'
| 'gray'
| 'grey'
| 'blackBright'
| 'redBright'
| 'greenBright'
| 'yellowBright'
| 'blueBright'
| 'magentaBright'
| 'cyanBright'
| 'whiteBright';
/** /**
Basic background colors. Basic background colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support) [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/ */
export type BackgroundColor = export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;
| 'bgBlack'
| 'bgRed'
| 'bgGreen'
| 'bgYellow'
| 'bgBlue'
| 'bgMagenta'
| 'bgCyan'
| 'bgWhite'
| 'bgGray'
| 'bgGrey'
| 'bgBlackBright'
| 'bgRedBright'
| 'bgGreenBright'
| 'bgYellowBright'
| 'bgBlueBright'
| 'bgMagentaBright'
| 'bgCyanBright'
| 'bgWhiteBright';
/** /**
Basic colors. Basic colors.