Last active
June 24, 2020 06:37
-
-
Save SangHakLee/5b92c5c16f2e828a6e9ab2d37ef53a9e to your computer and use it in GitHub Desktop.
v2019 - check some value is empty
This file contains 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 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/SangHakLee/is