1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.deepAssign = void 0;
|
4 | function isObject(x) {
|
5 | if (Array.isArray(x)) {
|
6 | return false;
|
7 | }
|
8 | const type = typeof x;
|
9 | return type === "object" || type === "function";
|
10 | }
|
11 | function assignKey(target, from, key) {
|
12 | const value = from[key];
|
13 |
|
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 | }
|
25 | function 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 | }
|
33 | function deepAssign(target, ...objects) {
|
34 | for (const o of objects) {
|
35 | if (o != null) {
|
36 | assign(target, o);
|
37 | }
|
38 | }
|
39 | return target;
|
40 | }
|
41 | exports.deepAssign = deepAssign;
|
42 |
|
\ | No newline at end of file |