Last active
December 18, 2020 16:23
-
-
Save lyatziv/6cba8cec35cf9fe12f1bffc1bfbf215f to your computer and use it in GitHub Desktop.
A presumptive function with exhaustive data type tests for empty, null, values.
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
export default (tr) => { | |
const hasLength = (val) => val.length | |
const noTest = () => true | |
const notZero = (val) => val !== 0 | |
const types = { | |
'symbol': (val) => val.description === "", | |
'function': noTest, | |
'undefined': noTest, | |
'bigint': notZero, | |
'object': (val) => Object.is(val, {}), | |
'boolean': (val) => val, | |
'array': hasLength, | |
'string': hasLength, | |
'number': notZero, | |
} | |
return !types[typeof tr](tr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment