Skip to main content

@std/fmt@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score58%
Published2 years ago (0.215.0)

String formatters and utilities for dealing with ANSI color codes.

This module is browser compatible.

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

Examples

Example 1

import {
  bgBlue,
  bgRgb24,
  bgRgb8,
  bold,
  italic,
  red,
  rgb24,
  rgb8,
} from "@std/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,
}));

Functions

f
bgBlack(str: string): string

Set background color to black.

f
bgBlue(str: string): string

Set background color to blue.

f
bgBrightBlack(str: string): string

Set background color to bright black.

f
bgBrightBlue(str: string): string

Set background color to bright blue.

f
bgBrightCyan(str: string): string

Set background color to bright cyan.

f
bgBrightGreen(str: string): string

Set background color to bright green.

f
bgBrightMagenta(str: string): string

Set background color to bright magenta.

f
bgBrightRed(str: string): string

Set background color to bright red.

f
bgBrightWhite(str: string): string

Set background color to bright white.

f
bgBrightYellow(str: string): string

Set background color to bright yellow.

f
bgCyan(str: string): string

Set background color to cyan.

f
bgGreen(str: string): string

Set background color to green.

f
bgMagenta(str: string): string

Set background color to magenta.

f
bgRed(str: string): string

Set background color to red.

f
bgRgb24(
str: string,
color: number | Rgb
): string

Set background color using 24bit rgb. color can be a number in range 0x000000 to 0xffffff or an Rgb.

f
bgRgb8(
str: string,
color: number
): string

Set background color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit

f
bgWhite(str: string): string

Set background color to white.

f
bgYellow(str: string): string

Set background color to yellow.

f
black(str: string): string

Set text color to black.

f
blue(str: string): string

Set text color to blue.

f
bold(str: string): string

Make the text bold.

f
brightBlack(str: string): string

Set text color to bright black.

f
brightBlue(str: string): string

Set text color to bright blue.

f
brightCyan(str: string): string

Set text color to bright cyan.

f
brightGreen(str: string): string

Set text color to bright green.

f
brightMagenta(str: string): string

Set text color to bright magenta.

f
brightRed(str: string): string

Set text color to bright red.

f
brightWhite(str: string): string

Set text color to bright white.

f
brightYellow(str: string): string

Set text color to bright yellow.

f
cyan(str: string): string

Set text color to cyan.

f
dim(str: string): string

The text emits only a small amount of light.

f
getColorEnabled(): boolean

Get whether text color change is enabled or disabled.

f
gray(str: string): string

Set text color to gray.

f
green(str: string): string

Set text color to green.

f
hidden(str: string): string

Make the text hidden.

f
inverse(str: string): string

Invert background color and text color.

f
italic(str: string): string

Make the text italic.

f
magenta(str: string): string

Set text color to magenta.

f
red(str: string): string

Set text color to red.

f
reset(str: string): string

Reset the text modified.

f
rgb24(
str: string,
color: number | Rgb
): string

Set text color using 24bit rgb. color can be a number in range 0x000000 to 0xffffff or an Rgb.

f
rgb8(
str: string,
color: number
): string

Set text color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit

f
setColorEnabled(value: boolean): void

Set changing text color to enabled or disabled

f
strikethrough(str: string): string

Put horizontal line through the center of the text.

f
stripAnsiCode(string: string): string

Remove ANSI escape codes from the string.

f
underline(str: string): string

Make the text underline.

f
white(str: string): string

Set text color to white.

f
yellow(str: string): string

Set text color to yellow.

f
stripColor(string: string): string

Remove ANSI escape codes from the string.

Interfaces

I

RGB 8-bits per channel. Each in range 0->255 or 0x00->0xff

  • b: number

    Blue component value

  • g: number

    Green component value

  • r: number

    Red component value

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.