source: node_modules/es-toolkit/dist/object/merge.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[a762898]1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isUnsafeProperty = require('../_internal/isUnsafeProperty.js');
6const isPlainObject = require('../predicate/isPlainObject.js');
7
8function 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}
32function isMergeableValue(value) {
33 return isPlainObject.isPlainObject(value) || Array.isArray(value);
34}
35
36exports.merge = merge;
Note: See TracBrowser for help on using the repository browser.