namespace

TOML

namespace TOML

TOML related APIs

  • function parse(
    input: string | ArrayBufferLike | TypedArray<ArrayBufferLike> | DataView<ArrayBufferLike> | Blob
    ): object;

    Parse a TOML (v1.1.0) document into a JavaScript object.

    Date/time values parse as Temporal objects: offset date-times as Temporal.Instant, local date-times as Temporal.PlainDateTime, local dates as Temporal.PlainDate, and local times as Temporal.PlainTime. Integers outside Number.MAX_SAFE_INTEGER throw, since they cannot be represented losslessly as JavaScript numbers.

    @param input

    The TOML document to parse, as a string or UTF-8 bytes

    @returns

    A JavaScript object

  • 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'