| [a762898] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isUnsafeProperty = require('../_internal/isUnsafeProperty.js');
|
|---|
| 6 | const isPlainObject = require('../predicate/isPlainObject.js');
|
|---|
| 7 |
|
|---|
| 8 | function mergeWith(target, source, merge) {
|
|---|
| 9 | const sourceKeys = Object.keys(source);
|
|---|
| 10 | for (let i = 0; i < sourceKeys.length; i++) {
|
|---|
| 11 | const key = sourceKeys[i];
|
|---|
| 12 | if (isUnsafeProperty.isUnsafeProperty(key)) {
|
|---|
| 13 | continue;
|
|---|
| 14 | }
|
|---|
| 15 | const sourceValue = source[key];
|
|---|
| 16 | const targetValue = target[key];
|
|---|
| 17 | const merged = merge(targetValue, sourceValue, key, target, source);
|
|---|
| 18 | if (merged !== undefined) {
|
|---|
| 19 | target[key] = merged;
|
|---|
| 20 | }
|
|---|
| 21 | else if (Array.isArray(sourceValue)) {
|
|---|
| 22 | if (Array.isArray(targetValue)) {
|
|---|
| 23 | target[key] = mergeWith(targetValue, sourceValue, merge);
|
|---|
| 24 | }
|
|---|
| 25 | else {
|
|---|
| 26 | target[key] = mergeWith([], sourceValue, merge);
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 | else if (isPlainObject.isPlainObject(sourceValue)) {
|
|---|
| 30 | if (isPlainObject.isPlainObject(targetValue)) {
|
|---|
| 31 | target[key] = mergeWith(targetValue, sourceValue, merge);
|
|---|
| 32 | }
|
|---|
| 33 | else {
|
|---|
| 34 | target[key] = mergeWith({}, sourceValue, merge);
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 | else if (targetValue === undefined || sourceValue !== undefined) {
|
|---|
| 38 | target[key] = sourceValue;
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | return target;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | exports.mergeWith = mergeWith;
|
|---|