import Kernel from './Kernel' ; type ArrayVoidCallback = ( value : any , index : number , arr : Array < any > ) => void ; type ArrayBooleanCallback = ( value : any , index : number , arr : any [ ] ) => boolean ; type ArrayAnyCallback = ( value : any , index : number , arr : any [ ] ) => any ; type TopicCallback = ( data : any ) => void ; const topic = { } ; export default class Utils { static isNumber ( v ) { return typeof v === "number" ; } static isInteger ( v ) { var isInt = false ; var isNum = this . isNumber ( v ) ; if ( isNum ) { var numFloat = parseFloat ( v ) ; var numInt = parseInt ( v ) ; if ( numFloat === numInt ) { isInt = true ; } else { isInt = false ; } } else { isInt = false ; } return isInt ; } static isPositive ( v ) { return v > 0 ; } static isNegative ( v ) { return v < 0 ; } static isNonNegative ( v ) { return v >= 0 ; } static isNonPositive ( v ) { return v <= 0 ; } static isPositiveInteger ( v ) { return this . isPositive ( v ) && this . isInteger ( v ) ; } static isNonNegativeInteger ( v ) { return this . isNonNegative ( v ) && this . isInteger ( v ) ; } static isArray ( v ) { return Object . prototype . toString . call ( v ) === '[object Array]' ; } static isFunction ( v ) { return typeof v === 'function' ; } static forEach ( arr , func ) { return this . isFunction ( ( < any > arr ) . forEach ) ? ( < any > arr ) . forEach ( func ) : Array . prototype . forEach . call ( arr , func ) ; } static filter ( arr , func ) { return this . isFunction ( ( < any > arr ) . filter ) ? ( < any > arr ) . filter ( func ) : Array . prototype . filter . call ( arr , func ) ; } static map ( arr , func ) { return this . isFunction ( ( < any > arr ) . map ) ? ( < any > arr ) . map ( func ) : Array . prototype . map . call ( arr , func ) ; } static some ( arr , func ) { return this . isFunction ( ( < any > arr ) . some ) ? ( < any > arr ) . some ( func ) : Array . prototype . some . call ( arr , func ) ; } static every ( arr , func ) { return this . isFunction ( ( < any > arr ) . every ) ? ( < any > arr ) . every ( func ) : Array . prototype . every . call ( arr , func ) ; } static filterRepeatArray ( arr ) { var cloneArray = arr . map ( function ( item ) { return item ; } ) ; var simplifyArray = [ ] ; while ( cloneArray . length > 0 ) { var e = cloneArray [ 0 ] ; var exist = simplifyArray . some ( function ( item ) { return e . equals ( item ) ; } ) ; if ( ! exist ) { simplifyArray . push ( e ) ; } cloneArray . splice ( 0 , 1 ) ; } return simplifyArray ; } static isMobile ( ) { return ! ! window . navigator . userAgent . match ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone|IEMobile|Opera Mini/i ) ; } static isWindows ( ) { const platform = window . navigator . platform ; return platform . toLowerCase ( ) . indexOf ( 'win' ) === 0 ; } static wrapUrlWithProxy ( url ) { if ( Kernel . proxy ) { return Kernel . proxy + "?" + url ; } return url ; } static subscribe ( topicName , callback ) { if ( ! topic [ topicName ] ) { topic [ topicName ] = [ ] ; } topic [ topicName ] . push ( callback ) ; } static publish ( topicName , data ? ) { var callbacks = topic [ topicName ] ; if ( callbacks && callbacks . length > 0 ) { callbacks . forEach ( function ( callback ) { callback ( data ) ; } ) ; } } } ;