'use strict';

/*!
 * @techmely/utils
 * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
 * MIT Licensed
 */


// src/isObject.ts
function isObject(val) {
  return toString.call(val) === "[object Object]" && !Array.isArray(val);
}

// src/mergeDeep.ts
function mergeDeep(target, ...sources) {
  if (sources.length === 0) {
    return target;
  }
  const source = sources.shift();
  if (source === void 0) {
    return target;
  }
  if (isObject(target) && isObject(source)) {
    const sourceKeys = Object.keys(source);
    for (const key of sourceKeys) {
      if (isObject(source[key])) {
        if (!target[key]) {
          target[key] = {};
        }
        if (isObject(target[key])) {
          mergeDeep(target[key], source[key]);
        } else {
          target[key] = source[key];
        }
      } else {
        target[key] = source[key];
      }
    }
  }
  return mergeDeep(target, ...sources);
}

exports.mergeDeep = mergeDeep;
