Last active
April 20, 2021 14:15
-
-
Save astromac/be60657451b098fb6d09bd0745343e85 to your computer and use it in GitHub Desktop.
isEmpty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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