SHMAML
Parse .ini
files into JSON objects. Support lists.
Install
$ npm install shmaml
Use
const parse = ; const resultPromise = ;// or:const result = parse;
Example config.ini
+ list:
username = mepasword = 1234 [SectionA] key=value [SectionB] key=value list=[ item1, item2, item3 ]
Becomes:
result = username: 'me' pasword: 1234 SectionA: key: 'value' SectionB: key: 'value' list: 'item1' 'item2' 'item3'
Convention
-
key-value pairs are noted with an equal sign.
key="value" -
Quoting values is optional. Strings are used as default.
; These are all the same:key=valuekey='value'key="value" -
Unquoted numbers are parsed as numbers. Use single/double quotes to make number values parsed as strings.
number = 55string = '55'string = "55" -
Unquoted booleans are parsed as booleans. Use single/double quotes to make boolean values parsed as strings. CaSe InSeNsITiVe.
bool = TRUEbool = falsestring = 'true'string = "false" -
Sections are noted with wrapping square brackets.
[categoryA]key="value"[categoryB]key="value" -
Lists are also noted with wrapping square brackets when come after a
key=
.[categoryA]key="value"list=[item1, item2, item3] -
Multiline lists are also supported.
[categoryA]multilineList=[item1,item2,item3]key="value"
NOTE: Nested lists are NOT supported.
list=[A, [B, [C, D]], E]
-
Comments are ignored, obviously. Use quotes to work with semicolons:
; line comment[category]key1=value1 ; inline commentkey2='quoted ; semicolon'key3="double quoted ; semicolon" -
Whitespace (including tabs) is trimmed:
;Same[sectionA][ sectionA ];Samekey= valuekey =valuekey = value[sectionA]key=value;Same as[sectionA]key=value -
Preserve whitespace using quotes:
[' section ']key=" value "" section ":key: " value " -
Duplicates.
Duplicated section names are merged to the same object.[sectionA]key1=value1[sectionA]key2=value2result =SectionA:key1: 'value1'key2: 'value2'Duplicated key names in the same section: the later overwrites the former.
sameKey=value1sameKey=value2sameKey=value3result =sameKey: 'value3'