Function stringify
- stringify(object, options?): string
Parameters
- object: object
The object to stringify
- options: StringifyOptions = {}
The option to use
Returns string
The INI string
Example: Usage
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`);Example: Using replacer option
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`);- object: object
Compile an object into an INI config string. Provide formatting options to modify the output.