export const getName = ( list ) : string => { let str = '' ; list . map ( ( item , index ) => { str += index === 0 ? item . name : '/' + item . name ; return item ; } ) ; return str ; } ; interface IRankItem { tracks : any [ ] ; } export const filterIndex = ( rankList ) : number => { for ( let i = 0 ; i < rankList . length - 1 ; i ++ ) { if ( rankList [ i ] . tracks . length && ! rankList [ i + 1 ] . tracks . length ) { return i + 1 ; } } return 0 ; } ; let elementStyle = document . createElement ( 'div' ) . style ; let vendor = ( ( ) => { let transformNames = { webkit : 'webkitTransform' , Moz : 'MozTransform' , O : 'OTransform' , ms : 'msTransform' , standard : 'Transform' , } ; for ( let key in transformNames ) { if ( elementStyle [ transformNames [ key ] ] !== undefined ) { return key ; } } return '' ; } ) ( ) ; export function prefixStyle ( style ) { if ( ! vendor ) { return '' ; } if ( vendor === 'standard' ) { return style ; } return vendor + style . charAt ( 0 ) . toUpperCase ( ) + style . substr ( 1 ) ; } export const isEmptyObject = ( obj ) => Object . keys ( obj ) . length === 0 ; function getRandomInt ( min , max ) { return Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ; } export function shuffle ( arr ) { let new_arr = [ ] ; arr . forEach ( item => { new_arr . push ( item ) ; } ) ; for ( let i = 0 ; i < new_arr . length ; i ++ ) { let j = getRandomInt ( 0 , i ) ; let t = new_arr [ i ] ; new_arr [ i ] = new_arr [ j ] ; new_arr [ j ] = t ; } return new_arr ; } export const findIndex = ( song , list ) => { return list . findIndex ( ( item ) => { return song . id === item . id ; } ) ; } ; export const formatPlayTime = ( interval ) => { interval = interval | 0 ; const minute = ( interval / 60 ) | 0 ; const second = ( interval % 60 ) . toString ( ) . padStart ( 2 , '0' ) ; return `${ minute }:${ second }` ; } ; export const trimPhone = ( val ) => val . replace ( /(^\s+)|(\s+$)|\s+/g , "" ) ;