UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.deepAssign = deepAssign;
7
8function isObject(x) {
9 if (Array.isArray(x)) {
10 return false;
11 }
12
13 const type = typeof x;
14 return type === "object" || type === "function";
15}
16
17function assignKey(target, from, key) {
18 const value = from[key]; // https://github.com/electron-userland/electron-builder/pull/562
19
20 if (value === undefined) {
21 return;
22 }
23
24 const prevValue = target[key];
25
26 if (prevValue == null || value == null || !isObject(prevValue) || !isObject(value)) {
27 target[key] = value;
28 } else {
29 target[key] = assign(prevValue, value);
30 }
31}
32
33function assign(to, from) {
34 if (to !== from) {
35 for (const key of Object.getOwnPropertyNames(from)) {
36 assignKey(to, from, key);
37 }
38 }
39
40 return to;
41}
42
43function deepAssign(target, ...objects) {
44 for (const o of objects) {
45 if (o != null) {
46 assign(target, o);
47 }
48 }
49
50 return target;
51}
52// __ts-babel@6.0.4
53//# sourceMappingURL=deepAssign.js.map
\No newline at end of file