This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
69 lines (53 loc) · 1.34 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var isObj = require('is-obj');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Cannot convert undefined or null to object');
}
return Object(val);
}
function assignKey(to, from, key) {
var val = from[key];
if (val === undefined || val === null) {
return;
}
if (hasOwnProperty.call(to, key)) {
if (to[key] === undefined || to[key] === null) {
throw new TypeError('Cannot convert undefined or null to object (' + key + ')');
}
}
if (!hasOwnProperty.call(to, key) || !isObj(val)) {
to[key] = val;
} else {
to[key] = assign(Object(to[key]), from[key]);
}
}
function assign(to, from) {
if (to === from) {
return to;
}
from = Object(from);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
assignKey(to, from, key);
}
}
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
assignKey(to, from, symbols[i]);
}
}
}
return to;
}
module.exports = function deepAssign(target) {
target = toObject(target);
for (var s = 1; s < arguments.length; s++) {
assign(target, arguments[s]);
}
return target;
};