UNPKG

keep-a-changelog

Version:

Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.

60 lines (59 loc) 1.41 kB
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. import { IniMap } from "./ini_map.js"; /** * Parse an INI config string into an object. Provide formatting options to override the default assignment operator. * * @example Usage * ```ts * import { parse } from "@std/ini/parse"; * import { assertEquals } from "@std/assert"; * * const parsed = parse(` * key = value * * [section 1] * foo = Hello * baz = World * `); * * assertEquals(parsed, { key: "value", "section 1": { foo: "Hello", baz: "World" } }) * ``` * * @example Using custom reviver * ```ts * import { parse } from "@std/ini/parse"; * import { assertEquals } from "@std/assert"; * * const parsed = parse(` * [section Foo] * date = 2012-10-10 * amount = 12345 * `, { * reviver(key, value, section) { * if (section === "section Foo") { * if (key === "date") { * return new Date(value); * } else if (key === "amount") { * return +value; * } * } * return value; * } * }); * * assertEquals(parsed, { * "section Foo": { * date: new Date("2012-10-10"), * amount: 12345, * } * }) * ``` * * @param text The text to parse * @param options The options to use * @return The parsed object */ export function parse(text, options) { return IniMap.from(text, options).toObject(); }