config.ini
v0.0.60
Published
your .ini files parser with some extras
Downloads
1,164
Maintainers
Readme
config.ini
your .ini
files parser with some extras
Version
Version|Published|By|URL
--- | --- | --- | ---
0.0.60 | 2019-08-11 | codebloke
| npm
How to use it
Installation
npm install --save config.ini
In your code...
var configIni = require('config.ini');
Examples
- Example .ini file format
- Reading string
- Reading from a file
- Output to .ini string (you can save it into a file)
- I8N Support
Example format
For all examples below we are assuming following .ini file
structure
# A comment
; This is a comment too
[SectionOne]
key = "value"
integer = 1234
real = 3.14
string1 = "Case 1"
string2 = 'Case 2'
multivalue[] = "first" # in-line comments
multivalue[] = 'second' # are supported as well
; Section: SectionTwo
[SectionTwo]
key = new value
integer = 1234
real = 3.14
string1 = Case 1
string2 = Case 2
string3 = Case 3
multivalue[] = first
multivalue[] = second
multivalue[] = third
Reading from a string
Reading config from an .ini string
with sections (For section-less feature see: #2)
var string = '',
conf = configIni.parse(string);
/// (...)
console.log(conf.SectionOne.integer);
// 1234
console.log(typeof conf.SectionOne.integer);
// 'number'
console.log(typeof conf.SectionTwo);
// 'object'
console.log(conf.SectionTwo.real);
// 3.14
/// (...)
Reading from a file
Reading config from a file.ini
var conf = configIni.load('/yourFull/path/to/file.ini');
/// (...)
console.log(conf.SectionOne.integer);
// 1234
console.log(typeof conf.SectionOne.integer);
// 'number'
console.log(typeof conf.SectionTwo);
// 'object'
console.log(conf.SectionTwo.real);
// 3.14
/// (...)
Output to an .ini string
var objToIniString = {
mysection: {
key: "string",
integer: 1234,
real: 3.14
}
};
console.log(configIni.stringify(objToIniString));
'
; Section: mysection
[mysection]
key = string
integer = 1234
real = 3.14
'
I8N Support
For the .ini
file as follows:
[Japan]
miyamoto_musashi = "宮本武蔵"
[Germany]
gebhard_von_bluecher = "Gebhard-Leberecht von Blücher Fürst von Wahlstatt"
[ME]
salah_ad_din = "صلاحالدينيوسفبنأيوب"
we are getting back following object:
console.log(
{
Japan: {
miyamoto_musashi: '宮本武蔵'
},
Germany: {
gebhard_von_bluecher: 'Gebhard-Leberecht von Blücher Fürst von Wahlstatt'
},
ME: {
salah_ad_din: 'صلاحالدينيوسفبنأيوب'
}
}
);