File tree Expand file tree Collapse file tree 1 file changed +3
-0
lines changed Expand file tree Collapse file tree 1 file changed +3
-0
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,13 @@ export function enableCustomJSONParsingForLargeNumbers(pg: typeof pgLib) {
12
12
pg . types . setTypeParser ( pg . types . builtins . JSONB , parseJSONWithLargeNumbersAsStrings ) ;
13
13
}
14
14
15
+ const { MAX_SAFE_INTEGER , MIN_SAFE_INTEGER } = Number ;
16
+
15
17
function parseJSONWithLargeNumbersAsStrings ( str : string ) {
16
18
return parse ( str , undefined , function ( k , str ) {
17
19
const n = + str ; // JSON parser ensures this is an ordinary number, parseInt(str, 10) not needed
18
20
if ( n === Infinity || n === - Infinity ) return str ;
21
+ if ( ( n < MIN_SAFE_INTEGER || n > MAX_SAFE_INTEGER ) && str . indexOf ( '.' ) === - 1 ) return str ;
19
22
if ( str . length <= 15 || numericStringToExponential ( str ) === n . toExponential ( ) ) return n ;
20
23
return str ;
21
24
} ) ;
You can’t perform that action at this time.
0 commit comments