tc39 / proposal-number-fromstring

{BigInt,Number}.fromString(string, radix)
https://mathiasbynens.github.io/proposal-number-fromstring/
65 stars 7 forks source link

What is needed to get this proposal moving? #22

Open WORMSS opened 1 year ago

WORMSS commented 1 year ago

What is needed to get this moving?

I have not been able to find a working polyfill to have a base36 BigInt.. (That doesn't break on the input 10 which should be 36, but all the ones I found come out as 1) Having something such as BigInt.fromString(input, 36) would help me greatly..

I have a string containing 58000+ 0 and 1 Which I have to manipulate with

const bigNum = BigInt(`0b${binStr}`); // Have to add 0b so BigInt knows its base2
const hexStr = bigNum.toString(16); // resulting in a 14000 character string;
/* this hex string gets transmitted over the network */
/* then on the otherside */
const bigNum = BigInt(`0x${hexStr}`); // Have to add 0x so BigInt knows its base16
const binStr = bigNum.toString(2); // Returns to the original binStr format.

It would be nice to do

const bigNum = BigInt.fromString(binStr, 2); // No dodgy 0b mess
const zStr = bigNum.toString(36); // resulting in a 10000 character string; (Saving 4000 chars)
/* this base36 string gets transmitted over the network */
/* then on the otherside */
const bigNum = BigInt.fromString(zStr, 36); // No dodgy 0z mess (since it doesn't exist, no way to specify its a base36 BigInt(input)
const binStr = bigNum.toString(2); // Returns to the original binStr format.
WORMSS commented 1 year ago

Ignore what I said about the no good polyfills, I seen what people was doing, and I reversed their math, and now it works.. But, still.. Having this built in would be nicer. If I could 'toString' to a higher base than 36 would also be very beneficial to me resulting in shorter strings.