vael:fmt
Cross-runtime string formatting (sprintf, printf), value inspection
(inspect), and ANSI escape code stripping (stripAnsiCode).
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Byte and duration formatters are exposed from "vael:fmt/bytes" and
"vael:fmt/duration"; subpath modules "vael:fmt/printf",
"vael:fmt/inspect", and "vael:fmt/strip-ansi-code" provide focused
entry points for the symbols exported here.
import ... from "vael:fmt"
vael-fmt (enabled by default in vaeljs-core and vaeljs-lite-core)Example
Section titled “Example”import { echof, errorf, inspect, sprintf, stripAnsiCode } from "vael:fmt";
const msg = sprintf("Hello %s! You have %d messages.", "Alice", 5);echof("%s", msg);console.log(inspect({ user: "bob", scores: [95, 87, 92] }));console.log(stripAnsiCode("\x1b[31mError\x1b[0m: Failed"));sprintfv0.0.0-alpha.2args according to format and return the resulting string.printfv0.0.0-alpha.2args according to format and write the result to stdout without appending a trailing newline.printv0.0.0-alpha.2args with no separator and write them directly to stdout without a trailing newline.echov0.0.0-alpha.2args separated by single spaces to stdout, followed by a newline (\n).echofv0.0.0-alpha.2args according to format and write the result to stdout followed by a newline (\n).errorfv0.0.0-alpha.2args according to format and return a new Error instance whose .message is the formatted string.setNoColorv0.0.0-alpha.2%i and %I inspect formatting.inspectv0.0.0-alpha.2stripAnsiCodev0.0.0-alpha.2text.Functions
Section titled “Functions”sprintf
Section titled “sprintf”export function sprintf(format: string, ...args: unknown[]): string;
Format args according to format and return the resulting string.
Supports POSIX/Go verbs (%s, %d, %b, %o, %x, %X, %e, %E,
%f, %F, %g, %G, %c, %t, %v, %#v, %T, %j, %i, %I,
%%), flags (+, -, #, 0, space, <), width/precision (including
*), and Go 1-based positional indices (%[2]s). Unmatched verbs,
missing arguments, and unused extra arguments produce inline %!(...)
diagnostic markers.
| Name | Type | Description |
|---|---|---|
format | string | Format template string containing literal text and % directives. |
...args | unknown[] | Values interpolated by directives in format. |
string — Formatted string.TypeError— whenformatis not a string.
import { sprintf } from "vael:fmt";
console.log(sprintf("Value: %d, Hex: %#x, Float: %.2f", 255, 255, 3.14159));printf
Section titled “printf”export function printf(format: string, ...args: unknown[]): void;
Format args according to format and write the result to stdout
without appending a trailing newline.
| Name | Type | Description |
|---|---|---|
format | string | Format template string. |
...args | unknown[] | Values interpolated by directives in format. |
voidTypeError— whenformatis not a string.
import { printf } from "vael:fmt";
printf("Processing: %d%%\n", 75);export function print(...args: unknown[]): void;
Concatenate args with no separator and write them directly to stdout
without a trailing newline.
| Name | Type | Description |
|---|---|---|
...args | unknown[] | Values converted via String(...), concatenated, and written to stdout. |
voidimport { print } from "vael:fmt";
print("Hello", "World");export function echo(...args: unknown[]): void;
Write args separated by single spaces to stdout, followed by a newline
(\n).
| Name | Type | Description |
|---|---|---|
...args | unknown[] | Values converted via String(...), joined with spaces, and written to stdout. |
voidimport { echo } from "vael:fmt";
echo("Hello", "World");export function echof(format: string, ...args: unknown[]): void;
Format args according to format and write the result to stdout
followed by a newline (\n).
| Name | Type | Description |
|---|---|---|
format | string | Format template string. |
...args | unknown[] | Values interpolated by directives in format. |
voidTypeError— whenformatis not a string.
import { echof } from "vael:fmt";
echof("Name: %-10s Age: %d", "Alice", 30);errorf
Section titled “errorf”export function errorf(format: string, ...args: unknown[]): Error;
Format args according to format and return a new Error instance whose
.message is the formatted string.
| Name | Type | Description |
|---|---|---|
format | string | Format template string. |
...args | unknown[] | Values interpolated by directives in format. |
Error — New Error with formatted message.TypeError— whenformatis not a string.
import { errorf } from "vael:fmt";
throw errorf("File %s not found at line %d", "config.json", 42);setNoColor
Section titled “setNoColor”export function setNoColor(noColor: boolean): void;
Enable or disable ANSI color output in %i and %I inspect formatting.
| Name | Type | Description |
|---|---|---|
noColor | boolean | Pass true to disable colors or false to allow colors. |
voidTypeError— whennoColoris not a boolean.
inspect
Section titled “inspect”export function inspect(value: unknown, options?: InspectOptions): string;
Format any JavaScript value into a human-readable diagnostic string.
| Name | Type | Description |
|---|---|---|
value | unknown | Any value to inspect. |
options optional | InspectOptions | Optional formatting configuration. |
string — Formatted string representation of value.TypeError— whenoptionsis provided and not an object.
import { inspect } from "vael:fmt";
console.log(inspect({ a: 1, b: [2, 3] }, { compact: false }));stripAnsiCode
Section titled “stripAnsiCode”export function stripAnsiCode(text: string): string;
Remove all ANSI escape sequences from text.
| Name | Type | Description |
|---|---|---|
text | string | Input string potentially containing ANSI escape sequences. |
string — Plain string with ANSI escape sequences removed.TypeError— whentextis not a string.
import { stripAnsiCode } from "vael:fmt";
console.log(stripAnsiCode("\x1b[31mError\x1b[0m: Something failed"));Interfaces
Section titled “Interfaces”InspectOptions
Section titled “InspectOptions”export interface InspectOptions {
colors?: boolean;
compact?: boolean;
depth?: number;
breakLength?: number;
escapeSequences?: boolean;
iterableLimit?: number;
showProxy?: boolean;
sorted?: boolean;
trailingComma?: boolean;
getters?: boolean;
showHidden?: boolean;
strAbbreviateSize?: number;
}
Formatting options accepted by inspect.
| Property | Type | Description | Since |
|---|---|---|---|
colors optional | boolean | Include ANSI color sequences in formatted output. Defaults to false. | v0.0.0-alpha.2 |
compact optional | boolean | Collapse nested objects onto fewer lines when true, or force multi-line expansion when false. | v0.0.0-alpha.2 |
depth optional | number | Maximum recursion depth when formatting nested objects and collections. Defaults to 4. | v0.0.0-alpha.2 |
breakLength optional | number | Maximum line length before breaking collections across multiple lines. Defaults to 80. | v0.0.0-alpha.2 |
escapeSequences optional | boolean | Escape control characters in string values. Defaults to true. | v0.0.0-alpha.2 |
iterableLimit optional | number | Maximum number of array, Map, Set, or object entries to display before truncating. Defaults to 100. | v0.0.0-alpha.2 |
showProxy optional | boolean | Inspect Proxy target and handler details when supported. | v0.0.0-alpha.2 |
sorted optional | boolean | Sort object property keys lexicographically. Defaults to false. | v0.0.0-alpha.2 |
trailingComma optional | boolean | Append a trailing comma on multi-line objects and arrays. Defaults to false. | v0.0.0-alpha.2 |
getters optional | boolean | Invoke getter properties when inspecting objects instead of printing [Getter]. Defaults to false. | v0.0.0-alpha.2 |
showHidden optional | boolean | Include non-enumerable and symbol-keyed properties. Defaults to false. | v0.0.0-alpha.2 |
strAbbreviateSize optional | number | Truncate string values longer than this character count with "...". | v0.0.0-alpha.2 |
