chalk
- Version 5.3.0
- Published
- 43.7 kB
- No dependencies
- MIT license
Install
npm i chalk
yarn add chalk
pnpm add chalk
Overview
Terminal string styling done right
Index
Variables
Interfaces
ChalkInstance
- ansi256
- bgAnsi256
- bgBlack
- bgBlackBright
- bgBlue
- bgBlueBright
- bgCyan
- bgCyanBright
- bgGray
- bgGreen
- bgGreenBright
- bgGrey
- bgHex
- bgMagenta
- bgMagentaBright
- bgRed
- bgRedBright
- bgRgb
- bgWhite
- bgWhiteBright
- bgYellow
- bgYellowBright
- black
- blackBright
- blue
- blueBright
- bold
- cyan
- cyanBright
- dim
- gray
- green
- greenBright
- grey
- hex
- hidden
- inverse
- italic
- level
- magenta
- magentaBright
- overline
- red
- redBright
- reset
- rgb
- strikethrough
- underline
- visible
- white
- whiteBright
- yellow
- yellowBright
Type Aliases
Variables
variable backgroundColorNames
const backgroundColorNames: readonly (keyof BackgroundColor)[];
Basic background color names.
variable backgroundColors
const backgroundColors: readonly (keyof BackgroundColor)[];
Deprecated
Use
backgroundColorNames
instead.Basic background color names.
variable chalk
const chalk: ChalkInstance;
Main Chalk object that allows to chain styles together.
Call the last one as a method with a string argument.
Order doesn't matter, and later styles take precedent in case of a conflict.
This simply means that
chalk.red.yellow.green
is equivalent tochalk.green
.
variable Chalk
const Chalk: new (options?: Options) => ChalkInstance;
Return a new Chalk instance.
variable chalkStderr
const chalkStderr: ChalkInstance;
variable colorNames
const colorNames: readonly ColorName[];
variable colors
const colors: readonly ColorName[];
Deprecated
Use
colorNames
instead.Basic color names. The combination of foreground and background color names.
variable foregroundColorNames
const foregroundColorNames: readonly (keyof ForegroundColor)[];
Basic foreground color names.
variable foregroundColors
const foregroundColors: readonly (keyof ForegroundColor)[];
Deprecated
Use
foregroundColorNames
instead.Basic foreground color names.
variable modifierNames
const modifierNames: readonly (keyof Modifier)[];
Basic modifier names.
variable modifiers
const modifiers: readonly (keyof Modifier)[];
Deprecated
Use
modifierNames
instead.Basic modifier names.
variable supportsColor
const supportsColor: ColorInfo;
variable supportsColorStderr
const supportsColorStderr: ColorInfo;
Interfaces
interface ChalkInstance
interface ChalkInstance {}
property ansi256
ansi256: (index: number) => this;
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
Example 1
``` import chalk from 'chalk';
chalk.ansi256(201); ```
property bgAnsi256
bgAnsi256: (index: number) => this;
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
Example 1
``` import chalk from 'chalk';
chalk.bgAnsi256(201); ```
property bgBlack
readonly bgBlack: this;
property bgBlackBright
readonly bgBlackBright: this;
property bgBlue
readonly bgBlue: this;
property bgBlueBright
readonly bgBlueBright: this;
property bgCyan
readonly bgCyan: this;
property bgCyanBright
readonly bgCyanBright: this;
property bgGray
readonly bgGray: this;
property bgGreen
readonly bgGreen: this;
property bgGreenBright
readonly bgGreenBright: this;
property bgGrey
readonly bgGrey: this;
property bgHex
bgHex: (color: string) => this;
Use HEX value to set background color.
Parameter color
Hexadecimal value representing the desired color.
Example 1
``` import chalk from 'chalk';
chalk.bgHex('#DEADED'); ```
property bgMagenta
readonly bgMagenta: this;
property bgMagentaBright
readonly bgMagentaBright: this;
property bgRed
readonly bgRed: this;
property bgRedBright
readonly bgRedBright: this;
property bgRgb
bgRgb: (red: number, green: number, blue: number) => this;
Use RGB values to set background color.
Example 1
``` import chalk from 'chalk';
chalk.bgRgb(222, 173, 237); ```
property bgWhite
readonly bgWhite: this;
property bgWhiteBright
readonly bgWhiteBright: this;
property bgYellow
readonly bgYellow: this;
property bgYellowBright
readonly bgYellowBright: this;
property black
readonly black: this;
property blackBright
readonly blackBright: this;
property blue
readonly blue: this;
property blueBright
readonly blueBright: this;
property bold
readonly bold: this;
Modifier: Make the text bold.
property cyan
readonly cyan: this;
property cyanBright
readonly cyanBright: this;
property dim
readonly dim: this;
Modifier: Make the text have lower opacity.
property gray
readonly gray: this;
property green
readonly green: this;
property greenBright
readonly greenBright: this;
property grey
readonly grey: this;
property hex
hex: (color: string) => this;
Use HEX value to set text color.
Parameter color
Hexadecimal value representing the desired color.
Example 1
``` import chalk from 'chalk';
chalk.hex('#DEADED'); ```
property hidden
readonly hidden: this;
Modifier: Print the text but make it invisible.
property inverse
readonly inverse: this;
Modifier: Invert background and foreground colors.
property italic
readonly italic: this;
Modifier: Make the text italic. *(Not widely supported)*
property level
level: ColorSupportLevel;
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.
property magenta
readonly magenta: this;
property magentaBright
readonly magentaBright: this;
property overline
readonly overline: this;
Modifier: Put a horizontal line above the text. *(Not widely supported)*
property red
readonly red: this;
property redBright
readonly redBright: this;
property reset
readonly reset: this;
Modifier: Reset the current style.
property rgb
rgb: (red: number, green: number, blue: number) => this;
Use RGB values to set text color.
Example 1
``` import chalk from 'chalk';
chalk.rgb(222, 173, 237); ```
property strikethrough
readonly strikethrough: this;
Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)*
property underline
readonly underline: this;
Modifier: Put a horizontal line below the text. *(Not widely supported)*
property visible
readonly visible: this;
Modifier: Print the text only when Chalk has a color level above zero.
Can be useful for things that are purely cosmetic.
property white
readonly white: this;
property whiteBright
readonly whiteBright: this;
property yellow
readonly yellow: this;
property yellowBright
readonly yellowBright: this;
call signature
(...text: unknown[]): string;
interface Options
interface Options {}
property level
readonly level?: ColorSupportLevel;
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.
Type Aliases
type BackgroundColor
type BackgroundColor = BackgroundColorName;
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)
type BackgroundColorName
type BackgroundColorName = keyof BackgroundColor;
Basic background color names.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
type Color
type Color = ColorName;
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)
type ColorInfo
type ColorInfo = ColorSupport | false;
type ColorName
type ColorName = ForegroundColorName | BackgroundColorName;
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)
type ColorSupport
type ColorSupport = { /** The color level. */ level: ColorSupportLevel;
/** Whether basic 16 colors are supported. */ hasBasic: boolean;
/** Whether ANSI 256 colors are supported. */ has256: boolean;
/** Whether Truecolor 16 million colors are supported. */ has16m: boolean;};
Detect whether the terminal supports color.
type ColorSupportLevel
type ColorSupportLevel = 0 | 1 | 2 | 3;
Levels: -
0
- All colors disabled. -1
- Basic 16 colors support. -2
- ANSI 256 colors support. -3
- Truecolor 16 million colors support.
type ForegroundColor
type ForegroundColor = ForegroundColorName;
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)
type ForegroundColorName
type ForegroundColorName = keyof ForegroundColor;
Basic foreground color names.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
type ModifierName
type ModifierName = keyof Modifier;
Basic modifier names.
type Modifiers
type Modifiers = ModifierName;
Deprecated
Use
ModifierName
instead.Basic modifier names.
Package Files (3)
Dependencies (0)
No dependencies.
Dev Dependencies (10)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/chalk
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/chalk)
- HTML<a href="https://www.jsdocs.io/package/chalk"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4192 ms. - Missing or incorrect documentation? Open an issue for this package.