BenjaminVanRyseghem / numbro

A JS library for number formatting
http://numbrojs.com
MIT License
1.1k stars 198 forks source link

BigInt support breaks in 1.10.0 and later + "Support BigInt in the operators (Incomplete NumeralJs issue/feature request #778)" #752

Open ryanwh-dw opened 9 months ago

ryanwh-dw commented 9 months ago

So this issue could be "ported over" from numeral https://github.com/adamwdraper/Numeral-js/issues/778 as it is still relevant and would be a welcome improvement.

I've also noticed that to get BigInt support it is possible to revert to older versions of numbro, but it is broken from 1.10.x and later, unless the expected implementation has changed.

The latest version I could find that is working is 1.9.3. See the code below with links for a very simple example.

import numbro from "numbro";
const value = BigInt(1000);

const testBigInt = numbro(value);

const elem = document.getElementById("app");

elem?.append(`${testBigInt.value()}`);

1.9.3 example - working https://codesandbox.io/p/sandbox/working-bigint-w6wgvr

1.10.0 example - broken with Invalid input error https://codesandbox.io/p/sandbox/broken-bigint-1-10-f6ny9f

2.4.0 example - broken with Cannot convert a BigInt value to a number error (still using legacy Old Format in example) https://codesandbox.io/p/sandbox/broken-bigint-ttwsz4