export type ExtendedFunction0 < T > = ( ... args : any [ ] ) => T ; export type ExtendedFunction1 < T , U > = ( arg0 : T ) => U ; export type ExtendedFunction2 < T , U , V > = ( arg0 : T , arg1 : U ) => V ; export type ExtendedFunction3 < T , U , V , W > = ( arg0 : T , arg1 : U , arg2 : V ) => W ; export type ExtendedFunction4 < T , U , V , W , X > = ( arg0 : T , arg1 : U , arg2 : V , arg3 : W ) => X ; export type ExtendedPromise0 < T > = ( ) => Promise < T > ; export type ExtendedPromise1 < T , U > = ( arg0 : T ) => Promise < U > ; export type ExtendedPromise2 < T , U , V > = ( arg0 : T , arg1 : U ) => Promise < V > ; export type ExtendedPromise3 < T , U , V , W > = ( arg0 : T , arg1 : U , arg2 : V ) => Promise < W > ; export type ExtendedPromise4 < T , U , V , W , X > = ( arg0 : T , arg1 : U , arg2 : V , arg3 : W ) => Promise < X > ; export function debounce < T > ( func , wait , immediate ? ) ; export function debounce < T , U > ( func , wait , immediate ? ) ; export function debounce < T , U , V > ( func , wait , immediate ? ) ; export function debounce < T , U , V , W > ( func , wait , immediate ? ) ; export function debounce < T , U , V , W , X > ( func , wait , immediate ? ) ; export function debounce ( func , wait , immediate ? ) { var timeout ; var self = { } ; return function ( ) { var args = arguments ; var later = ( ) => { timeout = null ; if ( ! immediate ) { func . apply ( self , args ) ; } } ; var callNow = immediate && ! timeout ; window . clearTimeout ( timeout ) ; timeout = window . setTimeout ( later , wait ) ; if ( callNow ) { func . apply ( self , args ) ; } } ; } param func param wait param thisArg export function debouncePromise < T > ( func , wait , thisArg ? ) ; export function debouncePromise < T , U > ( func , wait , thisArg ? ) ; export function debouncePromise < T , U , V > ( func , wait , thisArg ? ) ; export function debouncePromise < T , U , V , W > ( func , wait , thisArg ? ) ; export function debouncePromise < T , U , V , W , X > ( func , wait , thisArg ? ) ; export function debouncePromise ( func , wait , thisArg ? ) { var self = thisArg || { } ; var args ; var timeout ; var promise ; var resolveExternal ; return function ( ) { args = arguments ; if ( ! promise ) { promise = new Promise < any > ( function ( resolve ) { resolveExternal = resolve ; timeout = window . setTimeout ( function ( ) { timeout = undefined ; promise = undefined ; resolve ( func . apply ( self , args ) ) ; } , wait ) ; } ) ; } else { if ( timeout ) { window . clearTimeout ( timeout ) ; timeout = window . setTimeout ( function ( ) { timeout = undefined ; promise = undefined ; resolveExternal ( func . apply ( self , args ) ) ; } , wait ) ; } else { throw 'No Promise or Timeout for debouncePromise' ; } } return promise ; } ; } export function branchIn ( value , key , step ? ) { let result = key . split ( '.' ) , stepLength = result . length , currentStep = step || 0 , letCurrentValue = value [ result [ currentStep ] ] ; if ( currentStep !== stepLength - 1 ) { return branchIn ( letCurrentValue , key , currentStep + 1 ) ; } else { return letCurrentValue ; } } export function search ( dataSource , term , keys , fn ? ) { let queryResult = [ ] ; if ( term . length > 0 ) { dataSource . forEach ( function ( item ) { keys . forEach ( ( key ) => { if ( branchIn ( item , key ) ? branchIn ( item , key ) . toString ( ) . toLowerCase ( ) . indexOf ( term . toString ( ) . toLowerCase ( ) ) != - 1 : false ) { if ( ! queryResult . includes ( item ) ) { queryResult . push ( item ) ; } } } ) ; } ) ; } if ( fn ) { return fn ( dataSource , term ) ; } else { return queryResult ; } } export function isType ( value ) { var type ; if ( value instanceof Array ) { type = 'array' ; } else { switch ( typeof value ) { case 'object' : type = 'object' ; break ; case 'string' : type = 'string' ; break ; default : type = 'value' ; break ; } } return type ; } export function getType < T > ( value ) { var type = typeof value ; if ( type === 'object' && value instanceof Array ) { type = 'array' ; } return type ; } export function arraysEqual ( arr1 , arr2 ) { if ( arr1 . length !== arr2 . length ) return false ; for ( var i = arr1 . length ; i -- ; ) { if ( arr1 [ i ] !== arr2 [ i ] ) return false ; } return true ; }