-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefaults-deep.js
46 lines (38 loc) · 995 Bytes
/
defaults-deep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*!
* defaults-deep <https://github.com/jonschlinkert/defaults-deep>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*
* Modified by @andineck: removed lazy dependency in order to make it runnable with browserify
*
*/
'use strict';
var isExtendable = require('is-extendable');
var forOwn = require('for-own');
function defaultsDeep(target, objects) {
target = target || {};
function copy(target, current) {
forOwn(current, function (value, key) {
var val = target[key];
// add the missing property, or allow a null property to be updated
if (val == null) {
target[key] = value;
} else if (isExtendable(val) && isExtendable(value)) {
defaultsDeep(val, value);
}
});
}
var len = arguments.length, i = 1;
while (i < len) {
var obj = arguments[i++];
if (obj) {
copy(target, obj);
}
}
return target;
};
/**
* Expose `defaultsDeep`
*/
module.exports = defaultsDeep;