This funtion is able to check if a variable is empty. For objects, it uses recurssion to check if the proprties are empty.
const isVariableNotEmpty = (v: string |number | Array<any> | object): boolean => {
if (typeof v === "string" || Array.isArray(v)) {
return v.length > 0;
} else if (typeof v === "number") {
return v > 0;
} else if (typeof v === "object") {
const allValues = Object.values(v);
if (allValues.length === 0) {
return false;
}
return allValues.every((_) => isVariableNotEmpty(_) === true);
} else {
return false;
}
};