UNPKG

909 BJavaScriptView Raw
1var forOwn = require('./forOwn');
2var isPlainObject = require('../lang/isPlainObject');
3
4 /**
5 * Deeply copy missing properties in the target from the defaults.
6 */
7 function deepFillIn(target, defaults){
8 var i = 0,
9 n = arguments.length,
10 obj;
11
12 while(++i < n) {
13 obj = arguments[i];
14 if (obj) {
15 // jshint loopfunc: true
16 forOwn(obj, function(newValue, key) {
17 var curValue = target[key];
18 if (curValue == null) {
19 target[key] = newValue;
20 } else if (isPlainObject(curValue) &&
21 isPlainObject(newValue)) {
22 deepFillIn(curValue, newValue);
23 }
24 });
25 }
26 }
27
28 return target;
29 }
30
31 module.exports = deepFillIn;
32
33