Yet another (opinionated) ini encoder/decoder for Node.js.

Usage no npm install needed!

<script type="module">
  import xan105Ini from 'https://cdn.skypack.dev/@xan105/ini';


Yet another (opinionated) ini encoder/decoder for Node.js.

Usage example

Consider an ini-file that looks like this:

; this comment is being ignored
# that one as well

scope = global
 answer= 42
password type = string
yes = true

password = some very*difficult=password:
database-name =my-project-db

datadir = /var/lib/data
datadirWin = "C:\Windows"


import * as ini from '@xan105/ini';
import { promises as fs} from 'fs';
const ini = require('@xan105/ini');
const { promises : fs } = require('fs');

  const data = ini.parse(content);


  "scope": "global",
  "answer": "42",
  "password type": "string",
  "yes": true,
  "Database": {
    "password": "some very*difficult=password:",
    "database-name": "my-project-db"
  "DB.default": {
    "datadir": "/var/lib/data",
    "datadirWin": "C:\\Windows"


npm install @xan105/ini


parse(string: string, [option: obj]): obj

Decode the ini-style formatted string into an object.

option ⚙️

name type default description
autoType bool or {bool...} {...} Auto string to boolean / number and unquote string**
ignoreGlobalSection bool false Ignore keys without a section aka 'Global' section
sectionFilter string[] [] List of section name to filter out

Auto type**

autoType option accepts the following obj for granular control or a boolean true/false which force all options to true/false:

name type default description
bool bool true String to boolean
number bool false String to number
unquote bool false Remove leading and trailing quote (" or ') in a string value


ini.parse(string); //default
ini.parse(string, {autoType : true}); //every autotype to true
ini.parse(string, {autoType : { //granular autotype
  bool: true,
  number: true
}, ignoreGlobalSection: true}); //with an additional parse option

Implementation notice

  • Sections cannot be nested
  • Comments are ignored (! and #)
  • Inline comments are not allowed !
  • Duplicate names : override first occurrence
  • Case sensitive
  • Name/value delimiter is "=" and is mandatory
  • Whitespace around section name, key name and key value are trimmed.

stringify(obj: obj, [option: obj]: string

Encode the object obj into an ini-style formatted string.

option ⚙️

name type default description
whitespace bool false Whether to put whitespace around the delimiter =
blankLine bool true Add blank lines between sections
ignoreGlobalSection bool false Ignore root properties (not under any namespace if you will)
quoteString bool false Quote string values using double quotes ("...")

Implementation notice

  • Sections shall not be nested
  • Case sensitive
  • Empty section are allowed
  • Key value can only be a boolean, number or string