UNPKG

762 BJavaScriptView Raw
1'use strict';
2
3var isObject = require('is-plain-object');
4var forOwn = require('for-own');
5
6function mixinDeep(o, objects) {
7 if (!isObject(o)) return {};
8 if (!isObject(objects)) return o;
9
10 // don't slice args for v8 optimizations
11 var len = arguments.length - 1;
12 for (var i = 0; i < len; i++) {
13 var obj = arguments[i + 1];
14 if (isObject(obj)) {
15 forOwn(obj, copy, o);
16 }
17 }
18 return o;
19}
20
21/**
22 * copy properties from the source object to the
23 * target object.
24 *
25 * @param {*} `value`
26 * @param {String} `key`
27 */
28
29function copy(value, key) {
30 var obj = this[key];
31 if (isObject(value) && isObject(obj)) {
32 mixinDeep(obj, value);
33 } else {
34 this[key] = value;
35 }
36}
37
38/**
39 * Expose `mixinDeep`
40 */
41
42module.exports = mixinDeep;