Appearance
checkEmpty 判断空值
function checkEmpty(value: unknown): value is null | undefined | '' | [] | Record<string, never> | 0
判断传入值是否为空。''、0、空数组、空对象、null 和 undefined 都会被视为空值。
参数
| 参数名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 待判断的值 | unknown | 必填 |
返回值
| 返回值 | 说明 | 类型 |
|---|---|---|
| result | 是空值时返回 true,否则返回 false | boolean |
示例
typescript
import { checkEmpty } from '@mingto/tools'
checkEmpty('') // true
checkEmpty(0) // true
checkEmpty([]) // true
checkEmpty({}) // true
checkEmpty('0') // false注意事项
0会被视为空值;如果业务中0是有效值,请使用checkEmptyNotZero。