chalk

  • Version 6.0.0
  • Published
  • 56 kB
  • No dependencies
  • MIT license

Install

npm i chalk
yarn add chalk
pnpm add chalk

Overview

Terminal string styling done right

Index

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 to chalk.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[];
    • Basic color names. The combination of foreground and background color names.

    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;

        variable underlineColorNames

        const underlineColorNames: readonly (keyof UnderlineColor)[];
        • Basic underline color names.

        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.

            The value is downsampled to the 16-color palette on terminals that only support basic colors (level 1), so chalk.ansi256(196) becomes 91 (ANSI escape for bright red).

            Example 1

            ``` import chalk from 'chalk';

            chalk.ansi256(201); ```

          property bgAnsi256

          bgAnsi256: (index: number) => this;
          • Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.

            The value is downsampled to the 16-color palette on terminals that only support basic colors (level 1), so chalk.bgAnsi256(196) becomes 101 (ANSI escape for bright red background).

            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;
                      • Alias for bgBlackBright.

                      property bgGreen

                      readonly bgGreen: this;

                        property bgGreenBright

                        readonly bgGreenBright: this;

                          property bgGrey

                          readonly bgGrey: this;
                          • Alias for bgBlackBright.

                          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;
                                                      • Alias for blackBright.

                                                      property green

                                                      readonly green: this;

                                                        property greenBright

                                                        readonly greenBright: this;

                                                          property grey

                                                          readonly grey: this;
                                                          • Alias for blackBright.

                                                          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.

                                                            Throws

                                                            If the assigned value is not an integer from 0 to 3.

                                                          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 underlineAnsi256

                                                                  underlineAnsi256: (index: number) => this;
                                                                  • Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set underline color.

                                                                    The underline color is only visible when an underline style is also applied.

                                                                    The value is downsampled to the first 16 palette entries on terminals that only support basic colors (level 1), so chalk.underlineAnsi256(196) becomes 9 (the palette index for bright red).

                                                                    Example 1

                                                                    ``` import chalk from 'chalk';

                                                                    chalk.underlineAnsi256(201).underlineCurly('Hello, world!'); ```

                                                                  property underlineBlack

                                                                  readonly underlineBlack: this;

                                                                    property underlineBlackBright

                                                                    readonly underlineBlackBright: this;

                                                                      property underlineBlue

                                                                      readonly underlineBlue: this;

                                                                        property underlineBlueBright

                                                                        readonly underlineBlueBright: this;

                                                                          property underlineCurly

                                                                          readonly underlineCurly: this;
                                                                          • Modifier: Put a curly horizontal line below the text. *(Not widely supported)*

                                                                          property underlineCyan

                                                                          readonly underlineCyan: this;

                                                                            property underlineCyanBright

                                                                            readonly underlineCyanBright: this;

                                                                              property underlineDashed

                                                                              readonly underlineDashed: this;
                                                                              • Modifier: Put a dashed horizontal line below the text. *(Not widely supported)*

                                                                              property underlineDotted

                                                                              readonly underlineDotted: this;
                                                                              • Modifier: Put a dotted horizontal line below the text. *(Not widely supported)*

                                                                              property underlineDouble

                                                                              readonly underlineDouble: this;
                                                                              • Modifier: Put a double horizontal line below the text. *(Not widely supported)*

                                                                              property underlineGray

                                                                              readonly underlineGray: this;
                                                                              • Alias for underlineBlackBright.

                                                                              property underlineGreen

                                                                              readonly underlineGreen: this;

                                                                                property underlineGreenBright

                                                                                readonly underlineGreenBright: this;

                                                                                  property underlineGrey

                                                                                  readonly underlineGrey: this;
                                                                                  • Alias for underlineBlackBright.

                                                                                  property underlineHex

                                                                                  underlineHex: (color: string) => this;
                                                                                  • Use HEX value to set underline color.

                                                                                    The underline color is only visible when an underline style is also applied.

                                                                                    Parameter color

                                                                                    Hexadecimal value representing the desired color.

                                                                                    Example 1

                                                                                    ``` import chalk from 'chalk';

                                                                                    chalk.underlineHex('#DEADED').underlineCurly('Hello, world!'); ```

                                                                                  property underlineMagenta

                                                                                  readonly underlineMagenta: this;

                                                                                    property underlineMagentaBright

                                                                                    readonly underlineMagentaBright: this;

                                                                                      property underlineRed

                                                                                      readonly underlineRed: this;

                                                                                        property underlineRedBright

                                                                                        readonly underlineRedBright: this;

                                                                                          property underlineRgb

                                                                                          underlineRgb: (red: number, green: number, blue: number) => this;
                                                                                          • Use RGB values to set underline color.

                                                                                            The underline color is only visible when an underline style is also applied.

                                                                                            Example 1

                                                                                            ``` import chalk from 'chalk';

                                                                                            chalk.underlineRgb(222, 173, 237).underlineCurly('Hello, world!'); ```

                                                                                          property underlineWhite

                                                                                          readonly underlineWhite: this;

                                                                                            property underlineWhiteBright

                                                                                            readonly underlineWhiteBright: this;

                                                                                              property underlineYellow

                                                                                              readonly underlineYellow: this;

                                                                                                property underlineYellowBright

                                                                                                readonly underlineYellowBright: this;

                                                                                                  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 | undefined;
                                                                                                              • 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.

                                                                                                                Omit this option, or pass undefined, to have the level detected instead.

                                                                                                                Throws

                                                                                                                If the value is neither undefined nor an integer from 0 to 3.

                                                                                                              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.

                                                                                                                type UnderlineColorName

                                                                                                                type UnderlineColorName = keyof UnderlineColor;
                                                                                                                • Basic underline color names.

                                                                                                                  [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)

                                                                                                                Package Files (3)

                                                                                                                Dependencies (0)

                                                                                                                No dependencies.

                                                                                                                Dev Dependencies (11)

                                                                                                                Peer Dependencies (0)

                                                                                                                No peer dependencies.

                                                                                                                Badge

                                                                                                                To add a badge like this onejsDocs.io badgeto 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>