mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
BREAKING(ini): make IniMap
private (#5351)
This commit is contained in:
parent
be9eb72bdd
commit
e710e61b62
@ -40,25 +40,6 @@ export type ReviverFunction = (
|
||||
|
||||
/**
|
||||
* Class implementation for fine control of INI data structures.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const ini = new IniMap();
|
||||
* ini.set("section1", "keyA", 100)
|
||||
* assertEquals(ini.toString(), `[section1]
|
||||
* keyA=100`)
|
||||
*
|
||||
* ini.set('keyA', 25)
|
||||
* assertEquals(ini.toObject(), {
|
||||
* keyA: 25,
|
||||
* section1: {
|
||||
* keyA: 100,
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export class IniMap {
|
||||
#global = new Map<string, LineValue>();
|
||||
@ -181,25 +162,6 @@ export class IniMap {
|
||||
#formatting: FormattingOptions;
|
||||
|
||||
/** Constructs a new `IniMap`.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const ini = new IniMap();
|
||||
* ini.set("section1", "keyA", 100)
|
||||
* assertEquals(ini.toString(), `[section1]
|
||||
* keyA=100`)
|
||||
*
|
||||
* ini.set('keyA', 25)
|
||||
* assertEquals(ini.toObject(), {
|
||||
* keyA: 25,
|
||||
* section1: {
|
||||
* keyA: 100,
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param formatting Optional formatting options when printing an INI file.
|
||||
*/
|
||||
@ -210,26 +172,6 @@ export class IniMap {
|
||||
/**
|
||||
* Gets the count of key/value pairs.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg
|
||||
*
|
||||
* [section 2]
|
||||
* name = John`);
|
||||
*
|
||||
* assertEquals(iniMap.size, 6); // It has 6 keys in total
|
||||
* ```
|
||||
*
|
||||
* @returns The number of key/value pairs.
|
||||
*/
|
||||
get size(): number {
|
||||
@ -243,18 +185,6 @@ export class IniMap {
|
||||
/**
|
||||
* Gets the formatting options.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1`);
|
||||
*
|
||||
* assertEquals(iniMap.formatting.pretty, true);
|
||||
* ```
|
||||
*
|
||||
* @returns The formatting options
|
||||
*/
|
||||
get formatting(): FormattingOptions {
|
||||
@ -262,26 +192,6 @@ export class IniMap {
|
||||
}
|
||||
|
||||
/** Returns the comments in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* // Hey
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
* // Hello
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.comments.getAtLine(2), "// Hey")
|
||||
* assertEquals(iniMap.comments.getAtLine(5), "// Hello")
|
||||
* assertEquals(iniMap.comments.getAtSection("section 1"), "// Hello")
|
||||
* ```
|
||||
*
|
||||
* @returns The comments
|
||||
*/
|
||||
@ -292,38 +202,6 @@ export class IniMap {
|
||||
/**
|
||||
* Clears a single section or the entire INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg
|
||||
*
|
||||
* [section 2]
|
||||
* name = John`);
|
||||
*
|
||||
* iniMap.clear("section 1");
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 2": {
|
||||
* name: "John",
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* iniMap.clear(); // Clears all
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {});
|
||||
* ```
|
||||
*
|
||||
* @param sectionName The section name to clear
|
||||
*/
|
||||
clear(sectionName?: string): void {
|
||||
@ -345,32 +223,6 @@ export class IniMap {
|
||||
/**
|
||||
* Deletes a global key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* iniMap.delete("key0");
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param key The key to delete
|
||||
* @returns `true` if the key was deleted, `false` if not found.
|
||||
*/
|
||||
@ -378,38 +230,6 @@ export class IniMap {
|
||||
/**
|
||||
* Deletes a section key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg
|
||||
*
|
||||
* [section 2]
|
||||
* name = John`);
|
||||
*
|
||||
* iniMap.delete("section 1", "foo");
|
||||
* iniMap.delete("section 2", "name");
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* "section 2": {
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param section The section
|
||||
* @param key The key to delete
|
||||
* @returns `true` if the section was deleted, `false` if not found.
|
||||
@ -432,48 +252,11 @@ export class IniMap {
|
||||
/**
|
||||
* Gets a value from a global key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.get("key0"), "value0");
|
||||
* assertEquals(iniMap.get("key1"), "value1");
|
||||
* ```
|
||||
*
|
||||
* @param key The key to get
|
||||
* @returns The value for the key, or undefined if the key doesn't have a value
|
||||
*/
|
||||
get(key: string): unknown;
|
||||
/** Get a value from a section key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.get("section 1", "foo"), "Spam");
|
||||
* assertEquals(iniMap.get("section 1", "bar"), "Ham");
|
||||
* assertEquals(iniMap.get("section 1", "baz"), "Egg");
|
||||
* ```
|
||||
*
|
||||
* @param section The section
|
||||
* @param key The key to get
|
||||
@ -487,49 +270,12 @@ export class IniMap {
|
||||
/**
|
||||
* Check if a global key exists in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assert, assertFalse } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assert(iniMap.has("key0"));
|
||||
* assert(iniMap.has("key1"));
|
||||
* assertFalse(iniMap.has("key2"));
|
||||
* ```
|
||||
*
|
||||
* @param key The key to check
|
||||
* @returns `true` if the key has the value, `false` otherwise
|
||||
*/
|
||||
has(key: string): boolean;
|
||||
/** Check if a section key exists in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assert, assertFalse } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assert(iniMap.has("section 1", "foo"));
|
||||
* assert(iniMap.has("section 1", "bar"));
|
||||
* assertFalse(iniMap.has("section 1", "hello"));
|
||||
* ```
|
||||
* @param section The section
|
||||
* @param key The key to check
|
||||
* @returns `true` if the key has the value in the given section, `false` otherwise
|
||||
@ -542,35 +288,6 @@ export class IniMap {
|
||||
/**
|
||||
* Set the value of a global key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* iniMap.set("key1", "hello");
|
||||
* iniMap.set("hi", "hey");
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "hello",
|
||||
* hi: "hey",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param key The key to set the value
|
||||
* @param value The value to set
|
||||
* @returns The map object itself
|
||||
@ -579,37 +296,6 @@ export class IniMap {
|
||||
/**
|
||||
* Set the value of a section key in the INI.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* iniMap.set("section 1", "foo", "World");
|
||||
* iniMap.set("section X", "name", "John");
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "World",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* "section X": {
|
||||
* name: "John",
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param section The section
|
||||
* @param key The key to set
|
||||
* @param value The value to set
|
||||
@ -653,29 +339,6 @@ export class IniMap {
|
||||
/**
|
||||
* Iterate over each entry in the INI to retrieve key, value, and section.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals([...iniMap.entries()], [
|
||||
* ["key0", "value0"],
|
||||
* ["key1", "value1"],
|
||||
* ["foo", "Spam", "section 1"],
|
||||
* ["bar", "Ham", "section 1"],
|
||||
* ["baz", "Egg", "section 1"]
|
||||
* ]);
|
||||
* ```
|
||||
*
|
||||
* @returns The iterator of entries
|
||||
*/
|
||||
*entries(): Generator<
|
||||
@ -816,31 +479,6 @@ export class IniMap {
|
||||
/**
|
||||
* Convert this `IniMap` to a plain object.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @returns The object equivalent to this {@code IniMap}
|
||||
*/
|
||||
toObject(): Record<string, unknown | Record<string, unknown>> {
|
||||
@ -878,31 +516,6 @@ export class IniMap {
|
||||
/**
|
||||
* Convenience method for `JSON.stringify`.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.toJSON(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @returns The object equivalent to this {@code IniMap}
|
||||
*/
|
||||
toJSON(): Record<string, unknown | Record<string, unknown>> {
|
||||
@ -912,33 +525,6 @@ export class IniMap {
|
||||
/**
|
||||
* Convert this `IniMap` to an INI string.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* // Hey
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
* // Hello
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* iniMap.set("section 1", "foo", "Bacon");
|
||||
*
|
||||
* assertEquals(iniMap.toString(), `
|
||||
* // Hey
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
* // Hello
|
||||
* [section 1]
|
||||
* foo = Bacon
|
||||
* bar = Ham
|
||||
* baz = Egg`)
|
||||
* ```
|
||||
* @param replacer The replacer
|
||||
* @returns Ini string
|
||||
*/
|
||||
@ -978,33 +564,6 @@ export class IniMap {
|
||||
/**
|
||||
* Parse an INI string in this `IniMap`.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = new IniMap();
|
||||
*
|
||||
* iniMap.parse(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param text The text to parse
|
||||
* @param reviver The reviver function
|
||||
* @returns This {@code IniMap} object
|
||||
@ -1113,31 +672,6 @@ export class IniMap {
|
||||
/**
|
||||
* Create an `IniMap` from an INI string.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from(`
|
||||
* key0 = value0
|
||||
* key1 = value1
|
||||
*
|
||||
* [section 1]
|
||||
* foo = Spam
|
||||
* bar = Ham
|
||||
* baz = Egg`);
|
||||
*
|
||||
* assertEquals(iniMap.toObject(), {
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param input The input string
|
||||
* @param options The options to use
|
||||
* @returns The parsed {@code IniMap}
|
||||
@ -1149,28 +683,6 @@ export class IniMap {
|
||||
/**
|
||||
* Create an `IniMap` from a plain object.
|
||||
*
|
||||
* @example Usage
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniMap = IniMap.from({
|
||||
* key0: "value0",
|
||||
* key1: "value1",
|
||||
* "section 1": {
|
||||
* foo: "Spam",
|
||||
* bar: "Ham",
|
||||
* baz: "Egg",
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* assertEquals(iniMap.toString(), `key0=value0
|
||||
* key1=value1
|
||||
* [section 1]
|
||||
* foo=Spam
|
||||
* bar=Ham
|
||||
* baz=Egg`);
|
||||
* ```
|
||||
* @param input The input string
|
||||
* @param formatting The options to use
|
||||
* @returns The parsed {@code IniMap}
|
@ -1,6 +1,6 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { IniMap } from "./mod.ts";
|
||||
import { IniMap } from "./_ini_map.ts";
|
||||
import { assertEquals, assertObjectMatch } from "@std/assert";
|
||||
|
||||
Deno.test({
|
@ -3,7 +3,6 @@
|
||||
"version": "0.225.2",
|
||||
"exports": {
|
||||
".": "./mod.ts",
|
||||
"./ini-map": "./ini_map.ts",
|
||||
"./parse": "./parse.ts",
|
||||
"./stringify": "./stringify.ts"
|
||||
}
|
||||
|
68
ini/mod.ts
68
ini/mod.ts
@ -55,76 +55,8 @@
|
||||
* Section Date=1977-05-25`);
|
||||
* ```
|
||||
*
|
||||
* Optionally, {@linkcode IniMap} may be used for finer INI handling. Using this class will permit preserving
|
||||
* comments, accessing values like a map, iterating over key/value/section entries, and more.
|
||||
*
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const ini = new IniMap();
|
||||
* ini.set("section1", "keyA", 100);
|
||||
* assertEquals(ini.toString(), `[section1]
|
||||
* keyA=100`);
|
||||
*
|
||||
* ini.set('keyA', 25)
|
||||
* assertEquals(ini.toObject(), {
|
||||
* keyA: 25,
|
||||
* section1: {
|
||||
* keyA: 100
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* The reviver and replacer APIs can be used to extend the behavior of IniMap, such as adding support
|
||||
* for duplicate keys as if they were arrays of values.
|
||||
*
|
||||
* ```ts
|
||||
* import { IniMap } from "@std/ini/ini-map";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const iniFile = `# Example of key/value arrays
|
||||
* [section1]
|
||||
* key1=This key
|
||||
* key1=is non-standard
|
||||
* key1=but can be captured!`;
|
||||
*
|
||||
* const ini = new IniMap({ assignment: "=", deduplicate: true });
|
||||
* ini.parse(iniFile, (key, value, section) => {
|
||||
* if (section) {
|
||||
* if (ini.has(section, key)) {
|
||||
* const exists = ini.get(section, key);
|
||||
* if (Array.isArray(exists)) {
|
||||
* exists.push(value);
|
||||
* return exists;
|
||||
* } else {
|
||||
* return [exists, value];
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* return value;
|
||||
* });
|
||||
*
|
||||
* assertEquals(
|
||||
* ini.get("section1", "key1"),
|
||||
* ["This key", "is non-standard", "but can be captured!"]
|
||||
* );
|
||||
*
|
||||
* const result = ini.toString((key, value) => {
|
||||
* if (Array.isArray(value)) {
|
||||
* return value.join(
|
||||
* `${ini.formatting.lineBreak}${key}${ini.formatting.assignment}`,
|
||||
* );
|
||||
* }
|
||||
* return value;
|
||||
* });
|
||||
*
|
||||
* assertEquals(result, iniFile);
|
||||
* ```
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
export * from "./ini_map.ts";
|
||||
export * from "./parse.ts";
|
||||
export * from "./stringify.ts";
|
||||
|
@ -1,7 +1,8 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
// This module is browser compatible.
|
||||
|
||||
import { IniMap, type ParseOptions } from "./ini_map.ts";
|
||||
import { IniMap, type ParseOptions, type ReviverFunction } from "./_ini_map.ts";
|
||||
export type { ParseOptions, ReviverFunction };
|
||||
/**
|
||||
* Parse an INI config string into an object. Provide formatting options to override the default assignment operator.
|
||||
*
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { IniMap, parse, type ParseOptions } from "./mod.ts";
|
||||
import { parse, type ParseOptions } from "./mod.ts";
|
||||
import { IniMap } from "./_ini_map.ts";
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
type FormattingOptions,
|
||||
IniMap,
|
||||
type ReplacerFunction,
|
||||
} from "./ini_map.ts";
|
||||
} from "./_ini_map.ts";
|
||||
|
||||
/** Options for constructing INI strings. */
|
||||
export interface StringifyOptions extends FormattingOptions {
|
||||
@ -13,6 +13,8 @@ export interface StringifyOptions extends FormattingOptions {
|
||||
replacer?: ReplacerFunction;
|
||||
}
|
||||
|
||||
export type { FormattingOptions, ReplacerFunction };
|
||||
|
||||
/**
|
||||
* Compile an object into an INI config string. Provide formatting options to modify the output.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user