ini-data

1.1.2 • Public • Published

ini-data

⛔️ Warning: This library was created primarily for educational purposes, and is currently unstable

INI parser and serializer for JavaScript.

Usage

parse()

Let's say you have this INI file (named config.ini):

; this is a comment
key = value

[details]
user = root
password = thepassword

[database.main.values]
key1 = value1
key2 = value2

You can parse the file into an object like so:

const fs = require('fs');
const iniConfig = require('ini-data');

const text = fs.readFileSync('ini.config', 'utf-8');
const obj = iniConfig.parse(text);

console.log(obj.key); // value
console.log(obj.details.password); // thepassword
console.log(obj.database.main.values.key1); // value1

stringify()

const ini = require('ini-data');
const fs = require('fs');

const obj = {
  user: {
    name: 'root',
    password: 'thepassword',
    details: {
      item1: 'value1',
    },
  },
  key: 'value',
};
fs.writeFileSync('data.ini', ini.stringify(obj));

data.ini will contain the following INI data:

key = value

[user]
name = root
password = thepassword

[user.details]
item1 = value1

Readme

Keywords

Package Sidebar

Install

npm i ini-data

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

10.4 kB

Total Files

5

Last publish

Collaborators

  • tariibaba