Skip to content

assertcheck v0.5.15


assertcheck / fmtValue

Function: fmtValue()

ts
function fmtValue(v, depth?): string;

Defined in: src/format.ts:230

Formats any JavaScript value into a compact, type-coloured string suitable for display in error output.

Parameters

ParameterTypeDefault valueDescription
vunknownundefinedThe value to format.
depthnumber0Internal recursion depth (0 = top level).

Returns

string

A formatted, optionally coloured string.

Remarks

  • Strings are wrapped in "double quotes".
  • Arrays are abbreviated after 3 elements: [1, 2, 3, …+7].
  • Objects are abbreviated after 3 keys.
  • Recursion is limited to 2 levels deep.
  • When ANSI is available, each type is rendered in a distinct colour.

Example

ts
import { fmtValue } from "assertcheck/format"

fmtValue("hello")        // → "hello"   (green in terminal)
fmtValue(42)             // → 42        (yellow)
fmtValue([1, 2, 3, 4])   // → [1, 2, 3, …+1]
fmtValue(null)           // → null      (dim)

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.