num-or-not
Check for a valid Number value.
Numbers, and values that can be cast or evaluated to numbers will return true
.
All other values will return false
.
Installation
$ npm install --save num-or-not
Usage
const isNumber = ; // Integers; // => true; // => true; // => true; // => true // Floats (Decimal & Comma); // => true; // => true; // => true // Octal (ES6); // => true; // => true; // => true; // => true // Binary (ES6); // => true; // => true // Hexadecimal; // => true ; // => true // Exponential; // => true; // => true; // => true; // => true // Currency Values; // => true; // => true // "Evaluates to Int" values; // => true; // => true; // => true; // => true; // => true
Known Limitations
-
These binary and octal formats are only supported in ES6 environments:
-
Binary:
0b0
-
Octal:
0o144
&0O144
-
In order to support numbers with commas or decimals (currencies, Dewey Decimal System, etc), some unique values can pass as valid numbers (see Issue #1):
-
1,2,3.4.5
-
1,2,3,4.5
-
Open a pull request or issue if you think we need tighter control over these limitations.
Why?
Why do we need another open source number validator in Javascript? We don't, but I wanted one to help keep me accountable of the data type nuances in JS.
License
MIT @ Michael Wuergler