base62.js icon indicating copy to clipboard operation
base62.js copied to clipboard

BigInt version

Open Daniel15 opened this issue 4 years ago • 4 comments

Would be good to get BigInt support... I think the current version doesn't support BigInts.

Daniel15 avatar Jul 27 '19 04:07 Daniel15

https://gist.github.com/CatsMiaow/7fc9f28c9d2a5ab6d7605646086fdca6 I created a sample code using bignumber.js

CatsMiaow avatar Aug 30 '19 06:08 CatsMiaow

@CatsMiaow Modern browsers have a native BigInt type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt :)

Daniel15 avatar Aug 30 '19 07:08 Daniel15

I know but BigInt doesn't work as I want.

console.log(616580508813361172); // 616580508813361200
BigInt(616580508813361172); // 616580508813361152n
616580508813361152n.toString(); // "616580508813361152"
BigInt(616580508813361172).toString(); // "616580508813361152"
BigInt(616580508813361172).toString() === "616580508813361172" // false

But as I wrote this comment, I checked again

BigInt("616580508813361172").toString() === "616580508813361172" // true

🤔

Rewritten with BigInt https://gist.github.com/CatsMiaow/b479e96d5613dbd4711ab6d768b3eea0

CatsMiaow avatar Sep 02 '19 03:09 CatsMiaow

same issue here trying to encode this hex number: 5fce40b61ddd1a677bbdd9d7 back & forth get's it truncated into 5fce40b61ddd240000000000

gvasquez95 avatar Dec 18 '20 13:12 gvasquez95