-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (28 loc) · 782 Bytes
/
index.js
File metadata and controls
28 lines (28 loc) · 782 Bytes
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
var extend = require('extend')
module.exports = function safeExtend () {
var arg = Array.from(arguments).map(function (item) {
var cloneItem
// object and array
if(typeof item === 'object') {
if (Array.isArray(item)) {
cloneItem = extend(true, [], item)
}
else {
cloneItem = extend(true, {}, item)
}
}
return cloneItem? cloneItem: item
})
return extend.apply(undefined, arg)
}
module.exports.clone = function clone(target) {
if (typeof target === 'object' && target !== null) {
if (Array.isArray(target)) {
return extend(true, [], target)
}
return extend(true, {}, target)
}
else {
return target
}
}