Skip to content

Commit 5292ffe

Browse files
committed
BugFix for BigInt('0xffffffffffffffff') by CBOR lib
1 parent b9311f0 commit 5292ffe

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
* @format
33
*/
44

5-
if (typeof BigInt === 'undefined') global.BigInt = require('big-integer')
5+
if (typeof BigInt === 'undefined') {
6+
const bi = require('big-integer')
7+
8+
// BugFix for BigInt('0xffffffffffffffff') by CBOR lib
9+
function myBigInt(value) {
10+
if (typeof value === 'string') {
11+
const match = value.match(/^0([xo])([0-9a-f]+)$/i)
12+
if (match) {
13+
return bi(match[2], match[1].toLowerCase() === 'x' ? 16 : 8)
14+
}
15+
}
16+
return bi(value)
17+
}
18+
19+
global.BigInt = myBigInt;
20+
}
21+
622
global.Buffer = global.Buffer || require('buffer').Buffer;
723

824
import process from 'process';

0 commit comments

Comments
 (0)