Skip to content

Instantly share code, notes, and snippets.

@SangHakLee
Last active June 24, 2020 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangHakLee/5b92c5c16f2e828a6e9ab2d37ef53a9e to your computer and use it in GitHub Desktop.
Save SangHakLee/5b92c5c16f2e828a6e9ab2d37ef53a9e to your computer and use it in GitHub Desktop.
v2019 - check some value is empty
const empty = (value) => {
if (value === null) return true
if (typeof value === 'undefined') return true
if (typeof value === 'string' && value === '') return true
if (Array.isArray(value) && value.length < 1) return true
if (typeof value === 'object' && value.constructor.name === 'Object' && Object.keys(value).length < 1 && Object.getOwnPropertyNames(value) < 1) return true
if (typeof value === 'object' && value.constructor.name === 'String' && Object.keys(value).length < 1) return true // new String()
return false
}
@SangHakLee
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment