chalk

  • Version 4.1.2
  • Published
  • 35 kB
  • 2 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: chalk.Chalk &
chalk.ChalkFunction & {
supportsColor: chalk.ColorSupport | false;
Level: chalk.Level;
Color: Color;
ForegroundColor: ForegroundColor;
BackgroundColor: BackgroundColor;
Modifiers: Modifiers;
stderr: chalk.Chalk & { supportsColor: chalk.ColorSupport | false };
};
  • 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.

Interfaces

interface Chalk

interface Chalk extends ChalkFunction {}

    property bgBlack

    readonly bgBlack: Chalk;

      property bgBlackBright

      readonly bgBlackBright: Chalk;

        property bgBlue

        readonly bgBlue: Chalk;

          property bgBlueBright

          readonly bgBlueBright: Chalk;

            property bgCyan

            readonly bgCyan: Chalk;

              property bgCyanBright

              readonly bgCyanBright: Chalk;

                property bgGray

                readonly bgGray: Chalk;

                  property bgGreen

                  readonly bgGreen: Chalk;

                    property bgGreenBright

                    readonly bgGreenBright: Chalk;

                      property bgGrey

                      readonly bgGrey: Chalk;

                        property bgMagenta

                        readonly bgMagenta: Chalk;

                          property bgMagentaBright

                          readonly bgMagentaBright: Chalk;

                            property bgRed

                            readonly bgRed: Chalk;

                              property bgRedBright

                              readonly bgRedBright: Chalk;

                                property bgWhite

                                readonly bgWhite: Chalk;

                                  property bgWhiteBright

                                  readonly bgWhiteBright: Chalk;

                                    property bgYellow

                                    readonly bgYellow: Chalk;

                                      property bgYellowBright

                                      readonly bgYellowBright: Chalk;

                                        property black

                                        readonly black: Chalk;

                                          property blackBright

                                          readonly blackBright: Chalk;

                                            property blue

                                            readonly blue: Chalk;

                                              property blueBright

                                              readonly blueBright: Chalk;

                                                property bold

                                                readonly bold: Chalk;
                                                • Modifier: Make text bold.

                                                property cyan

                                                readonly cyan: Chalk;

                                                  property cyanBright

                                                  readonly cyanBright: Chalk;

                                                    property dim

                                                    readonly dim: Chalk;
                                                    • Modifier: Emitting only a small amount of light.

                                                    property gray

                                                    readonly gray: Chalk;

                                                      property green

                                                      readonly green: Chalk;

                                                        property greenBright

                                                        readonly greenBright: Chalk;

                                                          property grey

                                                          readonly grey: Chalk;

                                                            property hidden

                                                            readonly hidden: Chalk;
                                                            • Modifier: Prints the text, but makes it invisible.

                                                            property Instance

                                                            Instance: Instance;
                                                            • Return a new Chalk instance.

                                                            property inverse

                                                            readonly inverse: Chalk;
                                                            • Modifier: Inverse background and foreground colors.

                                                            property italic

                                                            readonly italic: Chalk;
                                                            • Modifier: Make text italic. (Not widely supported)

                                                            property level

                                                            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.

                                                            property magenta

                                                            readonly magenta: Chalk;

                                                              property magentaBright

                                                              readonly magentaBright: Chalk;

                                                                property red

                                                                readonly red: Chalk;

                                                                  property redBright

                                                                  readonly redBright: Chalk;

                                                                    property reset

                                                                    readonly reset: Chalk;
                                                                    • Modifier: Resets the current color chain.

                                                                    property strikethrough

                                                                    readonly strikethrough: Chalk;
                                                                    • Modifier: Puts a horizontal line through the center of the text. (Not widely supported)

                                                                    property underline

                                                                    readonly underline: Chalk;
                                                                    • Modifier: Make text underline. (Not widely supported)

                                                                    property visible

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

                                                                    property white

                                                                    readonly white: Chalk;

                                                                      property whiteBright

                                                                      readonly whiteBright: Chalk;

                                                                        property yellow

                                                                        readonly yellow: Chalk;

                                                                          property yellowBright

                                                                          readonly yellowBright: Chalk;

                                                                            method ansi

                                                                            ansi: (code: number) => Chalk;
                                                                            • Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.

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

                                                                            method ansi256

                                                                            ansi256: (index: number) => Chalk;
                                                                            • Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.

                                                                            method bgAnsi

                                                                            bgAnsi: (code: number) => Chalk;
                                                                            • Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) 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).

                                                                            method bgAnsi256

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

                                                                            method bgHex

                                                                            bgHex: (color: string) => Chalk;
                                                                            • Use HEX value to set background color.

                                                                              Parameter color

                                                                              Hexadecimal value representing the desired color.

                                                                              Example 1

                                                                              ``` import chalk = require('chalk');

                                                                              chalk.bgHex('#DEADED'); ```

                                                                            method bgHsl

                                                                            bgHsl: (hue: number, saturation: number, lightness: number) => Chalk;
                                                                            • Use HSL values to set background color.

                                                                            method bgHsv

                                                                            bgHsv: (hue: number, saturation: number, value: number) => Chalk;
                                                                            • Use HSV values to set background color.

                                                                            method bgHwb

                                                                            bgHwb: (hue: number, whiteness: number, blackness: number) => Chalk;
                                                                            • Use HWB values to set background color.

                                                                            method bgKeyword

                                                                            bgKeyword: (color: string) => Chalk;
                                                                            • Use keyword color value to set background color.

                                                                              Parameter color

                                                                              Keyword value representing the desired color.

                                                                              Example 1

                                                                              ``` import chalk = require('chalk');

                                                                              chalk.bgKeyword('orange'); ```

                                                                            method bgRgb

                                                                            bgRgb: (red: number, green: number, blue: number) => Chalk;
                                                                            • Use RGB values to set background color.

                                                                            method hex

                                                                            hex: (color: string) => Chalk;
                                                                            • Use HEX value to set text color.

                                                                              Parameter color

                                                                              Hexadecimal value representing the desired color.

                                                                              Example 1

                                                                              ``` import chalk = require('chalk');

                                                                              chalk.hex('#DEADED'); ```

                                                                            method hsl

                                                                            hsl: (hue: number, saturation: number, lightness: number) => Chalk;
                                                                            • Use HSL values to set text color.

                                                                            method hsv

                                                                            hsv: (hue: number, saturation: number, value: number) => Chalk;
                                                                            • Use HSV values to set text color.

                                                                            method hwb

                                                                            hwb: (hue: number, whiteness: number, blackness: number) => Chalk;
                                                                            • Use HWB values to set text color.

                                                                            method keyword

                                                                            keyword: (color: string) => Chalk;
                                                                            • Use keyword color value to set text color.

                                                                              Parameter color

                                                                              Keyword value representing the desired color.

                                                                              Example 1

                                                                              ``` import chalk = require('chalk');

                                                                              chalk.keyword('orange'); ```

                                                                            method rgb

                                                                            rgb: (red: number, green: number, blue: number) => Chalk;
                                                                            • Use RGB values to set text color.

                                                                            interface ChalkFunction

                                                                            interface ChalkFunction {}

                                                                              call signature

                                                                              (text: TemplateStringsArray, ...placeholders: unknown[]): string;
                                                                              • Use a template string.

                                                                                Remarks

                                                                                Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))

                                                                                Example 1

                                                                                ``` 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 2

                                                                                ``` import chalk = require('chalk');

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

                                                                              call signature

                                                                              (...text: unknown[]): string;

                                                                                interface ColorSupport

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

                                                                                property has16m

                                                                                has16m: boolean;
                                                                                • Return whether Chalk supports Truecolor 16 million colors.

                                                                                property has256

                                                                                has256: boolean;
                                                                                • Return whether Chalk supports ANSI 256 colors.

                                                                                property hasBasic

                                                                                hasBasic: boolean;
                                                                                • Return whether Chalk supports basic 16 colors.

                                                                                property level

                                                                                level: Level;
                                                                                • The color level used by Chalk.

                                                                                interface Options

                                                                                interface Options {}

                                                                                  property level

                                                                                  level?: Level;
                                                                                  • 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 Instance

                                                                                  type Instance = new (options?: Options) => Chalk;
                                                                                  • Return a new Chalk instance.

                                                                                  type Level

                                                                                  type Level = 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.

                                                                                  Package Files (1)

                                                                                  Dependencies (2)

                                                                                  Dev Dependencies (9)

                                                                                  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>