2017-12-09 21:51:18 +00:00
|
|
|
|
2017-12-10 09:45:38 +00:00
|
|
|
function defaults(options, def) {
|
2017-12-09 21:51:18 +00:00
|
|
|
options = options || {}
|
|
|
|
|
2017-12-10 09:45:38 +00:00
|
|
|
Object.keys(def).forEach(function(key) {
|
2017-12-09 21:51:18 +00:00
|
|
|
if (typeof options[key] === 'undefined') {
|
|
|
|
// No need to do clone since we mostly deal with
|
|
|
|
// flat objects
|
2017-12-10 09:45:38 +00:00
|
|
|
options[key] = def[key]
|
|
|
|
}
|
|
|
|
else if (typeof options[key] === 'object' &&
|
|
|
|
typeof def[key] === 'object') {
|
|
|
|
options[key] = defaults(options[key], def[key])
|
2017-12-09 21:51:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|
2017-12-10 09:45:38 +00:00
|
|
|
|
|
|
|
export default defaults
|