Transform streams for grouping INI lines into sections.

This module provides stream transformers that work with IniSection objects. Use IniSectionDecoderStream to group decoded INI lines into sections, and IniSectionEncoderStream to flatten sections back into individual lines.

For line-level processing, see the lines module. For convenient parse/stringify functions, see the main module.

Examples

Group lines into sections

import { assertEquals } from "@std/assert";
import { IniSectionDecoderStream } from "@hertzg/wg-ini/sections";
import type { IniLine } from "@hertzg/wg-ini/lines";

const lines: IniLine[] = [
  { $assign: ["global", "value"], $comment: null },
  { $section: "mysection", $trailer: "" },
  { $assign: ["key", "value"], $comment: null },
];

const sections = await Array.fromAsync(
  ReadableStream.from(lines).pipeThrough(new IniSectionDecoderStream())
);

assertEquals(sections.length, 2);
assertEquals(sections[0].section, null);
assertEquals(sections[0].entries.length, 1);
assertEquals(sections[1].section?.$section, "mysection");
assertEquals(sections[1].entries.length, 1);

Classes

c
IniSectionDecoderStream()

A transform stream that groups INI lines into sections.

c
IniSectionEncoderStream()

A transform stream that flattens INI sections back into individual lines.

Type Aliases

T
IniSection = { section: IniLineSection | null; entries: (IniLineAssign | IniLineComment | IniLineTrailer)[]; }

Represents an INI section with its header and entries.