|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [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 merge(target, source) {
|
|---|
| 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 | if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) {
|
|---|
| 18 | target[key] = merge(targetValue, sourceValue);
|
|---|
| 19 | }
|
|---|
| 20 | else if (Array.isArray(sourceValue)) {
|
|---|
| 21 | target[key] = merge([], sourceValue);
|
|---|
| 22 | }
|
|---|
| 23 | else if (isPlainObject.isPlainObject(sourceValue)) {
|
|---|
| 24 | target[key] = merge({}, sourceValue);
|
|---|
| 25 | }
|
|---|
| 26 | else if (targetValue === undefined || sourceValue !== undefined) {
|
|---|
| 27 | target[key] = sourceValue;
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | return target;
|
|---|
| 31 | }
|
|---|
| 32 | function isMergeableValue(value) {
|
|---|
| 33 | return isPlainObject.isPlainObject(value) || Array.isArray(value);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | exports.merge = merge;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.