Last active
February 11, 2023 08:03
-
-
Save KooiInc/2d58266e590052ab9d2042a79ffebb7c to your computer and use it in GitHub Desktop.
Check all js type
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
const ISOneOf = (obj, ...params) => !!params.find( param => IS(obj, param) ); | |
function IS(obj, ...shouldBe) { | |
if (shouldBe.length > 1) { return ISOneOf(obj, ...shouldBe); } | |
shouldBe = shouldBe.shift(); | |
const invalid = `Invalid parameter(s)`; | |
const self = obj === 0 ? Number : obj === `` ? String : | |
!obj ? {name: invalid} : | |
Object.getPrototypeOf(obj)?.constructor; | |
return shouldBe ? shouldBe === self?.__proto__ || shouldBe === self : | |
self?.name ?? invalid; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment