There's an excellent tool to avoid the default value mess shown there: defaults
https://github.com/tmpvar/defaults
It will fill your option object with the data if it's undefined
https://github.com/tmpvar/defaults
It will fill your option object with the data if it's undefined
var clone = require('clone');
module.exports = function(options, defaults) {
options = options || {};
Object.keys(defaults).forEach(function(key) {
if (typeof options[key] === 'undefined') {
options[key] = clone(defaults[key]);
}
});
return options;
};
Besides the tests and the fact that someone is maintaining it. It's not much, but it's code that doesn't have to be maintained by you