effect-io-ai

Package: effect
Module: Formatter

Formatter.format

Converts any JavaScript value into a human-readable string.

When to use

Use when you need to format arbitrary JavaScript values for debugging, logging, or error messages.

Details

Example (Formatting compact output)

import { Formatter } from "effect"

console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}

Example (Pretty-printed output)

import { Formatter } from "effect"

console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
//   "a": 1,
//   "b": [
//     2,
//     3
//   ]
// }

Example (Handling circular references)

import { Formatter } from "effect"

const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}

See

Signature

declare const format: (input: unknown, options?: { readonly space?: number | string | undefined; readonly ignoreToString?: boolean | undefined; }) => string

Source

Since v2.0.0