Skip to content

Commit

Permalink
[helper] added ini file parser (easier for end users to understand)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grovkillen committed Apr 15, 2020
1 parent e1fb94e commit a6e035c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gui_easy_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ const helpEasy = {
return json[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]][path[6]][path[7]][path[8]][path[9]];
}
},
'iniFileToObject': function(string) {
let object = {};
let sections = string.match(/^\[[^\]\n]+](?:\n(?:[^[\n].*)?)*/gm);
for (let i=0; i < sections.length; i++) {
let sectionName = sections[i].split("\n")[0];
sectionName = sectionName.slice(1, sectionName.length-1);
object[sectionName] = {};
let key = sections[i].match(/^[^;\s][^;\r\n]*/gm); //we remove comments behind ";" character
for (let k=1; k < key.length; k++) {
let keyValue = key[k].split("=");
object[sectionName][keyValue[0]] = keyValue[1];
}
}
return object;
},
'sortObjectArray': (propName) =>
(a, b) => a[propName] === b[propName] ? 0 : a[propName] < b[propName] ? -1 : 1
,
Expand Down

0 comments on commit a6e035c

Please sign in to comment.