@@ -8,8 +8,9 @@ export const URL_TAG = '__@json.url__'
88export const FUNCTION_TAG = '__@json.function__'
99export const NUMBER_TAG = '__@json.number__'
1010
11- export const undefined = void 0
12- export const isUndefined = ( value : any ) : value is undefined => typeof value === 'undefined'
11+ const UDF = 'undefined'
12+ export const undefined = void UDF
13+
1314export const isString = ( value : any ) : value is string => typeof value === 'string'
1415export const hasOwnProperty = ( obj : any , prop : string ) : boolean =>
1516 Object . prototype . hasOwnProperty . call ( obj , prop )
@@ -22,28 +23,28 @@ export const isDate = (value: any): value is Date => value instanceof Date
2223export const isMap = ( value : any ) : value is Map < any , any > => value instanceof Map
2324export const isSet = ( value : any ) : value is Set < any > => value instanceof Set
2425export const isRegExp = ( value : any ) : value is RegExp => value instanceof RegExp
25- export const isURL = ( value : any ) : value is URL => ! isUndefined ( URL ) && value instanceof URL
26+ export const isURL = ( value : any ) : value is URL => typeof URL !== UDF && value instanceof URL
2627export const isNonFiniteNumber = ( value : any ) : value is number =>
2728 typeof value === 'number' && ! Number . isFinite ( value )
2829export const isInteger = ( value : any ) : value is number => Number . isInteger ( value )
29- const hasBuffer = ( ) : boolean => typeof Buffer !== 'undefined'
30+ const hasBuffer = ( ) : boolean => typeof Buffer !== UDF && isFunction ( Buffer . isBuffer )
3031
3132export const isBuffer = ( value : any ) : value is Buffer =>
3233 hasBuffer ( ) && isFunction ( Buffer . isBuffer ) && Buffer . isBuffer ( value )
3334export const isArrayBuffer = ( value : any ) : value is ArrayBuffer =>
34- ! isUndefined ( ArrayBuffer ) && value instanceof ArrayBuffer
35+ typeof ArrayBuffer !== UDF && value instanceof ArrayBuffer
3536
3637export const isTypedArray = ( value : any ) : value is ArrayBufferView => {
37- if ( isUndefined ( value ) ) return false
38- if ( ! isUndefined ( ArrayBuffer ) && isFunction ( ArrayBuffer . isView ) && ArrayBuffer . isView ( value ) ) {
38+ if ( value == null ) return false
39+ if ( typeof ArrayBuffer !== UDF && isFunction ( ArrayBuffer . isView ) && ArrayBuffer . isView ( value ) ) {
3940 return Object . prototype . toString . call ( value ) !== '[object DataView]'
4041 }
4142 const tag = Object . prototype . toString . call ( value )
4243 return tag . endsWith ( 'Array]' ) && tag !== '[object Array]'
4344}
4445
4546export const getTypedArrayName = ( value : any ) : string | null => {
46- if ( isUndefined ( value ) ) return null
47+ if ( value == null ) return null
4748 const ctor = ( value as any ) . constructor
4849 if ( ctor && isString ( ctor . name ) ) return ctor . name
4950 const tag = Object . prototype . toString . call ( value )
@@ -52,22 +53,22 @@ export const getTypedArrayName = (value: any): string | null => {
5253}
5354
5455const TYPEDARRAY_CTORS : Record < string , any > = {
55- Int8Array : ! isUndefined ( Int8Array ) ? Int8Array : undefined ,
56- Uint8Array : ! isUndefined ( Uint8Array ) ? Uint8Array : undefined ,
57- Uint8ClampedArray : ! isUndefined ( Uint8ClampedArray ) ? Uint8ClampedArray : undefined ,
56+ Int8Array : typeof Int8Array !== UDF ? Int8Array : undefined ,
57+ Uint8Array : typeof Uint8Array !== UDF ? Uint8Array : undefined ,
58+ Uint8ClampedArray : typeof Uint8ClampedArray !== UDF ? Uint8ClampedArray : undefined ,
5859
59- Int16Array : ! isUndefined ( Int16Array ) ? Int16Array : undefined ,
60- Uint16Array : ! isUndefined ( Uint16Array ) ? Uint16Array : undefined ,
61- Float16Array : ! isUndefined ( Float16Array ) ? Float16Array : undefined ,
60+ Int16Array : typeof Int16Array !== UDF ? Int16Array : undefined ,
61+ Uint16Array : typeof Uint16Array !== UDF ? Uint16Array : undefined ,
62+ Float16Array : typeof Float16Array !== UDF ? Float16Array : undefined ,
6263
63- Int32Array : ! isUndefined ( Int32Array ) ? Int32Array : undefined ,
64- Uint32Array : ! isUndefined ( Uint32Array ) ? Uint32Array : undefined ,
65- Float32Array : ! isUndefined ( Float32Array ) ? Float32Array : undefined ,
64+ Int32Array : typeof Int32Array !== UDF ? Int32Array : undefined ,
65+ Uint32Array : typeof Uint32Array !== UDF ? Uint32Array : undefined ,
66+ Float32Array : typeof Float32Array !== UDF ? Float32Array : undefined ,
6667
67- Float64Array : ! isUndefined ( Float64Array ) ? Float64Array : undefined ,
68+ Float64Array : typeof Float64Array !== UDF ? Float64Array : undefined ,
6869
69- BigInt64Array : ! isUndefined ( BigInt64Array ) ? BigInt64Array : undefined ,
70- BigUint64Array : ! isUndefined ( BigUint64Array ) ? BigUint64Array : undefined ,
70+ BigInt64Array : typeof BigInt64Array !== UDF ? BigInt64Array : undefined ,
71+ BigUint64Array : typeof BigUint64Array !== UDF ? BigUint64Array : undefined ,
7172}
7273
7374export const toHex = ( value : Uint8Array ) : string => {
0 commit comments