{"ast":null,"code":"import { isArray, isPlainObject } from 'is-what';\n\nfunction mergeRecursively(origin, newComer, extensions) {\n  // work directly on newComer if its not an object\n  if (!isPlainObject(newComer)) {\n    // extend merge rules\n    if (extensions && isArray(extensions)) {\n      extensions.forEach(function (extend) {\n        newComer = extend(origin, newComer);\n      });\n    }\n\n    return newComer;\n  } // define newObject to merge all values upon\n\n\n  var newObject = isPlainObject(origin) ? Object.keys(origin).reduce(function (carry, key) {\n    var targetVal = origin[key]; // @ts-ignore\n\n    if (!Object.keys(newComer).includes(key)) carry[key] = targetVal;\n    return carry;\n  }, {}) : {};\n  return Object.keys(newComer).reduce(function (carry, key) {\n    // re-define the origin and newComer as targetVal and newVal\n    var newVal = newComer[key];\n    var targetVal = isPlainObject(origin) ? origin[key] : undefined; // extend merge rules\n\n    if (extensions && isArray(extensions)) {\n      extensions.forEach(function (extend) {\n        newVal = extend(targetVal, newVal);\n      });\n    } // early return when targetVal === undefined\n\n\n    if (targetVal === undefined) {\n      carry[key] = newVal;\n      return carry;\n    } // When newVal is an object do the merge recursively\n\n\n    if (isPlainObject(newVal)) {\n      carry[key] = mergeRecursively(targetVal, newVal, extensions);\n      return carry;\n    } // all the rest\n\n\n    carry[key] = newVal;\n    return carry;\n  }, newObject);\n}\n/**\r\n * Merge anything recursively.\r\n * Objects get merged, special objects (classes etc.) are re-assigned \"as is\".\r\n * Basic types overwrite objects or other basic types.\r\n *\r\n * @param {(IConfig | any)} origin\r\n * @param {...any[]} newComers\r\n * @returns the result\r\n */\n\n\nfunction index(origin) {\n  var newComers = [];\n\n  for (var _i = 1; _i < arguments.length; _i++) {\n    newComers[_i - 1] = arguments[_i];\n  }\n\n  var extensions = null;\n  var base = origin;\n\n  if (isPlainObject(origin) && origin.extensions && Object.keys(origin).length === 1) {\n    base = {};\n    extensions = origin.extensions;\n  }\n\n  return newComers.reduce(function (result, newComer) {\n    return mergeRecursively(result, newComer, extensions);\n  }, base);\n}\n\nexport default index;","map":null,"metadata":{},"sourceType":"module"}