@@ -10,7 +10,7 @@ export const FUNCTION_TAG = '__@json.function__'
1010export const NUMBER_TAG = '__@json.number__'
1111
1212const UDF = 'undefined'
13- export const undefined = void UDF
13+ export const udf = void UDF
1414
1515export const isString = ( value : any ) : value is string => typeof value === 'string'
1616export const hasOwnProperty = ( obj : any , prop : string ) : boolean =>
@@ -25,8 +25,9 @@ export const isMap = (value: any): value is Map<any, any> => value instanceof Ma
2525export const isSet = ( value : any ) : value is Set < any > => value instanceof Set
2626export const isRegExp = ( value : any ) : value is RegExp => value instanceof RegExp
2727export const isURL = ( value : any ) : value is URL => typeof URL !== UDF && value instanceof URL
28+ const isNumber = ( value : any ) : value is number => typeof value === 'number'
2829export const isNonFiniteNumber = ( value : any ) : value is number =>
29- typeof value === 'number' && ! Number . isFinite ( value )
30+ isNumber ( value ) && ! Number . isFinite ( value )
3031export const isInteger = ( value : any ) : value is number => Number . isInteger ( value )
3132const hasBuffer = ( ) : boolean => typeof Buffer !== UDF && isFunction ( Buffer . isBuffer )
3233
@@ -54,22 +55,22 @@ export const getTypedArrayName = (value: any): string | null => {
5455}
5556
5657const TYPEDARRAY_CTORS : Record < string , any > = {
57- Int8Array : typeof Int8Array !== UDF ? Int8Array : undefined ,
58- Uint8Array : typeof Uint8Array !== UDF ? Uint8Array : undefined ,
59- Uint8ClampedArray : typeof Uint8ClampedArray !== UDF ? Uint8ClampedArray : undefined ,
58+ Int8Array : typeof Int8Array !== UDF ? Int8Array : udf ,
59+ Uint8Array : typeof Uint8Array !== UDF ? Uint8Array : udf ,
60+ Uint8ClampedArray : typeof Uint8ClampedArray !== UDF ? Uint8ClampedArray : udf ,
6061
61- Int16Array : typeof Int16Array !== UDF ? Int16Array : undefined ,
62- Uint16Array : typeof Uint16Array !== UDF ? Uint16Array : undefined ,
63- Float16Array : typeof Float16Array !== UDF ? Float16Array : undefined ,
62+ Int16Array : typeof Int16Array !== UDF ? Int16Array : udf ,
63+ Uint16Array : typeof Uint16Array !== UDF ? Uint16Array : udf ,
64+ Float16Array : typeof Float16Array !== UDF ? Float16Array : udf ,
6465
65- Int32Array : typeof Int32Array !== UDF ? Int32Array : undefined ,
66- Uint32Array : typeof Uint32Array !== UDF ? Uint32Array : undefined ,
67- Float32Array : typeof Float32Array !== UDF ? Float32Array : undefined ,
66+ Int32Array : typeof Int32Array !== UDF ? Int32Array : udf ,
67+ Uint32Array : typeof Uint32Array !== UDF ? Uint32Array : udf ,
68+ Float32Array : typeof Float32Array !== UDF ? Float32Array : udf ,
6869
69- Float64Array : typeof Float64Array !== UDF ? Float64Array : undefined ,
70+ Float64Array : typeof Float64Array !== UDF ? Float64Array : udf ,
7071
71- BigInt64Array : typeof BigInt64Array !== UDF ? BigInt64Array : undefined ,
72- BigUint64Array : typeof BigUint64Array !== UDF ? BigUint64Array : undefined ,
72+ BigInt64Array : typeof BigInt64Array !== UDF ? BigInt64Array : udf ,
73+ BigUint64Array : typeof BigUint64Array !== UDF ? BigUint64Array : udf ,
7374}
7475
7576export const toHex = ( value : Uint8Array ) : string => {
@@ -105,6 +106,9 @@ export const toSerializable = (value: any, options: { allowFunction?: boolean }
105106 if ( isNonFiniteNumber ( value ) ) {
106107 return { [ NUMBER_TAG ] : String ( value ) }
107108 }
109+ if ( isNumber ( value ) && ! Number . isSafeInteger ( value ) ) {
110+ throw new Error ( 'Number exceeds safe integer range' )
111+ }
108112
109113 if ( isDate ( value ) ) {
110114 return { [ DATE_TAG ] : value . getTime ( ) }
0 commit comments