function parseObject
parseObject(text: string): Promise<Record<string, Record<string, unknown>>>

Parse an INI string into an object.

Since it returns an object, it does not support duplicate keys or sections. If duplicates exist, later values overwrite earlier ones. This is the reverse of stringifyObject and uses parseArray under the hood.

The global section (entries before any [section] header) is stored under the empty string key "".

Examples

Parse INI to object

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

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

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

Parameters

text: string

The INI content as a string.

Return Type

Promise<Record<string, Record<string, unknown>>>

A promise resolving to a nested object of sections and key-value pairs.

Usage

import { parseObject } from "mod.ts";