diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index 9d7cd3f..9f6bb92 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,10 @@ API Documentation * hasProperty(property, section) - checks if the property exists in the section. If the section is not specified then it checks if global property exists. -* get(config) - Gets property's value. config might be 'section.property' or - just 'property'. If the config is just a 'property' then the library tries to get +* get(section, property?) - Gets property's value. section might be 'section.property' or + just 'property'. If the section is just a 'property' then the library tries to get the global property. + Section names containing dots have to be queried by delimiting the section and property part as proper arguments Options ------- diff --git a/lib/simple-ini.js b/lib/simple-ini.js index 24f8e94..45c2cd3 100644 --- a/lib/simple-ini.js +++ b/lib/simple-ini.js @@ -223,37 +223,42 @@ var SimpleIni = (function () { this, "get", { - value: function(config) { - var section, - property, - isIgnoreCase, - delimiter; - - isIgnoreCase = !finalOptions.caseSensitive; - delimiter = config.indexOf('.'); - if (delimiter > -1) { - section = config.substr(0, delimiter); - property = config.substr(delimiter + 1); - + value: function(section, property) { + var isIgnoreCase = !finalOptions.caseSensitive; + if(!property){ + var delimiter; + + delimiter = section.indexOf('.'); + if (delimiter > -1) { + property = section.substr(delimiter + 1); + section = section.substr(0, delimiter); + + section = findProperty(self, section, isIgnoreCase); + if (section !== null) { + property = findProperty(self[section], property, isIgnoreCase); + return property === null ? property : self[section][property]; + } + } + else { + section = findProperty(self, section, isIgnoreCase); + if (section != null) { + property = self[section]; + if (!finalOptions.allowGlobalProperties || + (finalOptions.allowGlobalProperties && + (typeof property === 'string' || + typeof property === 'number' || + typeof property === 'boolean'))) { + return property; + } + } + } + } else { section = findProperty(self, section, isIgnoreCase); if (section !== null) { property = findProperty(self[section], property, isIgnoreCase); return property === null ? property : self[section][property]; } } - else { - section = findProperty(self, config, isIgnoreCase); - if (section != null) { - property = self[section]; - if (!finalOptions.allowGlobalProperties || - (finalOptions.allowGlobalProperties && - (typeof property === 'string' || - typeof property === 'number' || - typeof property === 'boolean'))) { - return property; - } - } - } return null; } @@ -269,7 +274,20 @@ var SimpleIni = (function () { } content = loadFunction().split(finalOptions.lineSeparator); - + + // Allow parsing ini files having non-compliant multiline entries + for (let [index, val] of content.entries()) { + if (!/(\[.+\]|=)/.test(val) && val) { + let tempindex = index - 1 + while (!content[tempindex].includes("=")) { + tempindex -= 1; + } + + content[tempindex] += `\n${ val }`; + content[index] = ""; + } + } + content = content.filter(x => x != ""); sectionName = null; next_line: @@ -361,4 +379,4 @@ var SimpleIni = (function () { if (typeof module != 'undefined') { module.exports = SimpleIni; -} \ No newline at end of file +} diff --git a/package.json b/package.json index 9ebc975..ef88c77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-ini", - "version": "1.0.4", + "version": "1.0.5", "description": "Simple INI-parser", "main": "./lib/simple-ini.js", "homepage": "https://github.com/ilich/simple-ini",