const isEmpty = (value) => {
let tmp = value;
if (value === null || value === undefined) {
tmp = '';
// true/false will be translated to "ture"/"false", so, boolean type always not empty
} else if (typeof value === 'number' || typeof value === 'boolean') {
tmp = String(value);
}
let ret = tmp;
if (typeof tmp === 'string' || Array.isArray(tmp)) {
ret = tmp.length;
} else if (typeof tmp === 'object') {
ret = Object.keys(tmp).length;
}
return !ret;
};
网友评论