Jonatan Nilsson
0948885671
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
25 lines
615 B
JavaScript
25 lines
615 B
JavaScript
|
|
// taken from isobject npm library
|
|
export function isObject(val) {
|
|
return val != null && typeof val === 'object' && Array.isArray(val) === false
|
|
}
|
|
|
|
export function defaults(original, def) {
|
|
if (!isObject(original)) throw new Error('defaults called with non-object type')
|
|
|
|
Object.keys(original).forEach(key => {
|
|
if (isObject(original[key]) && def && isObject(def[key])) {
|
|
defaults(original[key], def[key])
|
|
}
|
|
})
|
|
|
|
if (def) {
|
|
Object.keys(def).forEach(function(key) {
|
|
if (typeof original[key] === 'undefined') {
|
|
original[key] = def[key]
|
|
}
|
|
})
|
|
}
|
|
|
|
return original
|
|
}
|