chalk

  • Version 5.0.0
  • Published
  • 41.3 kB
  • No dependencies
  • MIT license

Install

npm i chalk
yarn add chalk
pnpm add chalk

Overview

Terminal string styling done right

Index

Variables

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 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 ColorSupport

                                                                                    interface ColorSupport {}
                                                                                    • Detect whether the terminal supports color.

                                                                                    property has16m

                                                                                    has16m: boolean;
                                                                                    • Whether Truecolor 16 million colors are supported.

                                                                                    property has256

                                                                                    has256: boolean;
                                                                                    • Whether ANSI 256 colors are supported.

                                                                                    property hasBasic

                                                                                    hasBasic: boolean;
                                                                                    • Whether basic 16 colors are supported.

                                                                                    property level

                                                                                    level: ColorSupportLevel;
                                                                                    • The color level.

                                                                                    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 =
                                                                                      | 'bgBlack'
                                                                                      | 'bgRed'
                                                                                      | 'bgGreen'
                                                                                      | 'bgYellow'
                                                                                      | 'bgBlue'
                                                                                      | 'bgMagenta'
                                                                                      | 'bgCyan'
                                                                                      | 'bgWhite'
                                                                                      | 'bgGray'
                                                                                      | 'bgGrey'
                                                                                      | 'bgBlackBright'
                                                                                      | 'bgRedBright'
                                                                                      | 'bgGreenBright'
                                                                                      | 'bgYellowBright'
                                                                                      | 'bgBlueBright'
                                                                                      | 'bgMagentaBright'
                                                                                      | 'bgCyanBright'
                                                                                      | 'bgWhiteBright';
                                                                                      • Basic background colors.

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

                                                                                      type Color

                                                                                      type Color = ForegroundColor | BackgroundColor;
                                                                                      • Basic colors.

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

                                                                                      type ColorInfo

                                                                                      type ColorInfo = ColorSupport | false;

                                                                                        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 =
                                                                                        | 'black'
                                                                                        | 'red'
                                                                                        | 'green'
                                                                                        | 'yellow'
                                                                                        | 'blue'
                                                                                        | 'magenta'
                                                                                        | 'cyan'
                                                                                        | 'white'
                                                                                        | 'gray'
                                                                                        | 'grey'
                                                                                        | 'blackBright'
                                                                                        | 'redBright'
                                                                                        | 'greenBright'
                                                                                        | 'yellowBright'
                                                                                        | 'blueBright'
                                                                                        | 'magentaBright'
                                                                                        | 'cyanBright'
                                                                                        | 'whiteBright';
                                                                                        • Basic foreground colors.

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

                                                                                        type Modifiers

                                                                                        type Modifiers =
                                                                                        | 'reset'
                                                                                        | 'bold'
                                                                                        | 'dim'
                                                                                        | 'italic'
                                                                                        | 'underline'
                                                                                        | 'overline'
                                                                                        | 'inverse'
                                                                                        | 'hidden'
                                                                                        | 'strikethrough'
                                                                                        | 'visible';

                                                                                          Package Files (2)

                                                                                          Dependencies (0)

                                                                                          No dependencies.

                                                                                          Dev Dependencies (10)

                                                                                          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>