Last active
September 6, 2022 07:53
-
-
Save iwill/5440541 to your computer and use it in GitHub Desktop.
isNumber(aNorNaN) === !isNaN(aNorNaN)
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
function isNumber(x, object, bigint, string) { | |
let type = typeof x; | |
if (object && type == "object") { | |
x = x instanceof Number ? x.valueOf() : NaN; | |
type = typeof x; | |
} | |
else if (bigint && type == "bigint") { | |
x = x >= Number.MIN_SAFE_INTEGER && x <= Number.MAX_SAFE_INTEGER ? Number(x) : NaN; | |
type = typeof x; | |
} | |
else if (string && type == "string") { | |
x = x ? Number(x) : NaN; | |
type = typeof x; | |
} | |
return type == "number" && !isNaN(x); | |
}; |
Author
iwill
commented
Sep 6, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment