-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (29 loc) · 810 Bytes
/
index.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
/*
* @exports extend
*/
/**
Extends a set of objects. Merges them into one new object
@public
@type Function
@param {Boolean} deep Should it extend all child objects
@param []{Object} splat objects to merge
*/
function extend( deep ) {
var out, objs, i, obj, prop, val
out = {}
typeof deep === "boolean" ? ( objs = [].slice.call(arguments, 1), deep = deep ) :
( objs = [].slice.call(arguments, 0), deep = false )
for( i = 0; i < objs.length; i++ ) {
obj = objs[ i ]
for( prop in obj ) {
val = obj[ prop ]
if( deep && typeof val === "object" && typeof out[prop] === "object") {
out[ prop ] = extend( out[prop], val )
} else {
out[ prop ] = val
}
}
}
return out
}
module.exports = extend;