Skip to content
VaelJS Blog

vael:fmt/inspect

Human-readable value inspection for debugging and diagnostic output.

Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes. Formats primitives, objects, arrays, maps, sets, typed arrays, dates, regular expressions, errors, symbols, and circular references.

import ... from "vael:fmt/inspect"
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)
import { inspect } from "vael:fmt/inspect";
console.log(inspect({ user: "alice", scores: [95, 87, 92] }));
console.log(inspect({ b: 1, a: 2 }, { sorted: true, compact: true }));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function inspect(value: unknown, options?: InspectOptions): string;

Format any JavaScript value into a human-readable diagnostic string.

Handles circular references safely ([Circular]), respects depth and iterableLimit, and avoids invoking getters unless options.getters is true.

Parameters
NameTypeDescription
valueunknownAny value to inspect.
options optionalInspectOptionsOptional formatting configuration.
Returns
string — Formatted string representation of value.
Exceptions
  • TypeError — when options is provided and not an object.
import { inspect } from "vael:fmt/inspect";
console.log(inspect("hello")); // "'hello'"
console.log(inspect(new Map([["k", 1]]))); // "Map(1) { 'k' => 1 }"
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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.

Properties
PropertyTypeDescriptionSince
colors optionalbooleanInclude ANSI color sequences in formatted output. Defaults to false.v0.0.0-alpha.2
compact optionalbooleanCollapse nested objects onto fewer lines when true, or force multi-line expansion when false.v0.0.0-alpha.2
depth optionalnumberMaximum recursion depth when formatting nested objects and collections. Defaults to 4.v0.0.0-alpha.2
breakLength optionalnumberMaximum line length before breaking collections across multiple lines. Defaults to 80.v0.0.0-alpha.2
escapeSequences optionalbooleanEscape control characters in string values. Defaults to true.v0.0.0-alpha.2
iterableLimit optionalnumberMaximum number of array, Map, Set, or object entries to display before truncating. Defaults to 100.v0.0.0-alpha.2
showProxy optionalbooleanInspect Proxy target and handler details when supported.v0.0.0-alpha.2
sorted optionalbooleanSort object property keys lexicographically. Defaults to false.v0.0.0-alpha.2
trailingComma optionalbooleanAppend a trailing comma on multi-line objects and arrays. Defaults to false.v0.0.0-alpha.2
getters optionalbooleanInvoke getter properties when inspecting objects instead of printing [Getter]. Defaults to false.v0.0.0-alpha.2
showHidden optionalbooleanInclude non-enumerable and symbol-keyed properties. Defaults to false.v0.0.0-alpha.2
strAbbreviateSize optionalnumberTruncate string values longer than this character count with "...".v0.0.0-alpha.2