( function ( ) { class Format { param time param type returns static timeFormat ( time = new Date ( ) . getTime ( ) , type ? ) { let date = new Date ( time ) , Y = date . getFullYear ( ) + '-' , M = ( date . getMonth ( ) + 1 < 10 ? '0' + ( date . getMonth ( ) + 1 ) : date . getMonth ( ) + 1 ) + '-' , D = ( date . getDate ( ) < 10 ? '0' + ( date . getDate ( ) ) : date . getDate ( ) ) + ' ' , h = ( date . getHours ( ) < 10 ? '0' + date . getHours ( ) : date . getHours ( ) ) + ':' , m = ( date . getMinutes ( ) < 10 ? '0' + date . getMinutes ( ) : date . getMinutes ( ) ) + ':' , s = ( date . getSeconds ( ) < 10 ? '0' + date . getSeconds ( ) : date . getSeconds ( ) ) ; return type ? Y + M + D + h + m + s : h + m + s ; } param size returns static sizeFormat ( size = 0 ) { let unit = [ "B" , "K" , "M" , "G" ] , i = unit . length - 1 , dex = 1024 ** i , vor = 1000 ** i ; while ( dex > 1 ) { if ( size >= vor ) { size = Number ( ( size / dex ) . toFixed ( 2 ) ) ; break ; } dex = dex / 1024 ; vor = vor / 1000 ; i -- ; } return size ? size + unit [ i ] : "N/A" ; } param num returns static unitFormat ( num = 0 ) { num = 1 * num || 0 ; let unit = [ "" , "万" , "亿" ] , i = unit . length - 1 , dex = 10000 ** i ; while ( dex > 1 ) { if ( num >= dex ) { num = Number ( ( num / dex ) . toFixed ( 1 ) ) ; break ; } dex = dex / 10000 ; i -- ; } return num + unit [ i ] ; } param arr returns static bubbleSort ( arr ) { let temp ; for ( let i = 0 ; i < arr . length - 1 ; i ++ ) { let bool = true ; for ( let j = 0 ; j < arr . length - 1 - i ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; bool = false ; } } if ( bool ) break ; } return arr ; } param arr param num returns static randomArray ( arr , num ) { let out = [ ] ; num = num || 1 ; num = num < arr . length ? num : arr . length ; while ( out . length < num ) { var temp = ( Math . random ( ) * arr . length ) >> 0 ; out . push ( arr . splice ( temp , 1 ) [ 0 ] ) ; } return out ; } param url param obj returns static objUrl ( url , obj ) { let data = this . urlObj ( url ) ; obj = typeof obj === "object" ? obj : { } ; data = Object . assign ( data , obj ) ; let arr = [ ] , i = 0 ; for ( let key in data ) { if ( data [ key ] !== undefined && data [ key ] !== null ) { arr [ i ] = key + "=" + data [ key ] ; i ++ ; } } if ( url ) url = url + "?" + arr . join ( "&" ) ; else url = arr . join ( "&" ) ; if ( url . charAt ( url . length - 1 ) == "?" ) url = url . split ( "?" ) [ 0 ] ; return url ; } param url returns static urlObj ( url = "" ) { let arr = url . split ( '?' ) [ 1 ] ? url . split ( '?' ) [ 1 ] . split ( '&' ) : [ ] ; return arr . reduce ( ( o , d ) => { if ( d . includes ( "#" ) ) d = d . split ( "#" ) [ 0 ] ; if ( d ) o [ d . split ( '=' ) [ 0 ] ] = d . split ( '=' ) [ 1 ] || "" ; return o ; } , { } ) ; } } Reflect . ownKeys ( Format ) . forEach ( d => typeof Format [ d ] == "function" && Reflect . set ( API , d , Format [ d ] ) ) ; } ) ( ) ; declare namespace API { param time param type returns function timeFormat ( time ? , type ? ) ; param size returns function sizeFormat ( size ? ) ; param num returns function unitFormat ( num ? ) ; param arr returns function bubbleSort ( arr ) ; param arr param num returns function randomArray ( arr , num ) ; param url param obj returns function objUrl ( url , obj ) ; param url returns function urlObj ( url ? ) ; }