chalk/source/index.d.ts

293 lines
6 KiB
TypeScript
Raw Normal View History

2021-11-26 16:34:27 +07:00
// TODO: Make it this when TS suports that.
// 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.
2021-01-24 14:27:41 +07:00
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type ForegroundColor = BasicColor | BrightColor | Grey;
/**
Basic background colors.
2021-01-24 14:27:41 +07:00
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;
/**
Basic colors.
2021-01-24 14:27:41 +07:00
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
2021-04-16 15:23:29 +07:00
export type Color = ForegroundColor | BackgroundColor;
2021-04-16 15:23:29 +07:00
export type Modifiers =
| 'reset'
| 'bold'
| 'dim'
| 'italic'
| 'underline'
| 'overline'
| 'inverse'
| 'hidden'
| 'strikethrough'
| 'visible';
2021-04-16 15:23:29 +07:00
export interface Options {
/**
2021-04-16 15:23:29 +07:00
Specify the color support for Chalk.
By default, color support is automatically detected based on the environment.
Levels:
- `0` - All colors disabled.
- `1` - Basic 16 colors support.
- `2` - ANSI 256 colors support.
- `3` - Truecolor 16 million colors support.
*/
2021-04-16 15:23:29 +07:00
readonly level?: ColorSupportLevel;
}
/**
Return a new Chalk instance.
*/
export const Chalk: new (options?: Options) => ChalkInstance; // eslint-disable-line @typescript-eslint/naming-convention
2021-04-16 15:23:29 +07:00
export interface ChalkInstance {
2021-04-16 15:23:29 +07:00
(...text: unknown[]): string;
/**
2021-04-16 15:23:29 +07:00
The color support for Chalk.
By default, color support is automatically detected based on the environment.
Levels:
- `0` - All colors disabled.
- `1` - Basic 16 colors support.
- `2` - ANSI 256 colors support.
- `3` - Truecolor 16 million colors support.
*/
2021-04-16 15:23:29 +07:00
level: ColorSupportLevel;
/**
Use RGB values to set text color.
2021-10-25 08:07:02 +13:00
@example
```
import chalk from 'chalk';
chalk.rgb(222, 173, 237);
```
*/
rgb: (red: number, green: number, blue: number) => this;
2021-04-16 15:23:29 +07:00
/**
Use HEX value to set text color.
2021-04-16 15:23:29 +07:00
@param color - Hexadecimal value representing the desired color.
2021-04-16 15:23:29 +07:00
@example
```
import chalk from 'chalk';
2021-04-16 15:23:29 +07:00
chalk.hex('#DEADED');
```
*/
2021-04-18 00:33:03 +12:00
hex: (color: string) => this;
2021-04-16 15:23:29 +07:00
/**
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
2021-10-25 08:07:02 +13:00
@example
```
import chalk from 'chalk';
chalk.ansi256(201);
```
2021-04-16 15:23:29 +07:00
*/
ansi256: (index: number) => this;
2021-04-16 15:23:29 +07:00
/**
Use RGB values to set background color.
2021-10-25 08:07:02 +13:00
@example
```
import chalk from 'chalk';
chalk.bgRgb(222, 173, 237);
```
2021-04-16 15:23:29 +07:00
*/
bgRgb: (red: number, green: number, blue: number) => this;
2021-04-16 15:23:29 +07:00
/**
Use HEX value to set background color.
2021-04-16 15:23:29 +07:00
@param color - Hexadecimal value representing the desired color.
2021-04-16 15:23:29 +07:00
@example
```
import chalk from 'chalk';
2021-04-16 15:23:29 +07:00
chalk.bgHex('#DEADED');
```
*/
2021-04-18 00:33:03 +12:00
bgHex: (color: string) => this;
2021-04-16 15:23:29 +07:00
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
2021-10-25 08:07:02 +13:00
@example
```
import chalk from 'chalk';
chalk.bgAnsi256(201);
```
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
bgAnsi256: (index: number) => this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Reset the current style.
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly reset: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Make the text bold.
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly bold: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Make the text have lower opacity.
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly dim: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Make the text italic. *(Not widely supported)*
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly italic: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Put a horizontal line below the text. *(Not widely supported)*
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly underline: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Put a horizontal line above the text. *(Not widely supported)*
*/
readonly overline: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Invert background and foreground colors.
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly inverse: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Print the text but make it invisible.
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly hidden: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)*
2021-04-16 15:23:29 +07:00
*/
2021-04-18 00:33:03 +12:00
readonly strikethrough: this;
2021-04-16 15:23:29 +07:00
/**
2021-08-11 15:01:41 +02:00
Modifier: Print the text only when Chalk has a color level above zero.
2021-04-16 15:23:29 +07:00
Can be useful for things that are purely cosmetic.
*/
2021-04-18 00:33:03 +12:00
readonly visible: this;
2021-04-16 15:23:29 +07:00
2021-04-18 00:33:03 +12:00
readonly black: this;
readonly red: this;
readonly green: this;
readonly yellow: this;
readonly blue: this;
readonly magenta: this;
readonly cyan: this;
readonly white: this;
2021-04-16 15:23:29 +07:00
/*
Alias for `blackBright`.
*/
2021-04-18 00:33:03 +12:00
readonly gray: this;
2021-04-16 15:23:29 +07:00
/*
Alias for `blackBright`.
*/
2021-04-18 00:33:03 +12:00
readonly grey: this;
readonly blackBright: this;
readonly redBright: this;
readonly greenBright: this;
readonly yellowBright: this;
readonly blueBright: this;
readonly magentaBright: this;
readonly cyanBright: this;
readonly whiteBright: this;
readonly bgBlack: this;
readonly bgRed: this;
readonly bgGreen: this;
readonly bgYellow: this;
readonly bgBlue: this;
readonly bgMagenta: this;
readonly bgCyan: this;
readonly bgWhite: this;
2021-04-16 15:23:29 +07:00
/*
Alias for `bgBlackBright`.
*/
2021-04-18 00:33:03 +12:00
readonly bgGray: this;
2021-04-16 15:23:29 +07:00
/*
Alias for `bgBlackBright`.
*/
2021-04-18 00:33:03 +12:00
readonly bgGrey: this;
2021-04-16 15:23:29 +07:00
2021-04-18 00:33:03 +12:00
readonly bgBlackBright: this;
readonly bgRedBright: this;
readonly bgGreenBright: this;
readonly bgYellowBright: this;
readonly bgBlueBright: this;
readonly bgMagentaBright: this;
readonly bgCyanBright: this;
readonly bgWhiteBright: this;
}
/**
Main Chalk object that allows to chain styles together.
2021-04-16 15:23:29 +07:00
Call the last one as a method with a string argument.
2021-04-16 15:23:29 +07:00
Order doesn't matter, and later styles take precedent in case of a conflict.
2021-04-16 15:23:29 +07:00
This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
*/
declare const chalk: ChalkInstance;
2021-04-18 00:33:03 +12:00
export const supportsColor: ColorInfo;
2021-04-18 00:33:03 +12:00
export const chalkStderr: typeof chalk;
export const supportsColorStderr: typeof supportsColor;
export {
ColorInfo,
ColorSupport,
ColorSupportLevel,
2021-11-26 16:34:27 +07:00
// } from '#supports-color';
} from './vendor/supports-color/index.js';
export const modifiers: readonly Modifiers[];
export const foregroundColors: readonly ForegroundColor[];
export const backgroundColors: readonly BackgroundColor[];
export const colors: readonly Color[];
2021-04-16 15:23:29 +07:00
export default chalk;