High-level utilities for working with INI data.

Provides helpers to parse and stringify INI text as arrays or objects, and stream-based transformers via decodeTextStream and encodeSectionStream.

The array-based functions (parseArray, stringifyArray) preserve duplicate keys and sections, while the object-based functions (parseObject, stringifyObject) collapse duplicates into single values.

Examples

Parse and roundtrip via arrays

import { assertEquals } from "@std/assert";
import { parseArray, stringifyArray } from "@hertzg/wg-ini";

const text = [
  "global_key=global_value",
  "",
  "[mysection]",
  "key1=1",
  "key2=2",
  "",
].join("\n");

const arr = await parseArray(text);
assertEquals(arr, [
  [null, [["global_key", "global_value"]]],
  ["mysection", [["key1", "1"], ["key2", "2"]]],
]);

const roundtrip = await stringifyArray(arr);
assertEquals(roundtrip, text);

Parse and stringify via objects

import { assertEquals } from "@std/assert";
import { parseObject, stringifyObject } from "@hertzg/wg-ini";

const text = [
  "global_key=global_value",
  "",
  "[mysection]",
  "key1=1",
  "key2=2",
  "",
].join("\n");

const obj = await parseObject(text);
assertEquals(obj, {
  "": { global_key: "global_value" },
  mysection: { key1: "1", key2: "2" },
});

const roundtrip = await stringifyObject(obj);
assertEquals(roundtrip, text);

Functions