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.
Parse and roundtrip via arrays
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
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);
f
decodeTextStream(stream: ReadableStream<string>): ReadableStream<IniSection>
Decode a text stream into INI sections.
f
encodeSectionStream(stream: ReadableStream<IniSection>): ReadableStream<string>
Encode a stream of INI sections into text lines.
f
parseArray(text: string): Promise<[string | null, string[][]][]>
Parse an INI string into an array of sections.
f
parseObject(text: string): Promise<Record<string, Record<string, unknown>>>
Parse an INI string into an object.
f
stringifyArray(array: [string | null, string[][]][]): Promise<string>
Convert an array of sections to an INI string.
f
stringifyObject(obj: Record<string, Record<string, unknown>>): Promise<string>
Convert an object to an INI string.
Usage
import * as mod from "mod.ts";