isEmpty.ts 681 Bytes
/**
 * 是否为空
 * @param {any} data
 * @return {Boolean}
 */
export const isEmpty = function (data: any): boolean {
  if (data === '' || data === null || data === undefined) {
    return true;
  }
  // [] {} 0 false/true
  else {
    const typeofs = Object.prototype.toString.call(data);
    // 数组
    if (typeofs === '[object Array]') {
      if (data.length > 0) {
        return false;
      } else {
        return true;
      }
    }
    // 对象
    else if (typeofs === '[object Object]') {
      if (Object.keys(data).length > 0) {
        return false;
      } else {
        return true;
      }
    } else {
      // 不为空
      return false;
    }
  }
};