import _typeof from '@babel/runtime/helpers/typeof';

function ordinary(object) {
  if (_typeof(object) !== 'object' || object === null) {
    return false;
  }
  if (Object.getPrototypeOf(object) === null) {
    return true;
  }
  var proto = object;
  while (Object.getPrototypeOf(proto) !== null) {
    proto = Object.getPrototypeOf(proto);
  }
  return Object.getPrototypeOf(object) === proto;
}
function clone(target, source) {
  for (var key in source) {
    var older = target[key],
      newer = source[key];
    if (older === newer && newer != null) continue;
    if (newer && ordinary(newer)) {
      target[key] = clone(ordinary(older) ? older : {}, newer);
    } else if (newer && Array.isArray(newer)) {
      target[key] = clone(Array.isArray(older) ? older : [], newer);
    } else {
      target[key] = newer;
    }
  }
  return target;
}
function assign(target) {
  if (target == null) {
    return target;
  }
  for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    sources[_key - 1] = arguments[_key];
  }
  return sources.reduce(function (last, source) {
    return clone(last, source);
  }, target);
}

export { assign as default };
