Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Last active December 18, 2019 04:31
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 jazzyjackson/44aa24f608b5e05f0204667691229f07 to your computer and use it in GitHub Desktop.
Save jazzyjackson/44aa24f608b5e05f0204667691229f07 to your computer and use it in GitHub Desktop.
// module.exports = function realType(anyType){
// return global[Object.prototype.toString.call(anyType).slice(8, -1)]
// }
const extractType = anyInput => Object.prototype.toString.call(anyInput).slice(8, -1)
module.exports = function realType(anyType){
let literalType = global[extractType(anyType)]
return {
literal: literalType,
is: typeInput => typeInput === literalType,
isNot: typeInput => typeInput !== literalType,
isOneOf: function(){ return Array.from(arguments).some(test => test === literalType) },
isNotOneOf: function(){ return Array.from(arguments).every(test => test !== literalType) },
toString: () => extractType(anyType)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment