JSFiddle - React, Tailwind, and code Playground
JavaScript
function merge() {
var options, name, src, copy, copyIsArray, clone, targetKey, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false;
var currentId = typeof arguments[length - 1] == 'string' ? arguments[length - 1] : null;
if (currentId) {
length = length - 1;
}
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep
// copy)
if (typeof target !== "object" && !jQuery.isFunction(target)) {
target = {};
}
// extend jQuery itself if only one argument is passed
if (length === i) {
target = this;
--i;
}
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
if (!options.hasOwnProperty(name)) {
continue;
}
copy = options[name];
var mm = undefined, src = undefined;
if (currentId && jQuery.isArray(options) && jQuery.isArray(target)) {
for (mm = 0; mm < target.length; mm++) {
if (currentId && (isSameString(target[mm][currentId], copy[currentId]))) {
src = target[mm];
break;
}
}
}
else {
src = target[name];
}
// Prevent never-ending loop
if (target === copy) {
continue;
}
targetKey = mm !== undefined ? mm : name;
// Recurse if we're merging plain objects or arrays
if (deep && copy &&...