-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
34 lines (28 loc) · 892 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
This module overrides the 'parse' and 'stringify' methods for
the global JSON object, to handle parsing of large numbers.
This is due to the fact the Javascript uses floating numbers to
store all numbers. Therefore, past a certain point (Number.MAX_SAFE_INTEGER),
integers will be incorrect due to the floating point percision.
*/
// We want to convert all BigInts to be-and-stay strings, so it would not
// 'parse' big numbers values to objects representation
var STORE_AS_STRING = true;
var JSONbigInt = require( 'json-bigint' )({
storeAsString: STORE_AS_STRING
});
var originalParser = JSON.parse
module.exports.override = override;
module.exports.restore = restore;
/**
* Overrides the global JSON methods
*/
function override () {
JSON.parse = JSONbigInt.parse;
}
/**
* Restores the original JSON methods
*/
function restore () {
JSON.parse = originalParser;
}