Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

java-properties

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-properties - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

gulpfile.js

282

lib/properties.js

@@ -9,135 +9,184 @@ /*

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var fs = require('fs');
// var utils = require('util');
// Construct a PropertiesFile class to handle all properties of a specifice file or group of file
var PropertiesFile = function () {
this.objs = {};
if (arguments) {
this.of.apply(this, arguments);
}
};
var PropertiesFile = (function () {
function PropertiesFile() {
_classCallCheck(this, PropertiesFile);
PropertiesFile.prototype.makeKeys = function (line) {
if (line && line.indexOf('#') !== 0) {
var splitIndex = line.indexOf('=');
var key = line.substring(0, splitIndex).trim();
var value = line.substring(splitIndex + 1).trim();
// if keys already exists ...
if (this.objs.hasOwnProperty(key)) {
// if it is already an Array
if (Array.isArray(this.objs[key])) {
// just push the new value
this.objs[key].push(value);
} else {
// transform the value into Array
var oldValue = this.objs[key];
this.objs[key] = [oldValue, value];
}
} else {
// the key does not exists
this.objs[key] = value;
this.objs = {};
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
}
};
PropertiesFile.prototype.addFile = function (file) {
var data = fs.readFileSync(file, 'utf-8');
var items = data.split(/\r?\n/);
var me = this;
for (var i = 0; i < items.length; i++) {
var line = items[i];
while (line.substring(line.length - 1) === '\\') {
line = line.slice(0, -1);
var nextLine = items[i + 1];
line = line + nextLine.trim();
i++;
}
me.makeKeys(line);
if (args.length) {
this.of.apply(this, args);
}
}
};
PropertiesFile.prototype.of = function () {
for (var i = 0; i < arguments.length; i++) {
this.addFile(arguments[i]);
}
};
_createClass(PropertiesFile, [{
key: 'makeKeys',
value: function makeKeys(line) {
if (line && line.indexOf('#') !== 0) {
var splitIndex = line.indexOf('=');
var key = line.substring(0, splitIndex).trim();
var value = line.substring(splitIndex + 1).trim();
// if keys already exists ...
if (this.objs.hasOwnProperty(key)) {
// if it is already an Array
if (Array.isArray(this.objs[key])) {
// just push the new value
this.objs[key].push(value);
} else {
// transform the value into Array
var oldValue = this.objs[key];
this.objs[key] = [oldValue, value];
}
} else {
// the key does not exists
this.objs[key] = value;
}
}
}
}, {
key: 'addFile',
value: function addFile(file) {
var data = fs.readFileSync(file, 'utf-8');
var items = data.split(/\r?\n/);
var me = this;
for (var i = 0; i < items.length; i++) {
var line = items[i];
while (line.substring(line.length - 1) === '\\') {
line = line.slice(0, -1);
var nextLine = items[i + 1];
line = line + nextLine.trim();
i++;
}
me.makeKeys(line);
}
}
}, {
key: 'of',
value: function of() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
PropertiesFile.prototype.get = function (key, defaultValue) {
if (this.objs.hasOwnProperty(key)) {
if (Array.isArray(this.objs[key])) {
var ret = [];
for (var i = 0; i < this.objs[key].length; i++) {
ret[i] = this.interpolate(this.objs[key][i]);
for (var i = 0; i < args.length; i++) {
this.addFile(args[i]);
}
return ret;
} else {
return typeof this.objs[key] === 'undefined' ? '' : this.interpolate(this.objs[key]);
}
}
return defaultValue;
};
}, {
key: 'get',
value: function get(key, defaultValue) {
if (this.objs.hasOwnProperty(key)) {
if (Array.isArray(this.objs[key])) {
var ret = [];
for (var i = 0; i < this.objs[key].length; i++) {
ret[i] = this.interpolate(this.objs[key][i]);
}
return ret;
} else {
return typeof this.objs[key] === 'undefined' ? '' : this.interpolate(this.objs[key]);
}
}
return defaultValue;
}
}, {
key: 'getInt',
value: function getInt(key, defaultIntValue) {
var val = this.get(key);
if (!val) {
return defaultIntValue;
} else {
return parseInt(val, 10);
}
}
}, {
key: 'getFloat',
value: function getFloat(key, defaultFloatValue) {
var val = this.get(key);
if (!val) {
return defaultFloatValue;
} else {
return parseFloat(val);
}
}
}, {
key: 'getBoolean',
value: function getBoolean(key, defaultBooleanValue) {
function parseBool(b) {
return !/^(false|0)$/i.test(b) && !!b;
}
PropertiesFile.prototype.getInt = function (key, defaultIntValue) {
var val = this.get(key);
if (!val) { return defaultIntValue; }
else { return parseInt(val, 10); }
};
var val = this.get(key);
if (!val) {
return defaultBooleanValue || false;
} else {
return parseBool(val);
}
}
}, {
key: 'set',
value: function set(key, value) {
this.objs[key] = value;
}
}, {
key: 'interpolate',
value: function interpolate(s) {
var me = this;
return s.replace(/\\\\/g, '\\').replace(/\$\{([A-Za-z0-9\.]*)\}/g, function (match) {
return me.get(match.substring(2, match.length - 1));
});
}
}, {
key: 'getKeys',
value: function getKeys() {
var keys = [];
for (var key in this.objs) {
keys.push(key);
}
return keys;
}
}, {
key: 'getMatchingKeys',
value: function getMatchingKeys(matchstr) {
var keys = [];
for (var key in this.objs) {
if (key.search(matchstr) !== -1) {
keys.push(key);
}
}
return keys;
}
}, {
key: 'reset',
value: function reset() {
this.objs = {};
}
}]);
PropertiesFile.prototype.getFloat = function (key, defaultFloatValue) {
var val = this.get(key);
if (!val) { return defaultFloatValue; }
else { return parseFloat(val); }
};
return PropertiesFile;
})();
PropertiesFile.prototype.getBoolean = function (key, defaultBooleanValue) {
function parseBool(b) {
return !(/^(false|0)$/i).test(b) && !!b;
}
var val = this.get(key);
if (!val) { return defaultBooleanValue || false; }
else { return parseBool(val); }
};
;
PropertiesFile.prototype.set = function (key, value) {
this.objs[key] = value;
};
// Retain 'of' from v1 for backward compatibility
var of = function of() {
var globalFile = new PropertiesFile();
PropertiesFile.prototype.interpolate = function (s) {
var me=this;
return s
.replace(/\\\\/g, '\\')
.replace(/\$\{([A-Za-z0-9\.]*)\}/g, function (match) {
return me.get(match.substring(2, match.length - 1));
});
};
PropertiesFile.prototype.getKeys = function () {
var keys = [];
for (var key in this.objs) {
keys.push(key);
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return keys;
};
PropertiesFile.prototype.getMatchingKeys = function (matchstr) {
var keys = [];
for (var key in this.objs) {
if (key.search(matchstr) !== -1) {
keys.push(key);
}
}
return keys;
};
PropertiesFile.prototype.reset = function () {
this.objs = {};
};
// Keeped from v1 for backward compatibility
exports.of = function () {
var globalFile = new PropertiesFile();
globalFile.of.apply(globalFile, arguments);
globalFile.of.apply(globalFile, args);
return globalFile;

@@ -147,1 +196,2 @@ };

exports.PropertiesFile = PropertiesFile;
exports.of = of;
{
"name": "java-properties",
"description": "Reads and interpolates Java .properties files",
"version": "0.2.4",
"version": "0.2.5",
"homepage": "http://github.com/mattdsteele/java-properties",
"author": {
"name": "Matt Steele",
"email": "orphum@gmail.com"
"email": "orphum@gmail.com",
"name": "Matt Steele"
},

@@ -28,11 +28,15 @@ "repository": {

"scripts": {
"test": "grunt nodeunit"
"test": "gulp test"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "^0.4.0",
"grunt-contrib-watch": "~0.2.0",
"grunt": "~0.4.1"
"gulp": "^3.9.0",
"gulp-babel": "^5.2.0",
"gulp-jshint": "^1.11.2",
"gulp-nodeunit": "0.0.5",
"gulp-sequence": "^0.4.0"
},
"keywords": ["java", "properties"]
"keywords": [
"java",
"properties"
]
}

@@ -75,4 +75,5 @@ # java-properties

* 0.2.4 Allow multi-line properties
* 0.2.5 Refactorings, no new features
## License
Licensed under the MIT license.

@@ -273,3 +273,3 @@ 'use strict';

test.done();
},
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc