Skip to content

Instantly share code, notes, and snippets.

@lyatziv
Last active December 18, 2020 16:23
Show Gist options
  • Save lyatziv/6cba8cec35cf9fe12f1bffc1bfbf215f to your computer and use it in GitHub Desktop.
Save lyatziv/6cba8cec35cf9fe12f1bffc1bfbf215f to your computer and use it in GitHub Desktop.
A presumptive function with exhaustive data type tests for empty, null, values.
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