UNPKG

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