Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/ansi

Index

Background Functions

Const backgroundBlack

  • backgroundBlack<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for black background.

    example
    backgroundBlack("Foo"); // "\x1b[40mFoo\x1b[49m"
    backgroundBlack("Bar"); // "\x1b[40mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with black background.

Const backgroundBlue

  • backgroundBlue<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for blue background.

    example
    backgroundBlue("Foo"); // "\x1b[44mFoo\x1b[49m"
    backgroundBlue("Bar"); // "\x1b[44mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with blue background.

Const backgroundBrightBlue

  • backgroundBrightBlue<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright blue background.

    example
    backgroundBrightBlue("Foo"); // "\x1b[104mFoo\x1b[49m"
    backgroundBrightBlue("Bar"); // "\x1b[104mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright blue background.

Const backgroundBrightCyan

  • backgroundBrightCyan<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright cyan background.

    example
    backgroundBrightCyan("Foo"); // "\x1b[106mFoo\x1b[49m"
    backgroundBrightCyan("Bar"); // "\x1b[106mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright cyan background.

Const backgroundBrightGreen

  • backgroundBrightGreen<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright green background.

    example
    backgroundBrightGreen("Foo"); // "\x1b[102mFoo\x1b[49m"
    backgroundBrightGreen("Bar"); // "\x1b[102mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright green background.

Const backgroundBrightMagenta

  • backgroundBrightMagenta<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright magenta background.

    example
    backgroundBrightMagenta("Foo"); // "\x1b[105mFoo\x1b[49m"
    backgroundBrightMagenta("Bar"); // "\x1b[105mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright magenta background.

Const backgroundBrightRed

  • backgroundBrightRed<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright red background.

    example
    backgroundBrightRed("Foo"); // "\x1b[101mFoo\x1b[49m"
    backgroundBrightRed("Bar"); // "\x1b[101mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright red background.

Const backgroundBrightWhite

  • backgroundBrightWhite<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright white background.

    example
    backgroundBrightWhite("Foo"); // "\x1b[107mFoo\x1b[49m"
    backgroundBrightWhite("Bar"); // "\x1b[107mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright white background.

Const backgroundBrightYellow

  • backgroundBrightYellow<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright yellow background.

    example
    backgroundBrightYellow("Foo"); // "\x1b[103mFoo\x1b[49m"
    backgroundBrightYellow("Bar"); // "\x1b[103mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright yellow background.

Const backgroundColor

  • backgroundColor<Open>(...arg0: number & Open): (<Input>(input: Input) => Input) | (<Input>(input: Input) => `[${Open}m${Input}`)
  • Takes an open ANSI code and an input string and adds the open and close ANSI codes to that string (for background color).

    example
    backgroundColor(13)("Foo"); // "\x1b[13mFoo\x1b[49m"
    backgroundColor(42)("Bar"); // "\x1b[42mBar\x1b[49m"

    Type parameters

    • Open: number

    Parameters

    • Rest ...arg0: number & Open

    Returns (<Input>(input: Input) => Input) | (<Input>(input: Input) => `[${Open}m${Input}`)

    Curried function with close ANSI code for background in context.

Const backgroundCyan

  • backgroundCyan<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for cyan background.

    example
    backgroundCyan("Foo"); // "\x1b[46mFoo\x1b[49m"
    backgroundCyan("Bar"); // "\x1b[46mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with cyan background.

Const backgroundGray

  • backgroundGray<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for gray background.

    example
    backgroundGray("Foo"); // "\x1b[100mFoo\x1b[49m"
    backgroundGray("Bar"); // "\x1b[100mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with gray background.

Const backgroundGreen

  • backgroundGreen<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for green background.

    example
    backgroundGreen("Foo"); // "\x1b[42mFoo\x1b[49m"
    backgroundGreen("Bar"); // "\x1b[42mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with green background.

Const backgroundMagenta

  • backgroundMagenta<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for magenta background.

    example
    backgroundMagenta("Foo"); // "\x1b[45mFoo\x1b[49m"
    backgroundMagenta("Bar"); // "\x1b[45mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with magenta background.

Const backgroundRed

  • backgroundRed<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for red background.

    example
    backgroundRed("Foo"); // "\x1b[41mFoo\x1b[49m"
    backgroundRed("Bar"); // "\x1b[41mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with red background.

Const backgroundWhite

  • backgroundWhite<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for white background.

    example
    backgroundWhite("Foo"); // "\x1b[47mFoo\x1b[49m"
    backgroundWhite("Bar"); // "\x1b[47mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with white background.

Const backgroundYellow

  • backgroundYellow<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for yellow background.

    example
    backgroundYellow("Foo"); // "\x1b[43mFoo\x1b[49m"
    backgroundYellow("Bar"); // "\x1b[43mBar\x1b[49m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with yellow background.

Common Functions

