@ende/fmt/colors

ende add jsr:@ende/fmt

Version 2026.10.15 on JSR.

String formatters and utilities for dealing with ANSI color codes.

Important

If printing directly to the console, it's recommended to style console output using CSS (guide here).

This module supports NO_COLOR environmental variable disabling any coloring if NO_COLOR is set.

import {
  bgBlue,
  bgRgb24,
  bgRgb8,
  bold,
  italic,
  red,
  rgb24,
  rgb8,
} from "@ende/fmt/colors";

console.log(bgBlue(italic(red(bold("Hello, World!")))));

// also supports 8bit colors

console.log(rgb8("Hello, World!", 42));

console.log(bgRgb8("Hello, World!", 42));

// and 24bit rgb

console.log(rgb24("Hello, World!", {
  r: 41,
  g: 42,
  b: 43,
}));

console.log(bgRgb24("Hello, World!", {
  r: 41,
  g: 42,
  b: 43,
}));

Exports

  • bgBlack — Set background color to black.
  • bgBlue — Set background color to blue.
  • bgBrightBlack — Set background color to bright black.
  • bgBrightBlue — Set background color to bright blue.
  • bgBrightCyan — Set background color to bright cyan.
  • bgBrightGreen — Set background color to bright green.
  • bgBrightMagenta — Set background color to bright magenta.
  • bgBrightRed — Set background color to bright red.
  • bgBrightWhite — Set background color to bright white.
  • bgBrightYellow — Set background color to bright yellow.
  • bgCyan — Set background color to cyan.
  • bgGreen — Set background color to green.
  • bgMagenta — Set background color to magenta.
  • bgRed — Set background color to red.
  • bgRgb24 — Set background color using 24bit rgb. `color` can be a number in range `0x000000` to `0xffffff` or an `Rgb`.
  • bgRgb8 — Set background color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
  • bgWhite — Set background color to white.
  • bgYellow — Set background color to yellow.
  • black — Set text color to black.
  • blue — Set text color to blue.
  • bold — Make the text bold.
  • brightBlack — Set text color to bright black.
  • brightBlue — Set text color to bright blue.
  • brightCyan — Set text color to bright cyan.
  • brightGreen — Set text color to bright green.
  • brightMagenta — Set text color to bright magenta.
  • brightRed — Set text color to bright red.
  • brightWhite — Set text color to bright white.
  • brightYellow — Set text color to bright yellow.
  • cyan — Set text color to cyan.
  • dim — The text emits only a small amount of light.
  • getColorEnabled — Get whether text color change is enabled or disabled.
  • gray — Set text color to gray.
  • green — Set text color to green.
  • hidden — Make the text hidden.
  • inverse — Invert background color and text color.
  • italic — Make the text italic.
  • magenta — Set text color to magenta.
  • red — Set text color to red.
  • reset — Reset the text modified.
  • Rgb — RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff`
  • rgb24 — Set text color using 24bit rgb. `color` can be a number in range `0x000000` to `0xffffff` or an `Rgb`.
  • rgb8 — Set text color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
  • setColorEnabled — Enable or disable text color when styling.
  • strikethrough — Put horizontal line through the center of the text.
  • stripAnsiCode — Remove ANSI escape codes from the string.
  • underline — Make the text underline.
  • white — Set text color to white.
  • yellow — Set text color to yellow.