export function assert ( input ) { if ( ! input ) { throw new Error ( 'Not a truthy value' ) ; } } export function strcmp ( a , b ) { if ( a < b ) { return - 1 ; } if ( a > b ) { return 1 ; } return 0 ; } export const isChromium = /Chrome/ . test ( navigator . userAgent ) ; export const isChrome = /Chrome/ . test ( navigator . userAgent ) && /Google Inc/ . test ( navigator . vendor ) ; export function shallowEqualsForMap < T1 , T2 > ( map1 , map2 ) { let testVal ; if ( map1 . size !== map2 . size ) { return false ; } for ( const [ key , val ] of map1 ) { testVal = map2 . get ( key ) ; if ( testVal !== val || ( testVal === undefined && ! map2 . has ( key ) ) ) { return false ; } } return true ; } export function diffMap < K , V1 , V2 > ( a , b ) { const diff = new Map < K , V1 > ( a ) ; for ( const elem of b ) { diff . delete ( elem [ 0 ] ) ; } return diff ; } export function diffSet < K > ( a , b ) { const diff = new Set < K > ( a ) ; for ( const elem of b ) { diff . delete ( elem ) ; } return diff ; } export function intersectionMap < K , V1 , V2 > ( a , b ) { const com = new Map < K , V1 > ( ) ; a . forEach ( ( v , k ) => { if ( b . has ( k ) ) { com . set ( k , v ) ; } } ) ; return com ; } export function extract < T > ( properties ) { return function < TActual extends T > ( value ) { const result = { } as T ; for ( const property of Object . keys ( properties ) as ( keyof T ) [ ] ) { result [ property ] = value [ property ] ; } return result ; } ; } export function isSmartphone ( ) { if ( navigator . userAgent . match ( /iPhone|Android.+Mobile/ ) ) { return true ; } return false ; } export function isPortrait ( ) { if ( window . parent . screen . width < window . parent . screen . height ) { return true ; } return false ; } export function isSelfUrl ( url ) { return ( url . host === window . location . host && url . pathname === window . location . pathname ) ; } export function checkImageUrl ( url ) { const img = new Image ( ) ; img . src = url ; const promise = new Promise < string > ( ( resolutionFunc , rejectionFunc ) => { img . onload = ( ) => { resolutionFunc ( url ) ; } ; img . onerror = ( ) => { rejectionFunc ( '' ) ; } ; } ) ; return promise ; }