function _exists (thing) {
const IS_UNDEFINED = 'undefined' === (typeof thing)
const IS_NULL = null === thing
if (IS_UNDEFINED || IS_NULL) return false
const TYPE = (typeof thing)
const IS_OBJECT = ('object' === TYPE)
const IS_STRING = ('string' === TYPE)
const IS_NUMBER = ('number' === TYPE)
const IS_ARRAY = (Array.isArray(thing))
if (IS_STRING || IS_ARRAY) return 0 < thing.length
if (IS_NUMBER) return 0 < String(thing).length
if (IS_OBJECT) return 0 < Object.keys(thing).length
return true
}
Last active
July 3, 2019 18:59
-
-
Save CyberStrike/aecd7a8c1f6ea66deaabacce984b27e6 to your computer and use it in GitHub Desktop.
Utility function for checking if a value is truthy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment