/* eslint-disable no-restricted-syntax */
var getRawType = function getRawType(val) {
  return Object.prototype.toString.call(val).slice(8, -1);
};
var isPlainObject = function isPlainObject(val) {
  return getRawType(val) === 'Object';
};
var isPlainObjectOrArray = function isPlainObjectOrArray(val) {
  return isPlainObject(val) || Array.isArray(val);
};
var _merge = function merge(object) {
  for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    sources[_key - 1] = arguments[_key];
  }
  for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
    var source = _sources[_i];
    for (var key in source) {
      if (source[key] === undefined && key in object) {
        continue;
      }
      if (isPlainObjectOrArray(source[key])) {
        if (isPlainObjectOrArray(object[key]) && getRawType(object[key]) === getRawType(source[key])) {
          if (isPlainObject(object[key])) {
            _merge(object[key], source[key]);
          } else {
            object[key] = object[key].concat(source[key]);
          }
        } else {
          object[key] = source[key];
        }
      } else {
        object[key] = source[key];
      }
    }
  }
  return object;
};

export { _merge as merge };
