export const isClient = typeof window === 'object' ; const checkType = ( typeToCheck ) => Object . prototype . toString . call ( typeToCheck ) ; export const isString = ( varToCheck ) => checkType ( varToCheck ) === '[object String]' ; export const isObj = ( varToCheck ) => checkType ( varToCheck ) === '[object Object]' ; export const isNull = ( varToCheck ) => checkType ( varToCheck ) === '[object Null]' ; export const isFunction = ( varToCheck ) => checkType ( varToCheck ) === '[object Function]' ; export const isUndefined = ( varToCheck ) => checkType ( varToCheck ) === '[object Undefined]' ; export const isNullOrUndefined = ( varToCheck ) => isNull ( varToCheck ) || isUndefined ( varToCheck ) ; let isPatched = false ; export const patchHistoryMethodsOnce = ( ) => { if ( isPatched ) return ; const methods = [ 'pushState' , 'replaceState' ] ; methods . forEach ( method => { const original = ( history as any ) [ method ] ; ( history as any ) [ method ] = function ( state ) { const result = original . apply ( this , arguments ) ; const event = new Event ( method . toLowerCase ( ) ) ; ( event as any ) . state = state ; window . dispatchEvent ( event ) ; return result ; } ; } ) ; isPatched = true ; } ; export const normalizeEntriesData = ( data ) => data . reduce ( ( acc , [ key , val ] ) => { acc [ key ] = val ; return acc ; } , { } as { [ key ] : any ; } ) ; export type SerializerFunction = ( value : any ) => string ; export type DeserializerFunction = ( value : string ) => any ; export const createSerializer = ( serializer ? ) => serializer || JSON . stringify ; export const createDeserializer = ( deserializer ? ) => deserializer || JSON . parse ; const fallbackToString = ( val ) => ( isString ( val ) ? val : String ( val ) ) ; export const trySerialize = ( val , serializer , shouldSerialize ? ) => { if ( ! shouldSerialize ) return fallbackToString ( val ) ; try { return fallbackToString ( serializer ( val ) ) ; } catch ( error ) { return fallbackToString ( val ) ; } } ; export const tryDeserialize = ( val , deserializer , shouldDeserialize ? ) => { if ( ! shouldDeserialize ) return val ; try { return deserializer ( val ) ; } catch ( error ) { return val ; } } ;