import "core-js/modules/es.array.reduce.js";
export function castArray(val) {
  return Array.isArray(val) ? val : [val];
}
export function get(obj, path) {
  if (!obj) return obj;
  if (!path) return void 0;
  if (typeof path === 'string') path = path.split('.');

  for (let i = 0, len = path.length; i < len; i++) {
    if ((obj = obj[path[i]]) == null) break;
  }

  return obj;
}
export function set(obj, path, val) {
  if (!obj) return obj;
  if (!path) return obj;
  if (typeof path === 'string') path = path.split('.');
  let temp = obj;

  for (var i = 0, len = path.length - 1; i < len; i++) {
    var _temp$path$i;

    temp = (_temp$path$i = temp[path[i]]) !== null && _temp$path$i !== void 0 ? _temp$path$i : temp[path[i]] = {};
  }

  temp[path[i]] = val;
  return obj;
}
export function property(path) {
  return obj => get(obj, path);
}
export function keyBy(arr, iteratee) {
  if (typeof iteratee !== 'function') iteratee = property(iteratee); // @ts-ignore

  return arr.reduce((obj, item) => (obj[iteratee(item)] = item, obj), {});
}
export function omit(obj, path) {
  path = castArray(path);
  const temp = { ...obj
  };
  path.forEach(key => {
    delete temp[key];
  });
  return temp;
}
export function cloneDeep(obj) {
  if (obj == null) return obj;
  if (obj instanceof Date) return new Date(obj);
  if (obj instanceof RegExp) return new RegExp(obj);
  if (typeof obj !== 'object') return obj; // 接下来，要么是对象，要么是数组 可以用 new obj.constructor得到它类型的空值

  let cloneObj = new obj.constructor();

  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      cloneObj[key] = cloneDeep(obj[key]);
    }
  }

  return cloneObj;
}