format type Assert = ( condition : unknown ) => asserts condition ; export const assert = ( condition ) => { if ( ! condition ) { throw new Error ( ) ; } } ; export const safeJSONStringify = ( data ) : string => { try { return JSON . stringify ( data ) ; } catch { return 'Unable to serialize' ; } } ; export const isPromise = ( val ) : val is Promise < unknown > => typeof val === 'object' && val !== null && typeof ( val as Promise < unknown > ) . then === 'function' && typeof ( val as Promise < unknown > ) . catch === 'function' ; type OS = 'iOS' | 'Android' | 'Metro' | 'Windows' | 'MacOS' | 'Browser' | 'Linux' ; const detectDeviceType = ( ) => typeof process === 'object' && typeof process . versions === 'object' && typeof process . versions . node !== 'undefined' ? 'Node.js' : 'Browser' ; export const detectOS = ( ) : OS => { if ( detectDeviceType ( ) === 'Browser' ) { return 'Browser' ; } switch ( require ( 'os' ) . type ( ) ) { case 'Linux' : return 'Linux' ; case 'Darwin' : return 'MacOS' ; default : return 'Windows' ; } } ; export const detectDevice = ( ) : string => { if ( detectDeviceType ( ) === 'Browser' ) { return window . navigator . userAgent ; } return require ( 'os' ) . release ( ) ; } ; export const awaitTimeout = ( timeout ) => new Promise ( resolve => setTimeout ) ;