cxc-szcx-uniapp/uni_modules/lime-shared/isEmpty/index.ts

83 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-01-13 02:49:20 +00:00
// @ts-nocheck
import {isDef} from '../isDef'
import {isString} from '../isString'
import {isNumber} from '../isNumber'
/**
*
*
* 0
* 0
* 0
* null或undefinedtrue
*
*
* @param {any} value -
* @returns {boolean} truefalse
*/
// #ifdef APP-IOS || APP-ANDROID
export function isEmpty(value : any | null) : boolean {
// 为null
if(!isDef(value)){
return true
}
// 为空字符
if(isString(value)){
return value.toString().trim().length == 0
}
// 为数值
if(isNumber(value)){
return false
}
if(typeof value == 'object'){
// 数组
if(Array.isArray(value)){
return (value as Array<unknown>).length == 0
}
// Map
if(value instanceof Map<unknown, unknown>) {
return value.size == 0
}
// Set
if(value instanceof Set<unknown>) {
return value.size == 0
}
if(value instanceof UTSJSONObject) {
return value.toMap().size == 0
}
return JSON.stringify(value) == '{}'
}
return true
}
// #endif
// #ifndef APP-IOS || APP-ANDROID
export function isEmpty(value: any): boolean {
// 检查是否为null或undefined
if (value == null) {
return true;
}
// 检查字符串是否为空
if (typeof value === 'string') {
return value.trim().length === 0;
}
// 检查数组是否为空
if (Array.isArray(value)) {
return value.length === 0;
}
// 检查对象是否为空
if (typeof value === 'object') {
return Object.keys(value).length === 0;
}
// 其他类型(如数字、布尔值等)不为空
return false;
}
// #endif