Skip to content

Commit 18c280d

Browse files
pedrottimarksindresorhus
authored andcommitted
Add ansi and bgAnsi to TypeScript declaration (#369)
1 parent 628b595 commit 18c280d

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ declare namespace chalk {
213213
*/
214214
hwb(hue: number, whiteness: number, blackness: number): Chalk;
215215

216+
/**
217+
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
218+
219+
30 <= code && code < 38 || 90 <= code && code < 98
220+
For example, 31 for red, 91 for redBright.
221+
*/
222+
ansi(code: number): Chalk;
223+
216224
/**
217225
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
218226
*/
@@ -266,6 +274,15 @@ declare namespace chalk {
266274
*/
267275
bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
268276

277+
/**
278+
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
279+
280+
30 <= code && code < 38 || 90 <= code && code < 98
281+
For example, 31 for red, 91 for redBright.
282+
Use the foreground code, not the background code (for example, not 41, nor 101).
283+
*/
284+
bgAnsi(code: number): Chalk;
285+
269286
/**
270287
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
271288
*/

index.test-d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ expectType<colorReturn>(chalk.rgb(0, 0, 0));
4949
expectType<colorReturn>(chalk.hsl(0, 0, 0));
5050
expectType<colorReturn>(chalk.hsv(0, 0, 0));
5151
expectType<colorReturn>(chalk.hwb(0, 0, 0));
52+
expectType<colorReturn>(chalk.ansi(30));
5253
expectType<colorReturn>(chalk.ansi256(0));
5354
expectType<colorReturn>(chalk.bgHex('#DEADED'));
5455
expectType<colorReturn>(chalk.bgKeyword('orange'));
5556
expectType<colorReturn>(chalk.bgRgb(0, 0, 0));
5657
expectType<colorReturn>(chalk.bgHsl(0, 0, 0));
5758
expectType<colorReturn>(chalk.bgHsv(0, 0, 0));
5859
expectType<colorReturn>(chalk.bgHwb(0, 0, 0));
60+
expectType<colorReturn>(chalk.bgAnsi(30));
5961
expectType<colorReturn>(chalk.bgAnsi256(0));
6062

6163
// -- Modifiers --

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The following color models can be used:
261261
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
262262
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
263263
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
264-
- `ansi16`
264+
- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
265265
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
266266

267267

0 commit comments

Comments
 (0)