ansiWrap()function
Wrap a string in the ANSI color/style codes (at the start), and ANSI_RESET at the end.
ansiWrap(input: string, ...wrappers: ImmutableArray<string>): void
Constants and a helper for wrapping terminal output in ANSI escape codes. Use these when writing CLI tools or test reporters that need colour and style without pulling in a third-party library.
ansiWrap().ansiWrap emits colour only when the runtime supports it, resolved once at module load the way the broader CLI ecosystem does — precedence FORCE_COLOR > NO_COLOR > TTY detection > default-off. Colour is emitted only when the output is an interactive TTY (or FORCE_COLOR opts in), so non-interactive sinks (files, log aggregators, serverless platforms like Cloudflare Workers) get plain text by default.NO_COLOR (any non-empty value) forces colour off, per no-color.org; FORCE_COLOR forces it on (0/false forces off) and overrides NO_COLOR.import { ansiWrap, ANSI_RED, ANSI_BOLD } from "shelving/util";
console.log(ansiWrap("Error!", ANSI_RED));
console.log(ansiWrap("Warning", ANSI_YELLOW, ANSI_BOLD)); // multiple wrappersimport { ANSI_SUCCESS, ANSI_FAILURE, ANSI_WAITING } from "shelving/util";
console.log(ANSI_SUCCESS); // ✓ in green
console.log(ANSI_FAILURE); // ✗ in red
console.log(ANSI_WAITING); // ⋯ in blueArrow icons (ANSI_UP, ANSI_DOWN, ANSI_LEFT, ANSI_RIGHT) are also available in blue.
Each icon is a plain string constant resolved once at module load via ansiWrap(), so colour is detected at import time — a TTY yields the coloured glyph, a non-interactive sink (file, log aggregator, Cloudflare Worker) yields the bare glyph.
import { ANSI_CYAN, ANSI_UNDERLINE, ANSI_RESET } from "shelving/util";
const styled = `${ANSI_CYAN}${ANSI_UNDERLINE}link text${ANSI_RESET}`;Wrap a string in the ANSI color/style codes (at the start), and ANSI_RESET at the end.
ansiWrap(input: string, ...wrappers: ImmutableArray<string>): void
ANSI escape code that resets the foreground colour to the terminal default.
ANSI escape code that sets the foreground colour to black.
ANSI escape code that sets the foreground colour to red.
ANSI escape code that sets the foreground colour to green.
ANSI escape code that sets the foreground colour to yellow.
ANSI escape code that sets the foreground colour to blue.
ANSI escape code that sets the foreground colour to magenta.
ANSI escape code that sets the foreground colour to cyan.
ANSI escape code that sets the foreground colour to white.
ANSI escape code that enables bold text.
ANSI escape code that enables italic text.
ANSI escape code that enables underlined text.
ANSI escape code that enables strikethrough text.
ANSI escape code that enables inverse (swapped foreground/background) text.
ANSI escape code that resets all colour and style attributes.
Blue-coloured waiting icon (⋯) for use in template literals, resolved once at module load.
Green-coloured success icon (✓) for use in template literals, resolved once at module load.
Red-coloured failure icon (✗) for use in template literals, resolved once at module load.
Blue-coloured up arrow icon (↑) for use in template literals, resolved once at module load.
Blue-coloured down arrow icon (↓) for use in template literals, resolved once at module load.
Blue-coloured right arrow icon (→) for use in template literals, resolved once at module load.
Blue-coloured left arrow icon (←) for use in template literals, resolved once at module load.