isEmpty internal space determination function to determine whether each other empty array is null

import { oneOf, isEmpty } from '@/libs/tools'

export const isEmpty = (value) => {
  if (value == null) {
    return true
  }
  if (isArrayLike(value)) {
    return !value.length
  } else if (isPlainObject(value)) {
    for (let key in value) {
      if (hasOwnProperty.call(value, key)) {
        return false
      }
    }
    return true
  }
  return false
}

export const isArrayLike = (value) => {
  return value != null && isLength(value.length) && !isFunction(value)
}

export const isPlainObject = (obj) => {
  return Object.prototype.toString.call(obj) === '[object Object]'
}

export const isLength = (value) => {
  return typeof value === 'number' && value > -1 && value % 1 === 0 && value <= Number.MAX_SAFE_INTEGER
}

export const isFunction = (value) => {
  return Object.prototype.toString.call(value) === '[object Function]'
}

 

Guess you like

Origin www.cnblogs.com/pengchenggang/p/11639945.html