An very easy to use ini file parser and serializer for node.js
Installation
npm install --save ezini
Usage
const ini = ;
parse(str, options, callback)
ini
where options
is a simple object, for now it only support one option {preserveQuotes: true}
or you can use the synchronize version parseSync(str, options)
In order to keep backward compatibility, the second parameter
options
can also be assigned a callback function (e.g.parse(str, callback)
)
stringify(obj, callback)
ini
or use the synchronize version stringifySync(obj)
Example
Giving a example ini file foobar.ini
which looks like this:
[owner]name=John Doorganization=Acme eProductsrich=truerichStr="true" [database]server=192.0.2.42; use IP address in case network name resolution is not working port=143portStr="143"file = "acme payroll.dat"
You can parse this ini file like this:
str = fs "utf-8")ini
and then obj
would looks like this:
owner: name: 'John Do' organization: 'Acme eProducts' rich: true richStr: 'true' database: server: '192.0.2.42' port: 143 portStr: '143' file: 'acme payroll.dat'
but if perserveQuotes
is set to true
, like this:
str = fs "utf-8")ini
the output will be like this
owner: name: 'John Do' organization: 'Acme eProducts' rich: true richStr: '"true"' database: server: '192.0.2.42' port: 143 portStr: '"143"' file: '"acme payroll.dat"'
You can also stringify the the first output object like this:
ini
str
would looks like this:
[owner]name=John Doorganization=Acme eProductsrich=truerichStr="true" [database]server=192.0.2.42port=143portStr="143"file=acme payroll.dat