--- title: "@std/ini" description: "Parsing and serializing of INI files" jsr: jsr:@std/ini pkg: ini version: 0.225.2 generated: true stability: unstable --- :::info Unstable This @std package is experimental and its API may change without a major version bump. ::: ## Overview
parse and stringify for handling
INI encoded data, such as the
Desktop Entry specification.
Values are parsed as strings by default to preserve data parity from the original.
Customization is possible in the form of reviver/replacer functions like those in JSON.parse and JSON.stringify.
Nested sections, repeated key names within a section, and key/value arrays are not supported,
but will be preserved when using IniMap. Multi-line values are not supported and will throw a syntax error.
White space padding and lines starting with '#', ';', or '//' will be treated as comments.
Optionally, 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.
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.
```js 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); ``` ### Add to your project ```sh deno add jsr:@std/ini ``` See all symbols in @std/ini on