vael:fmt/strip-ansi-code
Strip ANSI escape sequences from strings.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Removes CSI, OSC, and SGR escape sequences while preserving visible text
and whitespace.
import ... from "vael:fmt/strip-ansi-code"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature:
vael-fmt (enabled by default in vaeljs-core and vaeljs-lite-core)Example
Section titled “Example”import { stripAnsiCode } from "vael:fmt/strip-ansi-code";
const colored = "\x1b[31mError\x1b[0m: Something failed";console.log(stripAnsiCode(colored)); // "Error: Something failed"API Symbols
Functions
Section titled “Functions”stripAnsiCode
Section titled “stripAnsiCode”export function stripAnsiCode(text: string): string;
Remove all ANSI escape sequences from text.
Parameters
| Name | Type | Description |
|---|---|---|
text | string | Input string potentially containing ANSI escape sequences. |
Returns
string — Plain string with ANSI escape sequences removed.Exceptions
TypeError— whentextis not a string.
import { stripAnsiCode } from "vael:fmt/strip-ansi-code";
console.log(stripAnsiCode("\x1b[1m\x1b[32mOK\x1b[0m")); // "OK"