Skip to content

Instantly share code, notes, and snippets.

@astromac
Last active April 20, 2021 14:15
Show Gist options
  • Save astromac/be60657451b098fb6d09bd0745343e85 to your computer and use it in GitHub Desktop.
Save astromac/be60657451b098fb6d09bd0745343e85 to your computer and use it in GitHub Desktop.
isEmpty
/** Determines if passed value is empty or not.
* Works on multiple data types.
**/
const isEmpty = data => {
let count = 0;
if (typeof (data) === 'number' || typeof (data) === 'boolean') { return false; }
if (typeof (data) === 'undefined' || data === null) { return true; }
if (typeof (data.length) !== 'undefined') { return data.length === 0; }
Object.keys(data).forEach(() => { count += 1; });
return count === 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment