config.ini

your .ini files parser with some extras

Usage no npm install needed!

<script type="module">
  import configIni from 'https://cdn.skypack.dev/config.ini';
</script>

README

config.ini

your .ini files parser with some extras

MIT License Build Status npm version Build

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 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

« back to list

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
    /// (...)

« back to list

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
    /// (...)

« back to list

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
'

« back to list

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: 'صلاحالدينيوسفبنأيوب'
        }
    }
);

« back to list