diff --git a/readme.md b/readme.md index 5431631..f18b2aa 100644 --- a/readme.md +++ b/readme.md @@ -210,19 +210,19 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color= `chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience. -### modifiers, foregroundColors, backgroundColors, and colors +### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames -All supported style strings are exposed as an array of strings for convenience. `colors` is the combination of `foregroundColors` and `backgroundColors`. +All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`. This can be useful if you wrap Chalk and need to validate input: ```js -import {modifiers, foregroundColors} from 'chalk'; +import {modifierNames, foregroundColorNames} from 'chalk'; -console.log(modifiers.includes('bold')); +console.log(modifierNames.includes('bold')); //=> true -console.log(foregroundColors.includes('pink')); +console.log(foregroundColorNames.includes('pink')); //=> false ``` diff --git a/source/index.d.ts b/source/index.d.ts index dd249f5..f514c19 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -1,7 +1,7 @@ // TODO: Make it this when TS suports that. -// import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from '#ansi-styles'; +// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles'; // import {ColorInfo, ColorSupportLevel} from '#supports-color'; -import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from './vendor/ansi-styles/index.js'; +import {ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './vendor/ansi-styles/index.js'; import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js'; export interface Options { @@ -242,10 +242,10 @@ export const chalkStderr: typeof chalk; export const supportsColorStderr: typeof supportsColor; export { - ModifierName as Modifiers, - ForegroundColorName as ForegroundColor, - BackgroundColorName as BackgroundColor, - ColorName as Color, + ModifierName, + ForegroundColorName, + BackgroundColorName, + ColorName, // } from '#ansi-styles'; } from './vendor/ansi-styles/index.js'; @@ -256,9 +256,86 @@ export { // } from '#supports-color'; } from './vendor/supports-color/index.js'; +/** +Basic modifier names. +*/ +export const modifierNames: readonly ModifierName[]; + +/** +Basic foreground color names. +*/ +export const foregroundColorNames: readonly ForegroundColorName[]; + +/** +Basic background color names. +*/ +export const backgroundColorNames: readonly BackgroundColorName[]; + +/** +Basic color names. The combination of foreground and background color names. +*/ +export const colorNames: readonly ColorName[]; + +/** +@deprecated Use `ModifierName` instead. + +Basic modifier names. +*/ +export type Modifiers = ModifierName; + +/** +@deprecated Use `ForegroundColorName` instead. + +Basic foreground color names. + +[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support) +*/ +export type ForegroundColor = ForegroundColorName; + +/** +@deprecated Use `BackgroundColorName` instead. + +Basic background color names. + +[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support) +*/ +export type BackgroundColor = BackgroundColorName; + +/** +@deprecated Use `ColorName` instead. + +Basic color names. The combination of foreground and background color names. + +[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support) +*/ +export type Color = ColorName; + +/** +@deprecated Use `modifierNames` instead. + +Basic modifier names. +*/ export const modifiers: readonly Modifiers[]; + +/** +@deprecated Use `foregroundColorNames` instead. + +Basic foreground color names. +*/ export const foregroundColors: readonly ForegroundColor[]; + +/** +@deprecated Use `backgroundColorNames` instead. + +Basic background color names. +*/ export const backgroundColors: readonly BackgroundColor[]; + +/** +@deprecated Use `colorNames` instead. + +Basic color names. The combination of foreground and background color names. +*/ export const colors: readonly Color[]; export default chalk; diff --git a/source/index.js b/source/index.js index 7a3cc71..86a86e6 100644 --- a/source/index.js +++ b/source/index.js @@ -205,6 +205,10 @@ const chalk = createChalk(); export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0}); export { + modifierNames, + foregroundColorNames, + backgroundColorNames, + colorNames, modifierNames as modifiers, foregroundColorNames as foregroundColors, backgroundColorNames as backgroundColors, diff --git a/source/index.test-d.ts b/source/index.test-d.ts index 20fdd59..67faf82 100644 --- a/source/index.test-d.ts +++ b/source/index.test-d.ts @@ -1,5 +1,8 @@ -import {expectType, expectAssignable, expectError} from 'tsd'; -import chalk, {Chalk, ChalkInstance, Modifiers, ForegroundColor, BackgroundColor, Color, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js'; +import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd'; +import chalk, { + Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr, + ModifierName, ForegroundColorName, BackgroundColorName, ColorName, +} from './index.js'; // - supportsColor - expectType(supportsColor); @@ -142,19 +145,19 @@ expectType(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`); expectType(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`); // -- Modifiers types -expectAssignable('strikethrough'); -expectError('delete'); +expectAssignable('strikethrough'); +expectError('delete'); // -- Foreground types -expectAssignable('red'); -expectError('pink'); +expectAssignable('red'); +expectError('pink'); // -- Background types -expectAssignable('bgRed'); -expectError('bgPink'); +expectAssignable('bgRed'); +expectError('bgPink'); // -- Color types -- -expectAssignable('red'); -expectAssignable('bgRed'); -expectError('hotpink'); -expectError('bgHotpink'); +expectAssignable('red'); +expectAssignable('bgRed'); +expectError('hotpink'); +expectError('bgHotpink');