qc-to_int
A simple JavaScript utility to convert various values to an integer.
What it does that parseInt
doesn't
- Allow a default value to be set instead of returning
NaN
. - Convert
'-0'
to0
instead of-0
. - Convert strings in scientific notation to the correct value.
'1e-4'
is converted to0
instead of1
.
- Convert very large numbers written in scientific notation to the correct
value.
6.022e23
is converted to6.022e23
instead of6
.
- Convert
Number.MIN_VALUE
to0
instead of5
. - Convert
Number.MAX_VALUE
toNumber.MAX_VALUE
instead of1
. - Convert
Infinity
toInfinity
instead ofNaN
.
Installation
npm install --save qc-to_int
Example Usage
; ; // 3; // 10000; // -3; // -3; // `undefined`; // `null`; // `''`; // `null`; // `0`; // `0`; // `NaN`; // `null`; // `null`; // `null`; // `undefined`; // `null`