import _typeof from 'babel-runtime/helpers/typeof';
export var isEmpty = function isEmpty(v) {
  return v === '' || v === void 0 || v === null;
};

export function debounce(delay, fn) {
  var movement = null;
  return function () {
    var args = arguments;
    clearTimeout(movement);
    movement = setTimeout(function () {
      fn.apply(this, args);
    }, delay);
  };
}

export function transformArrToMap(arr, key) {
  return arr.reduce(function (res, data) {
    if (key) {
      res[data[key]] = true;
    } else {
      res[data] = true;
    }
    return res;
  }, {});
}

export function isFunction(target) {
  return Object.prototype.toString.call(target) === '[object Function]';
}

export function isObject(target) {
  return Object.prototype.toString.call(target) === '[object Object]';
}

export var isString = function isString(target) {
  return Object.prototype.toString.call(target) === '[object String]';
};

export var isJSON = function isJSON(target) {
  if (isString(target)) {
    try {
      var obj = JSON.parse(target);
      if ((isObject(obj) || Array.isArray(obj)) && obj) {
        return true;
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }
};

export function isPromise(obj) {
  return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
}