Skip to main content

@std/fmt@1.0.6
Built and signed on GitHub Actions

Utilities for formatting values, such as adding colors to text, formatting durations, printf utils, formatting byte numbers.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (1.0.6)

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 "@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

Set background color to black.

f
bgBlue

Set background color to blue.

f
bgBrightBlack

Set background color to bright black.

f
bgBrightBlue

Set background color to bright blue.

f
bgBrightCyan

Set background color to bright cyan.

f
bgBrightGreen

Set background color to bright green.

f
bgBrightMagenta

Set background color to bright magenta.

f
bgBrightRed

Set background color to bright red.

f
bgBrightWhite

Set background color to bright white.

f
bgBrightYellow

Set background color to bright yellow.

f
bgCyan

Set background color to cyan.

f
bgGreen

Set background color to green.

f
bgMagenta

Set background color to magenta.

f
bgRed

Set background color to red.

f
bgRgb24

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

f
bgRgb8

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

f
bgWhite

Set background color to white.

f
bgYellow

Set background color to yellow.

f
black

Set text color to black.

f
blue

Set text color to blue.

f
bold

Make the text bold.

f
brightBlack

Set text color to bright black.

f
brightBlue

Set text color to bright blue.

f
brightCyan

Set text color to bright cyan.

f
brightGreen

Set text color to bright green.

f
brightMagenta

Set text color to bright magenta.

f
brightRed

Set text color to bright red.

f
brightWhite

Set text color to bright white.

f
brightYellow

Set text color to bright yellow.

f
cyan

Set text color to cyan.

f
dim

The text emits only a small amount of light.

f
getColorEnabled

Get whether text color change is enabled or disabled.

f
gray

Set text color to gray.

f
green

Set text color to green.

f
hidden

Make the text hidden.

f
inverse

Invert background color and text color.

f
italic

Make the text italic.

f
magenta

Set text color to magenta.

f
red

Set text color to red.

f
reset

Reset the text modified.

f
rgb24

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

f
rgb8

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

f
setColorEnabled

Enable or disable text color when styling.

f
strikethrough

Put horizontal line through the center of the text.

f
stripAnsiCode

Remove ANSI escape codes from the string.

f
underline

Make the text underline.

f
white

Set text color to white.

f
yellow

Set text color to yellow.

Interfaces

I
Rgb

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

Add Package

deno add jsr:@std/fmt

Import symbol

import * as mod from "@std/fmt/colors";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@std/fmt/colors";

Add Package

npx jsr add @std/fmt

Import symbol

import * as mod from "@std/fmt/colors";

Add Package

yarn dlx jsr add @std/fmt

Import symbol

import * as mod from "@std/fmt/colors";

Add Package

pnpm dlx jsr add @std/fmt

Import symbol

import * as mod from "@std/fmt/colors";

Add Package

bunx jsr add @std/fmt

Import symbol

import * as mod from "@std/fmt/colors";