Skip to content

Instantly share code, notes, and snippets.

@atomize
Created October 8, 2018 17:00
Show Gist options
  • Save atomize/57cc71752dc92e226d6f3be7fdd7ba9a to your computer and use it in GitHub Desktop.
Save atomize/57cc71752dc92e226d6f3be7fdd7ba9a to your computer and use it in GitHub Desktop.
ES6 null-undefined-''-[]-{} type check
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