import { convertToParamMap , ParamMap , Params } from '@angular/router' ; import { isObservable , Observable , of } from 'rxjs' ; import { Comparator } from './types' ; internal export const LOOSE_IDENTITY_COMPARATOR = < T > ( a , b ) => a == b ; internal export const NOP = ( ) => { } ; internal export function isMissing ( obj ) { return obj === undefined || obj === null ; } internal export function undefinedToNull < T > ( obj ) { if ( obj === undefined ) { return null ; } return obj ; } internal export function isPresent < T > ( obj ) { return ! isMissing ( obj ) ; } internal export function isFunction ( obj ) { return isPresent ( obj ) && typeof obj === 'function' ; } internal export function wrapTryCatch < T extends Function > ( fn , msg ) { return < any > function ( this ) { try { return fn . apply ( this , arguments ) ; } catch ( err ) { console . error ( msg , err ) ; return null ; } } ; } internal export function areEqualUsing < T > ( first , second , comparator ) { const comparison = comparator ( first , second ) ; if ( typeof comparison === 'boolean' ) { return comparison ; } return comparison === 0 ; } internal export function filterParamMap ( paramMap , keys ) { const params = { } ; keys . filter ( key => paramMap . keys . includes ( key ) ) . forEach ( key => params [ key ] = paramMap . getAll ( key ) ) ; return convertToParamMap ( params ) ; } internal export function compareParamMaps ( first , second ) { if ( ( first && ! second ) || ( second && ! first ) ) { return false ; } if ( ! compareStringArraysUnordered ( first . keys , second . keys ) ) { return false ; } return first . keys . every ( key => compareStringArraysUnordered ( first . getAll ( key ) , second . getAll ( key ) ) ) ; } internal export function compareStringArraysUnordered ( first , second ) { if ( ! first && ! second ) { return true ; } if ( ( first && ! second ) || ( second && ! first ) ) { return false ; } if ( first . length !== second . length ) { return false ; } const sortedFirst = first . sort ( ) ; const sortedSecond = second . sort ( ) ; return sortedFirst . every ( ( firstKey , index ) => firstKey === sortedSecond [ index ] ) ; } internal export function wrapIntoObservable < T > ( input ) { if ( isObservable ( input ) ) { return input ; } return of ( input ) ; }