/**
 * 合并对象.
 */
export function mergeObject(source, target) {
  if (!source && !target) {
    return {};
  }

  if (!source) {
    return !!target && isObject(target) ? deepClone(target) : {};
  }

  if (!target) {
    return !!source && isObject(source) ? deepClone(source) : {};
  }

  const resultObj = deepClone(source);
  for (const key in target) {
    const sourceObj = resultObj[key];
    const targetObj = target[key];

    if (!isObject(sourceObj) || !isObject(targetObj)) {
      resultObj[key] = deepClone(target[key]);
      continue;
    }
    resultObj[key] = mergeObject(sourceObj, targetObj);
  }
  return resultObj;
}
