You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was able to work around this by sanitizing the value:
let sanitizedValue = value;
if (typeof value === 'bigint') {
if (value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER) {
sanitizedValue = Number(value);
} else {
throw new Error('Can\'t format value as BigInt is out of safe integer range');
}
}
format(expression, sanitizedValue)
Would be great if the library handled big int values.
The text was updated successfully, but these errors were encountered:
Yes, at the absolute minimum we should not be crashing when passed a bigint. 😅
It should be easy enough to stop crashing: Convert anything that can be into Number and proceed as normally and anything outside of that should be either emitted as "######" or as String(bigint) (maybe dependent on a setting). This would be very similar to how dates are handled.
I can't help wondering how difficult it would be to have full support bigint throughout the library. 🤔
We should not crash when passed a bigint. This patch will make it so that
the formatter will convert the bigint to a number if possible, else it will
emit an overflow string (#####). A setting has been added so that instead
of the overflow string, a string version of the bigint is emitted instead.
This is similar how date overflows are handled.
I have made an attempt at supporting bigint throughout the library with
some success, but I have abandoned that because it was complicating the
code a lot and I had some worries about performance.
I think partial support would be possible with low cost. But I don't
have the resources to spare for that right now.
Closes#61
At the moment, the format method throws "TypeError: Cannot mix BigInt and other types, use explicit conversions" when the value is a bigint.
More about the error: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_BigInt_to_number
I was able to work around this by sanitizing the value:
Would be great if the library handled big int values.
The text was updated successfully, but these errors were encountered: