From c2311622c3f5b972cf80b9f353ea82679cc77edf Mon Sep 17 00:00:00 2001 From: Matt Schlenker Date: Sat, 24 Sep 2022 22:24:19 -0700 Subject: [PATCH] Use template literal types for simple color name transformations in the TypeScript types (#564) --- source/index.d.ts | 45 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/source/index.d.ts b/source/index.d.ts index b2408c6..c840202 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -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}`; /** Basic colors.