base62 / base62.js

:abcd: A javascript Base62 encode/decoder for node.js
MIT License
142 stars 25 forks source link

BigInt version #78

Open Daniel15 opened 5 years ago

Daniel15 commented 5 years ago

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

CatsMiaow commented 5 years ago

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

Daniel15 commented 5 years ago

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

CatsMiaow commented 5 years ago

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

gvasquez95 commented 3 years ago

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

MrXyfir commented 1 month ago

With BigInt more common nowadays, it'd definitely be nice to have this functionality