Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
72 changes: 45 additions & 27 deletions lib/simple-ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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:
Expand Down Expand Up @@ -361,4 +379,4 @@ var SimpleIni = (function () {

if (typeof module != 'undefined') {
module.exports = SimpleIni;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down