java-properties
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -16,5 +16,21 @@ /* | ||
var splitIndex = j.indexOf('='); | ||
var key = j.substring(0, splitIndex); | ||
var value = j.substring(splitIndex + 1); | ||
objs[key.trim()] = value.trim(); | ||
var key = j.substring(0, splitIndex).trim(); | ||
var value = j.substring(splitIndex + 1).trim(); | ||
// if keys already exists ... | ||
if (objs.hasOwnProperty(key)) { | ||
// if it is already an Array | ||
if (Array.isArray(objs[key])) { | ||
// just push the new value | ||
objs[key].push(value); | ||
} | ||
else { | ||
// transform the value into Array | ||
var oldValue = objs[key]; | ||
objs[key] = [ oldValue, value ]; | ||
} | ||
} | ||
else { | ||
// the key does not exists | ||
objs[key] = value; | ||
} | ||
} | ||
@@ -36,3 +52,12 @@ }; | ||
if (objs.hasOwnProperty(key)) { | ||
return typeof objs[key] === 'undefined' ? '' : interpolate(objs[key]); | ||
if (Array.isArray(objs[key])) { | ||
var ret=[]; | ||
for (var i=0; i < objs[key].length; i++) { | ||
ret[i] = interpolate(objs[key][i]); | ||
} | ||
return ret; | ||
} | ||
else { | ||
return typeof objs[key] === 'undefined' ? '' : interpolate(objs[key]); | ||
} | ||
} | ||
@@ -39,0 +64,0 @@ return undefined; |
{ | ||
"name": "java-properties", | ||
"description": "Reads and interpolates Java .properties files", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"homepage": "http://github.com/mattdsteele/java-properties", | ||
@@ -6,0 +6,0 @@ "author": { |
# java-properties | ||
Reads and interpolates Java .properties files | ||
Read Java .properties files. Supports adding dynamically some files and array key value (same key multiple times) | ||
@@ -22,2 +22,14 @@ ## Getting Started | ||
values.reset(); | ||
... | ||
values.getKeys(); // returns all the keys | ||
... | ||
values.addFile('anotherFile.properties'); // adds another file the properties list | ||
... | ||
values.reset(); // empty the keys previously loaded | ||
... | ||
[ -- .properties file | ||
an.array.key=value1 | ||
an.array.key=value2 | ||
] | ||
values.get('an.array.key'); // returns [value1, value2] | ||
``` | ||
@@ -27,3 +39,10 @@ ## Contributing | ||
## Release History | ||
0.1.0 Initial commit | ||
0.1.5: Support empty strings | ||
0.1.6 New API: `getKeys` | ||
0.1.7 New APIs: `addFile` and `reset` | ||
0.1.8 Add array key (the same key many time in files) | ||
## License | ||
Licensed under the MIT license. |
@@ -153,3 +153,20 @@ 'use strict'; | ||
test.done(); | ||
} | ||
}, | ||
'array file': function(test) { | ||
test.expect(5); | ||
props = properties.of('test/fixtures/example.properties', 'test/fixtures/arrayExample.properties'); | ||
var arrayKey = props.get('arrayKey'); | ||
test.equal(true, Array.isArray(arrayKey)); | ||
test.equal(3, arrayKey.length); | ||
test.equal('first : ricola-2.5', arrayKey[0]); | ||
test.equal('second', arrayKey[1]); | ||
test.equal('third', arrayKey[2]); | ||
test.done(); | ||
}, | ||
'array file undefined': function(test) { | ||
test.expect(1); | ||
props = properties.of('test/fixtures/example.properties', 'test/fixtures/arrayExample.properties'); | ||
test.equal(undefined, props.get('arrayKeyUndefined')); | ||
test.done(); | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13842
12
296
47