30 ms·
There's an excellent tool to avoid the default value mess shown there: defaults https://github.com/tmpvar/defaults https://github.com/tmpvar/defaults It will
by franciscop 11y ago
There's an excellent tool to avoid the default value mess shown there: defaults
https://github.com/tmpvar/defaults https://github.com/tmpvar/defaults
It will fill your option object with the data if it's undefined
- carterehsmith 11y agoAlso, if he ever needs to check if a variable is a number, there is another one-line-of-JS project on npm that does just that!
- franciscop 11y agoBut it isn't one line: 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
- jkcxn 11y agoYeah even _.extend