function

TOML.stringify

function stringify(
input: unknown,
replacer?: null,
space?: string | number
): undefined | string;

Serialize a JavaScript object to a TOML document.

The top-level value must be an object (a TOML document is a table). Temporal.Instant, Temporal.PlainDateTime, Temporal.PlainDate, and Temporal.PlainTime values become the corresponding TOML date/time literals, Temporal.ZonedDateTime becomes an offset date-time, and Date becomes an offset date-time in UTC; time-zone and calendar annotations are dropped, since TOML has no syntax for them. null, BigInt, circular structures, invalid Dates, date values outside years 0000–9999, and Temporal types with no TOML form (Temporal.PlainYearMonth, Temporal.PlainMonthDay, Temporal.Duration) throw, since TOML cannot represent them; undefined, function, and symbol properties are skipped (inside arrays they throw, since TOML arrays cannot have holes).

@param input

The JavaScript object to serialize.

@param replacer

Not supported; pass undefined or null.

@param space

Accepted for signature parity with YAML.stringify and JSON5.stringify, but ignored: TOML output is line-oriented.

@returns

A TOML document string, or undefined if the input is undefined, a function, or a symbol.

import { TOML } from "bun";
TOML.stringify({ name: "app", server: { port: 8080 } });
// 'name = "app"\n\n[server]\nport = 8080\n'