/**
 * merge.js
 *
 * @Author: apple
 * @Date: 2018/1/5 10:15
 */
import deepExtend from 'deep-extend';
import { hasChildren, isObject } from './isType';

var merge = function merge(originalData) {
  var typeObject = isObject(originalData);
  var typeArray = Array.isArray(originalData);
  var copyObj;

  if (hasChildren(originalData)) {
    if (typeArray) {
      copyObj = [];
      originalData.forEach(function (item, index) {
        copyObj[index] = {};
        deepExtend(copyObj[index], item);
      });
    }

    if (typeObject) {
      copyObj = {};
      deepExtend(copyObj, originalData);
    }
  } else {
    copyObj = originalData;
  }

  return copyObj;
};

export default merge;