Function stringify

  • Compile an object into an INI config string. Provide formatting options to modify the output.

    Parameters

    • object: object

      The object to stringify

    • options: StringifyOptions = {}

      The option to use

    Returns string

    The INI string

    import { stringify } from "@std/ini/stringify";
    import { assertEquals } from "@std/assert";

    const str = stringify({
    key1: "value1",
    key2: "value2",
    section1: {
    foo: "bar",
    },
    section2: {
    hello: "world",
    },
    });

    assertEquals(str, `key1=value1
    key2=value2
    [section1]
    foo=bar
    [section2]
    hello=world`);
    import { stringify } from "@std/ini/stringify";
    import { assertEquals } from "@std/assert";

    const str = stringify({
    "section X": {
    date: new Date("2024-06-10"),
    },
    "section Y": {
    name: "John"
    }
    }, {
    replacer(key, value, section) {
    if (section === "section X" && key === "date") {
    return value.toISOString().slice(0, 10);
    }
    return value;
    },
    });

    assertEquals(str, `[section X]
    date=2024-06-10
    [section Y]
    name=John`);