Skip to content

checkEmpty 判断空值

function checkEmpty(value: unknown): value is null | undefined | '' | [] | Record<string, never> | 0

判断传入值是否为空。''0、空数组、空对象、nullundefined 都会被视为空值。

参数

参数名说明类型默认值
value待判断的值unknown必填

返回值

返回值说明类型
result是空值时返回 true,否则返回 falseboolean

示例

typescript
import { checkEmpty } from '@mingto/tools'

checkEmpty('') // true
checkEmpty(0) // true
checkEmpty([]) // true
checkEmpty({}) // true
checkEmpty('0') // false

注意事项

  • 0 会被视为空值;如果业务中 0 是有效值,请使用 checkEmptyNotZero