/**
 * Control flow functions.
 */ import * as ts from 'typescript' ; export namespace Utils { /**
     * Logical 'any' or 'exists' function.
     */ export function exists < T extends ts . Node > ( list , predicate ) { if ( list != null ) { for ( let i = 0 ; i < list . length ; i ++ ) { const obj = list [ i ] ; if ( predicate ( obj ) ) { return true ; } } } return false ; } /**
     * A contains function.
     */ export function contains < T extends ts . Node > ( list , element ) { return exists ( list , ( item ) : boolean => { return item === element ; } ) ; } /**
     * A removeAll function.
     */ export function removeAll < T extends ts . Node > ( source , elementsToRemove ) { if ( source == null || source . length === 0 ) { return [ ] ; } if ( elementsToRemove == null || elementsToRemove . length === 0 ) { return [ ] . concat ( source ) ; } return source . filter ( ( sourceElement ) : boolean => { return ! contains ( elementsToRemove , sourceElement ) ; } ) ; } /**
     * A remove() function.
     */ export function remove < T extends ts . Node > ( source , elementToRemove ) { return removeAll ( source , < any > [ elementToRemove ] ) ; } export function trimTo ( source , maxLength ) { if ( source == null ) { return '' ; } if ( source . length <= maxLength ) { return source ; } return source . substr ( 0 , maxLength - 2 ) + '...' ; } /**
     * Check whether two arrays are equal.
     */ export function arraysShallowEqual ( arr1 , arr2 ) { if ( arr1 . length !== arr2 . length ) { return false ; } for ( let i = arr1 . length ; i -- ; ) { if ( arr1 [ i ] !== arr2 [ i ] ) { return false ; } } return true ; } }