import ts = require ( "typescript" ) ; export namespace Utils { export function forEach < T , U > ( array , callback ) { if ( array ) { for ( let i = 0 , len = array . length ; i < len ; i ++ ) { let result = callback ( array [ i ] , i ) ; if ( result ) { return result ; } } } return undefined ; } export function contains < T > ( array , value ) { if ( array ) { for ( let v of array ) { if ( v === value ) { return true ; } } } return false ; } let hasOwnProperty = Object . prototype . hasOwnProperty ; export function hasProperty < T > ( map , key ) { return hasOwnProperty . call ( map , key ) ; } export function clone < T > ( object ) { let result = { } ; for ( let id in object ) { result [ id ] = ( < any > object ) [ id ] ; } return < T > result ; } export function map < T , U > ( array , f ) { let result ; if ( array ) { result = [ ] ; for ( let v of array ) { result . push ( f ( v ) ) ; } } return result ; } export function extend < T1 , T2 > ( first , second ) { let sentinal = 1 ; let result = { } ; for ( let id in first ) { ( result as any ) [ id ] = first [ id ] ; } for ( let id in second ) { if ( ! hasProperty ( result , id ) ) { ( result as any ) [ id ] = second [ id ] ; } } return result ; } export function replaceAt ( str , index , character ) { return str . substr ( 0 , index ) + character + str . substr ( index + character . length ) ; } }