export const notEmpty = (data) => {
const type = Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
switch (type) {
case 'null':
case 'undefined':
return false;
case 'object':
return Object.keys(data).length > 0;
case 'array':
case 'string':
return data !== 'undefined' && data !== 'null' && data.length > 0;
case 'boolean':
return !!data;
default:
return true;
}
};
I've made above function for checking null, undefined, '' and empty Array and Object. But as you can see, it has many ifs. Is there another better solution for checking them?