peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

Invalid integer with the value 0x leading #239

Closed Mayank8290 closed 1 year ago

Mayank8290 commented 1 year ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch big-integer@1.6.51 for the project I'm working on.

while trying this package with React Native for android , i was getting invalid integer when passing the value with leading 0x , applied this solutions to make this work.

Here is the diff that solved my problem:

diff --git a/node_modules/big-integer/BigInteger.js b/node_modules/big-integer/BigInteger.js
index c4263d5..cae03c7 100644
--- a/node_modules/big-integer/BigInteger.js
+++ b/node_modules/big-integer/BigInteger.js
@@ -10,6 +10,10 @@ var bigInt = (function (undefined) {
     var supportsNativeBigInt = typeof BigInt === "function";

     function Integer(v, radix, alphabet, caseSensitive) {
+        if (v.toString().includes('0x')) {
+            v = v.substring(2);
+            radix = 16;
+        }
         if (typeof v === "undefined") return Integer[0];
         if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive);
         return parseValue(v);

This issue body was partially generated by patch-package.

peterolson commented 1 year ago

Duplicate of issue #237