import Url from 'url' ; param url export function backspaceUrlParse ( url ) { if ( url ) { const { protocol , slashes , host , pathname , search , hash } = Url . parse ( url ) ; if ( hash ) { return [ protocol , slashes ? '//' : '' , host , pathname , search ] . join ( '' ) ; } if ( search ) { const searchParameters = new URLSearchParams ( search ) ; const searchParametersArray = [ ] ; for ( const [ key , value ] of searchParameters . entries ( ) ) { searchParametersArray . push ( `${ key }=${ value }` ) ; } if ( searchParametersArray . length > 1 ) { const minusLast = searchParametersArray . slice ( 0 , - 1 ) ; const searchParametersString = minusLast . join ( '&' ) ; return [ protocol , slashes ? '//' : '' , host , pathname , '?' , searchParametersString , ] . join ( '' ) ; } return `${ protocol }${ slashes ? '//' : '' }${ host }${ pathname }` ; } if ( pathname && pathname !== '/' ) { const pathnameArray = pathname . split ( '/' ) . filter ( Boolean ) ; if ( pathnameArray . length > 1 ) { const minusLast = pathnameArray . slice ( 0 , - 1 ) ; const pathnameString = minusLast . join ( '/' ) ; return `${ protocol }${ slashes ? '//' : '' }${ host }/${ pathnameString }/` ; } return `${ protocol }${ slashes ? '//' : '' }${ host }/` ; } } return '' ; }