@yaas/iniparser

3.0.1 • Public • Published

iniParser

A tool that allows you to parse and create .ini files to and from regular javascript objects

const fs = require('fs');
const ini = require('@yaas/iniparser');

const config = ini.parse(fs.readFileSync('./config.ini', 'utf8'), '\n'); // By default the eol is \n, but you can change it to \r\n if required.
fs.writeFileSync('./other_config.ini', ini.stringify(config), 'utf8');

Valid .ini config to JS object

; This is a comment
# This is also a comment
key = value ; This is now valid
[scope=global]
globalBool
[user]
name = Sam Price
[user.data]
someDataKey = dataProp
[global]
name = iniFile

arr[] = value1 ; value at index 0
arr[] = value2 ; value at index 1

Is transformed into

// Assuming you parsed it correctly into the variable `config`
const config = {
  key: 'value',
  globalBool: true,
  name: 'iniFile',
  arr: ['value1', 'value2'],
  user: {
    name: 'Sam Price',
    data: {
      someDataKey: 'dataProp'
    }
  }
};

NOTE: Numbers, Sets, Bigints, NaN or false are not supported to be parsed

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @yaas/iniparser

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

4.38 kB

Total Files

3

Last publish

Collaborators

  • yaas-dev