Created
October 8, 2018 17:00
-
-
Save atomize/57cc71752dc92e226d6f3be7fdd7ba9a to your computer and use it in GitHub Desktop.
ES6 null-undefined-''-[]-{} type check
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
const isEmpty = value => { | |
if (typeof value === 'number') return false | |
else if (typeof value === 'string') return value.trim().length === 0 | |
else if (Array.isArray(value)) return value.length === 0 | |
else if (typeof value === 'object') return value == null || Object.keys(value).length === 0 | |
else if (typeof value === 'boolean') return false | |
else return !value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment