Hierarchy

  • Use a template string.

    Remarks

    Template literals are unsupported for nested calls (see issue #341)

    Example

    import chalk = require('chalk');

    log(chalk`
    CPU: {red ${cpu.totalPercent}%}
    RAM: {green ${ram.used / ram.total * 100}%}
    DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
    `);

    Example

    import chalk = require('chalk');

    log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)

    Parameters

    Returns string

  • Parameters

    • Rest ...text: unknown[]

    Returns string

Properties

Instance: Instance

Return a new Chalk instance.

bgBlack: Chalk
bgBlackBright: Chalk
bgBlue: Chalk
bgBlueBright: Chalk
bgCyan: Chalk
bgCyanBright: Chalk
bgGray: Chalk

Alias for bgBlackBright.

bgGreen: Chalk
bgGreenBright: Chalk
bgGrey: Chalk

Alias for bgBlackBright.

bgMagenta: Chalk
bgMagentaBright: Chalk
bgRed: Chalk
bgRedBright: Chalk
bgWhite: Chalk
bgWhiteBright: Chalk
bgYellow: Chalk
bgYellowBright: Chalk
black: Chalk
blackBright: Chalk
blue: Chalk
blueBright: Chalk
bold: Chalk

Modifier: Make text bold.

cyan: Chalk
cyanBright: Chalk
dim: Chalk

Modifier: Emitting only a small amount of light.

gray: Chalk

Alias for blackBright.

green: Chalk
greenBright: Chalk
grey: Chalk

Alias for blackBright.

hidden: Chalk

Modifier: Prints the text, but makes it invisible.

inverse: Chalk

Modifier: Inverse background and foreground colors.

italic: Chalk

Modifier: Make text italic. (Not widely supported)

level: Level

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.
magenta: Chalk
magentaBright: Chalk
red: Chalk
redBright: Chalk
reset: Chalk

Modifier: Resets the current color chain.

strikethrough: Chalk

Modifier: Puts a horizontal line through the center of the text. (Not widely supported)

underline: Chalk

Modifier: Make text underline. (Not widely supported)

visible: Chalk

Modifier: Prints the text only when Chalk has a color support level > 0. Can be useful for things that are purely cosmetic.

white: Chalk
whiteBright: Chalk
yellow: Chalk
yellowBright: Chalk

Methods

  • Use a Select/Set Graphic Rendition (SGR) color code number to set text color.

    30 <= code && code < 38 || 90 <= code && code < 98 For example, 31 for red, 91 for redBright.

    Parameters

    • code: number

    Returns Chalk

  • Use a 8-bit unsigned number to set text color.

    Parameters

    • index: number

    Returns Chalk

  • Use a Select/Set Graphic Rendition (SGR) color code number to set background color.

    30 <= code && code < 38 || 90 <= code && code < 98 For example, 31 for red, 91 for redBright. Use the foreground code, not the background code (for example, not 41, nor 101).

    Parameters

    • code: number

    Returns Chalk

  • Use a 8-bit unsigned number to set background color.

    Parameters

    • index: number

    Returns Chalk

  • Use HEX value to set background color.

    Example

    import chalk = require('chalk');

    chalk.bgHex('#DEADED');

    Parameters

    • color: string

      Hexadecimal value representing the desired color.

    Returns Chalk

  • Use HSL values to set background color.

    Parameters

    • hue: number
    • saturation: number
    • lightness: number

    Returns Chalk

  • Use HSV values to set background color.

    Parameters

    • hue: number
    • saturation: number
    • value: number

    Returns Chalk

  • Use HWB values to set background color.

    Parameters

    • hue: number
    • whiteness: number
    • blackness: number

    Returns Chalk

  • Use keyword color value to set background color.

    Example

    import chalk = require('chalk');

    chalk.bgKeyword('orange');

    Parameters

    • color: string

      Keyword value representing the desired color.

    Returns Chalk

  • Use RGB values to set background color.

    Parameters

    • red: number
    • green: number
    • blue: number

    Returns Chalk

  • Use HEX value to set text color.

    Example

    import chalk = require('chalk');

    chalk.hex('#DEADED');

    Parameters

    • color: string

      Hexadecimal value representing the desired color.

    Returns Chalk

  • Use HSL values to set text color.

    Parameters

    • hue: number
    • saturation: number
    • lightness: number

    Returns Chalk

  • Use HSV values to set text color.

    Parameters

    • hue: number
    • saturation: number
    • value: number

    Returns Chalk

  • Use HWB values to set text color.

    Parameters

    • hue: number
    • whiteness: number
    • blackness: number

    Returns Chalk

  • Use keyword color value to set text color.

    Example

    import chalk = require('chalk');

    chalk.keyword('orange');

    Parameters

    • color: string

      Keyword value representing the desired color.

    Returns Chalk

  • Use RGB values to set text color.

    Parameters

    • red: number
    • green: number
    • blue: number

    Returns Chalk