A transform stream that decodes lines of an INI file into structured objects.
Parses each input line and emits one of four line types:
- IniLineComment: Lines starting with the comment delimiter
- IniLineSection: Lines with section brackets (e.g.,
[section]) - IniLineAssign: Lines with key-value pairs (e.g.,
key=value) - IniLineTrailer: Empty lines or unrecognized content
Since this processes line by line, it preserves duplicate keys and sections.
Input chunks are expected to be individual lines of text (use TextLineStream
to split text into lines first).
Decode INI lines with various content types
Decode INI lines with various content types
import { assertEquals } from "@std/assert"; import { IniLineDecoderStream } from "@hertzg/wg-ini/lines"; const stream = ReadableStream.from([ "# comment outside of section", "global_key=global_value # with comment", "duplicated=key", "duplicated=with other value", "[empty]", "[section with spaces] # and a comment", "key1=1", "key2=2", "[duplicated section]", "key1=1", "[duplicated section]", "key1=2", ]).pipeThrough(new IniLineDecoderStream()); const lines = await Array.fromAsync(stream); assertEquals(lines, [ { $comment: " comment outside of section" }, { $assign: ["global_key", "global_value "], $comment: " with comment" }, { $assign: ["duplicated", "key"], $comment: null }, { $assign: ["duplicated", "with other value"], $comment: null }, { $section: "empty", $trailer: "" }, { $section: "section with spaces", $trailer: " # and a comment" }, { $assign: ["key1", "1"], $comment: null }, { $assign: ["key2", "2"], $comment: null }, { $section: "duplicated section", $trailer: "" }, { $assign: ["key1", "1"], $comment: null }, { $section: "duplicated section", $trailer: "" }, { $assign: ["key1", "2"], $comment: null }, ]);
IniLineDecoderStream(options?: IniLineDecoderStreamOptions)
Create a new INI line decoder stream.
Parameters
optional
options: IniLineDecoderStreamOptions
Configuration options for parsing delimiters.