Last active
December 18, 2019 04:31
-
-
Save jazzyjackson/44aa24f608b5e05f0204667691229f07 to your computer and use it in GitHub Desktop.
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
// 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