node-settings
Advanced tools
Comparing version 0.1.1 to 0.1.2
(function() { | ||
var Configurator, argv, fs, merge, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
_this = this; | ||
@@ -12,3 +13,2 @@ fs = require('fs'); | ||
Configurator = (function() { | ||
var _this = this; | ||
@@ -26,41 +26,6 @@ function Configurator(source) { | ||
Configurator.prototype.config_sources = { | ||
file: { | ||
get: function(options, callback) { | ||
return fs.readFile(options.location, function(err, data) { | ||
throw err(err ? process.nextTick(function() { | ||
return callback(JSON.parse(data)); | ||
}) : void 0); | ||
}); | ||
}, | ||
getSync: function(options) { | ||
var data; | ||
data = fs.readFileSync(options.location); | ||
return JSON.parse(data); | ||
} | ||
}, | ||
json: { | ||
get: function(options, callback) { | ||
return process.nextTick(function() { | ||
return callback(options.data); | ||
}); | ||
}, | ||
getSync: function(options) { | ||
return options.data; | ||
} | ||
}, | ||
string: { | ||
get: function(options, callback) { | ||
return callback(JSON.parse(options.data)); | ||
}, | ||
getSync: function(options) { | ||
return JSON.parse(options.data); | ||
} | ||
} | ||
}; | ||
Configurator.prototype.load = function(callback) { | ||
var config_loader, | ||
_this = this; | ||
config_loader = this.config_sources[this.source.name]; | ||
config_loader = Configurator.config_sources[this.source.name]; | ||
return config_loader.get(this.source.options, function(data) { | ||
@@ -79,3 +44,3 @@ var config, env_config; | ||
var config, config_loader, data, env_config; | ||
config_loader = this.config_sources[this.source.name]; | ||
config_loader = Configurator.config_sources[this.source.name]; | ||
data = config_loader.getSync(this.source.options); | ||
@@ -90,6 +55,42 @@ config = data["default"] || {}; | ||
}).call(this); | ||
})(); | ||
Configurator.config_sources = { | ||
file: { | ||
get: function(options, callback) { | ||
return fs.readFile(options.location, options.encoding || 'ascii', function(err, data) { | ||
if (err) throw err; | ||
return process.nextTick(function() { | ||
return callback(eval(data)); | ||
}); | ||
}); | ||
}, | ||
getSync: function(options) { | ||
var data; | ||
data = fs.readFileSync(options.location, options.encoding || 'utf8'); | ||
return eval(data); | ||
} | ||
}, | ||
json: { | ||
get: function(options, callback) { | ||
return process.nextTick(function() { | ||
return callback(options.data); | ||
}); | ||
}, | ||
getSync: function(options) { | ||
return options.data; | ||
} | ||
}, | ||
string: { | ||
get: function(options, callback) { | ||
return callback(eval(options.data)); | ||
}, | ||
getSync: function(options) { | ||
return eval(options.data); | ||
} | ||
} | ||
}; | ||
module.exports = Configurator; | ||
}).call(this); |
@@ -5,3 +5,3 @@ { | ||
"description": "Provides easy, multi-environment configuration", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "", | ||
@@ -8,0 +8,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
10845
9
82
4