0.0.2 • Published 11 months ago
nv-string-s2n v0.0.2
nv-string-s2n
parse a string to a number, same as eval("1.1....")
support 0b|0B 0o|0O 0x|0X , bigInt, double, NaN , Infinity , -Infinity JUST Like parseFloat DO;
support lodash _ seperator, loose rule, NOT so strict as parseFloat;
extra support 0q|0Q, it means radix 4
NOT support oct-using-leading-0-without-oO, such as 034
- IF meet BigDemical, it do NOTHING just return a pair "maybe_big_demical",\<the-original-string>
this pkg is SLOW( 50 times slower than parseFloat/parseInt/Number/BigInt ) , should ONLY be used in repl/cli TOOLS , its just for test the state-transfer when parseFloat.
but its faster than eval
- it is USED for test 0q123 0Q123 in nvlang, nvlang support int-number-literal-of-radix-4
install
- npm install nv-string-s2n
usage
const parse_numlike = require("nv-string-s2n");
example
> parse_numlike("0b111_001")
57
> parse_numlike("0q12_30")
108
> parse_numlike("-0o567")
-375
> parse_numlike("-0xabcdef")
-11259375
>
> parse_numlike("0b111_001n")
57n
> parse_numlike("0q12_30n")
108n
> parse_numlike("-0o567n")
-375n
> parse_numlike("-0xabcdefn")
-11259375n
>
>
> parse_numlike("1.1")
1.1
> parse_numlike("-1.1E200")
-1.1e+200
>
> parse_numlike("0b_11_10")
14
> parse_numlike("0b123")
Uncaught 'for bin: only 0b[10_]+n? is valid'
>
>
TEST
long 0b
TEST# node b.js 100000
{ rounds: 1, f: [Function: using_Number], costed: 23.86091709136963 }
{ rounds: 1, f: [Function: using_s2n], costed: 479.0749931335449 }
{ rounds: 1, f: [Function: using_eval], costed: 670.5458121299744 }
short 0b
TEST# node short-b.js 100000
{ rounds: 1, f: [Function: using_Number], costed: 9.460304737091064 }
{ rounds: 1, f: [Function: using_s2n], costed: 6.899360656738281 }
{ rounds: 1, f: [Function: using_eval], costed: 64.11680889129639 }
root@dli:/mnt/sda3/NV6-/nvstr/pkgs/nv-string-s2n/TEST#
METHODS
APIS
LICENSE
- ISC
0.0.2
11 months ago