@ghostff/ini_parser
v1.0.1
Published
Converts an .ini file/string to javascript object.
Downloads
2
Maintainers
Readme
.INI Parser
Converts an .ini file/string to javascript object. Supports section processing and typed value scan.
Installation
npm i @ghostff/ini_parser
Method Synopsis
parse (ini_string_or_filepath, callback, process_sections = true, scan = false)
parseSync (ini_string_or_filepath, process_sections = true, scan = false)
parseString(ini_string, process_sections = true, scan = false)
Usage
Node
var iniParser = require('@ghostff/ini_parser');
// Async
iniParser.parse('./example.ini', function(err, data) {
console.log(data);
});
// Sync
var data = iniParser.parseSync('./config.ini');
// String
var data = iniParser.parseString("name=foo bar");
Regular JS
var iniParser = require('@ghostff/ini_parser');
var data = iniParser.parse('' +
'; example.ini\n' +
'name=foo bar\n' +
'age=33\n' +
'single=false'
);
Demo
- process_sections: By setting the
process_sections
parameter toTRUE
, you get a nested object, with the section names and settings included. The default forprocess_sections
isFALSE
. - scan: When
scan
is set toTRUE
, ini property value will be parsed. The default forscan
is (FALSE
).
; example.ini
name=foo bar
datails[age] = 30
datails[single] = true
[db]
user=foo
pass=null
[app]
site_name=foobar
iniParser.parseSync('./example.ini');
iniParser.parseSync('./example.ini', true); // process sections.
iniParser.parseSync('./example.ini', true, true); // process sections and use typed scan.
Result
{
name: 'foo bar',
datails: { age: '30', single: 'true' },
user: 'foo',
pass: 'null',
site_name: 'foobar'
}
{
name: 'foo bar',
datails: { age: '30', single: 'true' },
db: { user: 'foo', pass: 'null' },
app: { site_name: 'foobar' }
}
{
name: 'foo bar',
datails: { age: 30, single: true },
db: { user: 'foo', pass: null },
app: { site_name: 'foobar' }
}