@smitch/fluid
Version:
A lightweight, Tailwind-powered React/Next.js UI component library.
35 lines • 1.29 kB
JavaScript
export function merge() {
var objects = [];
for (var _i = 0; _i < arguments.length; _i++) {
objects[_i] = arguments[_i];
}
var validObjects = objects.filter(function (obj) { return obj != null && typeof obj === "object"; });
if (validObjects.length === 0)
return {};
if (validObjects.length === 1)
return validObjects[0];
var result = {};
for (var _a = 0, validObjects_1 = validObjects; _a < validObjects_1.length; _a++) {
var obj = validObjects_1[_a];
var keys = Object.keys(obj);
for (var _b = 0, keys_1 = keys; _b < keys_1.length; _b++) {
var key = keys_1[_b];
var currentValue = result[key];
var newValue = obj[key];
var isObject = function (v) { return v !== null && typeof v === "object" && !Array.isArray(v); };
if (isObject(currentValue) && isObject(newValue)) {
result[key] = merge(currentValue, newValue);
}
else {
if (Array.isArray(newValue)) {
result[key] = newValue.slice();
}
else {
result[key] = newValue;
}
}
}
}
return result;
}
//# sourceMappingURL=merge.js.map