A stricter
parseInt
andparseFloat
.
Usage
numero; // 42numero; // 42numero; // 42numero; // nullnumero; // nullnumero; // null numero; // 42numero; // 42numero; // 42numero; // 3.14numero; // 3.14numero; // 3.14
-
null
is returned ifx
cannot be parsed to an integer/float. -
An integer is also a float.
-
x
can have trailing/leading whitespace.
Numero is stricter than the native parseInt
and parseFloat
in that extraneous characters are not allowed. For example:
; // 42numero; // null ; // 3.14numero; // null
Numero can also handle numbers in their octal and hexadecimal representations, and negative numbers too:
numero; // 42numero; // -42
API
numero.isInt(x)
Returns true
if x
can be parsed to an integer. Alias: isInteger
numero.parseInt(x)
Returns an integer, or null
if x
cannot be parsed to an integer. Alias: parseInteger
.
numero.isFloat(x)
Returns true
if x
can be parsed to a float.
numero.parseFloat(x)
Returns a float, or null
if x
cannot be parsed to a float.
Installation
Install via npm:
$ npm i --save numero
Changelog
- 0.1.0
- Initial release