1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.deepAssign = deepAssign;
|
7 |
|
8 | function 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 |
|
17 | function assignKey(target, from, key) {
|
18 | const value = from[key];
|
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 |
|
33 | function 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 |
|
43 | function 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 |
|
53 |
|
\ | No newline at end of file |