import { Files } from '../models/global' ; export function splitUrl ( url , options ) { let urlNew = url ; const paramsArray = [ ] ; Object . keys ( options ) . forEach ( ( key ) => paramsArray . push ( `${ key }=${ options [ key ] }` ) ) ; if ( Object . keys ( options ) . length === 0 ) { return url ; } if ( /\?/ . test ( urlNew ) === false ) { urlNew = `${ urlNew }?${ paramsArray . join ( '&' ) }` ; } else { urlNew += `&${ paramsArray . join ( '&' ) }` ; } return urlNew ; } export function nameSort ( data = [ ] , resule = [ ] ) { let dirs = [ ] ; let files = [ ] ; data . forEach ( ( item ) => { if ( item . type === 'directory' ) { dirs . push ( item ) ; } else if ( item . type === 'file' ) { files . push ( item ) ; } } ) ; dirs = dirs . sort ( ( a , b ) => { return a . path . replace ( /^\// , '' ) . localeCompare ( b . path . replace ( /^\// , '' ) ) ; } ) ; files = files . sort ( ( a , b ) => { return a . path . replace ( /^\// , '' ) . localeCompare ( b . path . replace ( /^\// , '' ) ) ; } ) ; return [ ... dirs , ... files ] ; } export function dataFilesSort ( files = [ ] , resule = [ ] ) { resule = nameSort ( files ) ; resule = resule . map < Files > ( ( file ) => { if ( file . files ) { file . files = dataFilesSort ( file . files ) ; } return file ; } ) ; return resule ; }