persona-community-5/.pnpm-store/v3/files/05/66e4f175d7ab12c6579685b09746ddef5a1da247538008734d00a8139e821a080f0882048ccb659673c3f32d6ecf983d09cfa2ca1ad1f6125fd122e6ef3cc5
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

46 lines
1.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepMerge = deepMerge;
exports.isObjectNotArray = isObjectNotArray;
/**
* Check if the variable contains an object strictly rejecting arrays
* @returns `true` if obj is an object
*/
function isObjectNotArray(obj) {
return typeof obj === 'object' && obj != null && !Array.isArray(obj);
}
/**
* Pure function - doesn't mutate either parameter!
* Merges two objects together deeply, overwriting the properties in first with the properties in second
* @param first The first object
* @param second The second object
* @returns a new object
*/
function deepMerge(first = {}, second = {}) {
// get the unique set of keys across both objects
const keys = new Set(Object.keys(first).concat(Object.keys(second)));
return Array.from(keys).reduce((acc, key) => {
const firstHasKey = key in first;
const secondHasKey = key in second;
const firstValue = first[key];
const secondValue = second[key];
if (firstHasKey && secondHasKey) {
if (isObjectNotArray(firstValue) && isObjectNotArray(secondValue)) {
// object type
acc[key] = deepMerge(firstValue, secondValue);
}
else {
// value type
acc[key] = secondValue;
}
}
else if (firstHasKey) {
acc[key] = firstValue;
}
else {
acc[key] = secondValue;
}
return acc;
}, {});
}
//# sourceMappingURL=deepMerge.js.map