Open neverendingqs opened 3 years ago
How would the custom number parser be used to solve the defect in parsing long decimal numbers when using the native BigInt with json-bigint?
How would the custom number parser be used to solve the defect in parsing long decimal numbers when using the native BigInt with json-bigint?
I'm thinking something like this:
const JSONBI = require('json-bigint')({
numberParser: str => {
const attempt = Number(str);
if(str.indexOf('.') >= 0) {
// Or do something else if the precision of decimal numbers is important
return attempt;
}
if(attempt <= Number.MIN_SAFE_INTEGER || attempt >= Number.MAX_SAFE_INTEGER) {
return BigInt(str);
}
return attempt;
}
});
@sidorares - bump :)
@sidorares - bump :)
@sidorares - bump :). Any concerns with the pull request?
Is this what you had in mind @sidorares?