Const ansi

  • ansi<Input>(input: Input): `[${Input}m`
  • Takes an input number and returns the escape ANSI sequence.

    example
    ansi(13); // "\x1b[13m"
    ansi(42); // "\x1b[42m"

    Type parameters

    • Input: number

    Parameters

    • input: Input

      Input to escape.

    Returns `[${Input}m`

    Escaped ANSI sequence.

Const format

  • format<Close>(close: Close): <Open>(open: Open) => <Input>(input: Input) => `[${Open}m${Input}[${Close}m`
  • Given an open, a close value and an input string, return formatted input (surrounded by open and close).

    example
    format(13)(42)("Foo"); // "\x1b[42mFoo\x1b[13m"
    format(42)(13)("Bar"); // "\x1b[13mBar\x1b[42m"

    Type parameters

    • Close: number

    Parameters

    • close: Close

      Close value.

    Returns <Open>(open: Open) => <Input>(input: Input) => `[${Open}m${Input}[${Close}m`

    Curried function with close in context.

      • <Open>(open: Open): <Input>(input: Input) => `[${Open}m${Input}[${Close}m`
      • Type parameters

        • Open: number

        Parameters

        • open: Open

        Returns <Input>(input: Input) => `[${Open}m${Input}[${Close}m`

          • <Input>(input: Input): `[${Open}m${Input}[${Close}m`
          • Type parameters

            • Input: string

            Parameters

            • input: Input

            Returns `[${Open}m${Input}[${Close}m`

            Curried function with open and close in context.

Const formattingEnabled

  • formattingEnabled(process?: { env?: ProcessEnv; stdout?: Pick<WriteStream & { fd: 1 }, "isTTY"> }): boolean
  • Given a NodeJS process, return true if colors are enabled.

    Parameters

    • process: { env?: ProcessEnv; stdout?: Pick<WriteStream & { fd: 1 }, "isTTY"> } = {}

      NodeJS process.

      • Optional Readonly env?: ProcessEnv
      • Optional Readonly stdout?: Pick<WriteStream & { fd: 1 }, "isTTY">

    Returns boolean

Const mix

  • mix(formatters: readonly ((input: string) => string)[]): (input: string) => string
  • Composes formatters.

    example
    const redTextWhiteBackground = mix([foregroundRed, backgroundWhite]);

    redTextWhiteBackground("Foo"); // "\x1b[47m\x1b[31mFoo\x1b[39m\x1b[49m"
    redTextWhiteBackground("Bar"); // "\x1b[47m\x1b[31mBar\x1b[39m\x1b[49m"

    Parameters

    • formatters: readonly ((input: string) => string)[]

      Array of formatters to be composed.

    Returns (input: string) => string

      • (input: string): string
      • Parameters

        • input: string

        Returns string

Const optionalFormat

  • optionalFormat<Close>(...arg0: Close & number): (<Open>(open: Open) => <Input>(input: Input) => `[${Open}m${Input}[${Close}m`) | ((_open: number) => <Input>(input: Input) => Input)
  • Impure version of format which changes depending on the current NodeJS process environment.

    Type parameters

    • Close: number

    Parameters

    • Rest ...arg0: Close & number

    Returns (<Open>(open: Open) => <Input>(input: Input) => `[${Open}m${Input}[${Close}m`) | ((_open: number) => <Input>(input: Input) => Input)

Foreground Functions

Const foregroundBlack

  • foregroundBlack<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for black foreground.

    example
    foregroundBlack("Foo"); // "\x1b[30mFoo\x1b[39m"
    foregroundBlack("Bar"); // "\x1b[30mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with black foreground.

Const foregroundBlue

  • foregroundBlue<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for blue foreground.

    example
    foregroundBlue("Foo"); // "\x1b[34mFoo\x1b[39m"
    foregroundBlue("Bar"); // "\x1b[34mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with blue foreground.

Const foregroundBrightBlue

  • foregroundBrightBlue<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright blue foreground.

    example
    foregroundBrightBlue("Foo"); // "\x1b[94mFoo\x1b[39m"
    foregroundBrightBlue("Bar"); // "\x1b[94mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright blue foreground.

Const foregroundBrightCyan

  • foregroundBrightCyan<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright cyan foreground.

    example
    foregroundBrightCyan("Foo"); // "\x1b[96mFoo\x1b[39m"
    foregroundBrightCyan("Bar"); // "\x1b[96mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright cyan foreground.

Const foregroundBrightGreen

  • foregroundBrightGreen<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright green foreground.

    example
    foregroundBrightGreen("Foo"); // "\x1b[92mFoo\x1b[39m"
    foregroundBrightGreen("Bar"); // "\x1b[92mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright green foreground.

Const foregroundBrightMagenta

  • foregroundBrightMagenta<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright magenta foreground.

    example
    foregroundBrightMagenta("Foo"); // "\x1b[95mFoo\x1b[39m"
    foregroundBrightMagenta("Bar"); // "\x1b[95mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright magenta foreground.

Const foregroundBrightRed

  • foregroundBrightRed<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright red foreground.

    example
    foregroundBrightRed("Foo"); // "\x1b[91mFoo\x1b[39m"
    foregroundBrightRed("Bar"); // "\x1b[91mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright red foreground.

Const foregroundBrightWhite

  • foregroundBrightWhite<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright white foreground.

    example
    foregroundBrightWhite("Foo"); // "\x1b[97mFoo\x1b[39m"
    foregroundBrightWhite("Bar"); // "\x1b[97mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright white foreground.

Const foregroundBrightYellow

  • foregroundBrightYellow<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bright yellow foreground.

    example
    foregroundBrightYellow("Foo"); // "\x1b[93mFoo\x1b[39m"
    foregroundBrightYellow("Bar"); // "\x1b[93mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bright yellow foreground.

Const foregroundColor

  • foregroundColor<Open>(...arg0: number & Open): (<Input>(input: Input) => Input) | (<Input>(input: Input) => `[${Open}m${Input}`)
  • Takes an open ANSI code and an input string and adds the open and close ANSI codes to that string (for text color).

    example
    foregroundColor(13)("Foo"); // "\x1b[13mFoo\x1b[39m"
    foregroundColor(42)("Bar"); // "\x1b[42mBar\x1b[39m"

    Type parameters

    • Open: number

    Parameters

    • Rest ...arg0: number & Open

    Returns (<Input>(input: Input) => Input) | (<Input>(input: Input) => `[${Open}m${Input}`)

    Curried function with close ANSI code for text color in context.

Const foregroundCyan

  • foregroundCyan<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for cyan foreground.

    example
    foregroundCyan("Foo"); // "\x1b[36mFoo\x1b[39m"
    foregroundCyan("Bar"); // "\x1b[36mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with cyan foreground.

Const foregroundGray

  • foregroundGray<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for gray foreground.

    example
    foregroundGray("Foo"); // "\x1b[90mFoo\x1b[39m"
    foregroundGray("Bar"); // "\x1b[90mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with gray foreground.

Const foregroundGreen

  • foregroundGreen<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for green foreground.

    example
    foregroundGreen("Foo"); // "\x1b[32mFoo\x1b[39m"
    foregroundGreen("Bar"); // "\x1b[32mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with green foreground.

Const foregroundMagenta

  • foregroundMagenta<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for magenta foreground.

    example
    foregroundMagenta("Foo"); // "\x1b[35mFoo\x1b[39m"
    foregroundMagenta("Bar"); // "\x1b[35mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with magenta foreground.

Const foregroundRed

  • foregroundRed<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for red foreground.

    example
    foregroundRed("Foo"); // "\x1b[31mFoo\x1b[39m"
    foregroundRed("Bar"); // "\x1b[31mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with red foreground.

Const foregroundWhite

  • foregroundWhite<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for white foreground.

    example
    foregroundWhite("Foo"); // "\x1b[37mFoo\x1b[39m"
    foregroundWhite("Bar"); // "\x1b[37mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with white foreground.

Const foregroundYellow

  • foregroundYellow<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for yellow foreground.

    example
    foregroundYellow("Foo"); // "\x1b[33mFoo\x1b[39m"
    foregroundYellow("Bar"); // "\x1b[33mBar\x1b[39m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with yellow foreground.

Text Functions

Const bold

  • bold<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for bold text.

    example
    bold("Foo"); // "\x1b[1mFoo\x1b[22m"
    bold("Bar"); // "\x1b[1mBar\x1b[22m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with bold format.

Const dimmed

  • dimmed<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for dimmed text.

    example
    dimmed("Foo"); // "\x1b[2mFoo\x1b[22m"
    dimmed("Bar"); // "\x1b[2mBar\x1b[22m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with dimmed format.

Const inverse

  • inverse<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for inverse text.

    example
    inverse("Foo"); // "\x1b[7mFoo\x1b[27m"
    inverse("Bar"); // "\x1b[7mBar\x1b[27m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with inverse format.

Const italic

  • italic<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for italic text.

    example
    italic("Foo"); // "\x1b[3mFoo\x1b[23m"
    italic("Bar"); // "\x1b[3mBar\x1b[23m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with italic format.

Const strikethrough

  • strikethrough<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for strikethrough text.

    example
    strikethrough("Foo"); // "\x1b[9mFoo\x1b[29m"
    strikethrough("Bar"); // "\x1b[9mBar\x1b[29m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with strikethrough format.

Const underlined

  • underlined<Input>(...input: Input): Input | `${Input}`
  • Takes an input string and adds the ANSI codes for underlined text.

    example
    underlined("Foo"); // "\x1b[4mFoo\x1b[24m"
    underlined("Bar"); // "\x1b[4mBar\x1b[24m"

    Type parameters

    • Input: string

    Parameters

    • Rest ...input: Input

    Returns Input | `${Input}`

    input string with underlined format.