Skip to content

Commit 202e797

Browse files
committed
Deprecated current style names in favor of using Name suffix
1 parent 553c468 commit 202e797

File tree

4 files changed

+107
-23
lines changed

4 files changed

+107
-23
lines changed

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,19 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
210210

211211
`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.
212212

213-
### modifiers, foregroundColors, backgroundColors, and colors
213+
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
214214

215-
All supported style strings are exposed as an array of strings for convenience. `colors` is the combination of `foregroundColors` and `backgroundColors`.
215+
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
216216

217217
This can be useful if you wrap Chalk and need to validate input:
218218

219219
```js
220-
import {modifiers, foregroundColors} from 'chalk';
220+
import {modifierNames, foregroundColorNames} from 'chalk';
221221

222-
console.log(modifiers.includes('bold'));
222+
console.log(modifierNames.includes('bold'));
223223
//=> true
224224

225-
console.log(foregroundColors.includes('pink'));
225+
console.log(foregroundColorNames.includes('pink'));
226226
//=> false
227227
```
228228

source/index.d.ts

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: Make it this when TS suports that.
2-
// import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from '#ansi-styles';
2+
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
33
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
4-
import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from './vendor/ansi-styles/index.js';
4+
import {ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './vendor/ansi-styles/index.js';
55
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
66

77
export interface Options {
@@ -242,10 +242,10 @@ export const chalkStderr: typeof chalk;
242242
export const supportsColorStderr: typeof supportsColor;
243243

244244
export {
245-
ModifierName as Modifiers,
246-
ForegroundColorName as ForegroundColor,
247-
BackgroundColorName as BackgroundColor,
248-
ColorName as Color,
245+
ModifierName,
246+
ForegroundColorName,
247+
BackgroundColorName,
248+
ColorName,
249249
// } from '#ansi-styles';
250250
} from './vendor/ansi-styles/index.js';
251251

@@ -256,9 +256,86 @@ export {
256256
// } from '#supports-color';
257257
} from './vendor/supports-color/index.js';
258258

259+
/**
260+
Basic modifier names.
261+
*/
262+
export const modifierNames: readonly ModifierName[];
263+
264+
/**
265+
Basic foreground color names.
266+
*/
267+
export const foregroundColorNames: readonly ForegroundColorName[];
268+
269+
/**
270+
Basic background color names.
271+
*/
272+
export const backgroundColorNames: readonly BackgroundColorName[];
273+
274+
/**
275+
Basic color names. The combination of foreground and background color names.
276+
*/
277+
export const colorNames: readonly ColorName[];
278+
279+
/**
280+
@deprecated Use `ModifierName` instead.
281+
282+
Basic modifier names.
283+
*/
284+
export type Modifiers = ModifierName;
285+
286+
/**
287+
@deprecated Use `ForegroundColorName` instead.
288+
289+
Basic foreground color names.
290+
291+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
292+
*/
293+
export type ForegroundColor = ForegroundColorName;
294+
295+
/**
296+
@deprecated Use `BackgroundColorName` instead.
297+
298+
Basic background color names.
299+
300+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
301+
*/
302+
export type BackgroundColor = BackgroundColorName;
303+
304+
/**
305+
@deprecated Use `ColorName` instead.
306+
307+
Basic color names. The combination of foreground and background color names.
308+
309+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
310+
*/
311+
export type Color = ColorName;
312+
313+
/**
314+
@deprecated Use `modifierNames` instead.
315+
316+
Basic modifier names.
317+
*/
259318
export const modifiers: readonly Modifiers[];
319+
320+
/**
321+
@deprecated Use `foregroundColorNames` instead.
322+
323+
Basic foreground color names.
324+
*/
260325
export const foregroundColors: readonly ForegroundColor[];
326+
327+
/**
328+
@deprecated Use `backgroundColorNames` instead.
329+
330+
Basic background color names.
331+
*/
261332
export const backgroundColors: readonly BackgroundColor[];
333+
334+
/**
335+
@deprecated Use `colorNames` instead.
336+
337+
Basic color names. The combination of foreground and background color names.
338+
*/
262339
export const colors: readonly Color[];
263340

264341
export default chalk;

source/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ const chalk = createChalk();
205205
export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
206206

207207
export {
208+
modifierNames,
209+
foregroundColorNames,
210+
backgroundColorNames,
211+
colorNames,
208212
modifierNames as modifiers,
209213
foregroundColorNames as foregroundColors,
210214
backgroundColorNames as backgroundColors,

source/index.test-d.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import {expectType, expectAssignable, expectError} from 'tsd';
2-
import chalk, {Chalk, ChalkInstance, Modifiers, ForegroundColor, BackgroundColor, Color, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
1+
import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd';
2+
import chalk, {
3+
Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr,
4+
ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
5+
} from './index.js';
36

47
// - supportsColor -
58
expectType<ColorInfo>(supportsColor);
@@ -142,19 +145,19 @@ expectType<string>(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`);
142145
expectType<string>(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`);
143146

144147
// -- Modifiers types
145-
expectAssignable<Modifiers>('strikethrough');
146-
expectError<Modifiers>('delete');
148+
expectAssignable<ModifierName>('strikethrough');
149+
expectError<ModifierName>('delete');
147150

148151
// -- Foreground types
149-
expectAssignable<ForegroundColor>('red');
150-
expectError<ForegroundColor>('pink');
152+
expectAssignable<ForegroundColorName>('red');
153+
expectError<ForegroundColorName>('pink');
151154

152155
// -- Background types
153-
expectAssignable<BackgroundColor>('bgRed');
154-
expectError<BackgroundColor>('bgPink');
156+
expectAssignable<BackgroundColorName>('bgRed');
157+
expectError<BackgroundColorName>('bgPink');
155158

156159
// -- Color types --
157-
expectAssignable<Color>('red');
158-
expectAssignable<Color>('bgRed');
159-
expectError<Color>('hotpink');
160-
expectError<Color>('bgHotpink');
160+
expectAssignable<ColorName>('red');
161+
expectAssignable<ColorName>('bgRed');
162+
expectError<ColorName>('hotpink');
163+
expectError<ColorName>('bgHotpink');

0 commit comments

Comments
 (0)