export function fileToUrl ( filepath , base = null ) { if ( base ) { filepath = filepath . split ( `/${ base }/` ) [ 1 ] ; } return filepath . replace ( / /g , '-' ) . slice ( 0 , - 3 ) . trim ( ) ; } const everythingBeforeTheHash = /(.*)#.*$/ ; const everythingBeforeTheQuery = /(.*)\?.*$/ ; const everythingExceptTheTrailingSlash = /(.*)\/$/ ; function createReplacer ( expr ) { return ( url ) => { if ( ! url ) return url ; return url . replace ( expr , '$1' ) ; } ; } const removeHash = createReplacer ( everythingBeforeTheHash ) ; const removeQuery = createReplacer ( everythingBeforeTheQuery ) ; const removeTrailingSlash = createReplacer ( everythingExceptTheTrailingSlash ) ; /**
 * returns true if @url1 and @url2 go to the same place
 * (after stripping any query, hash, and trailing slash in each)
 */ export function matchActualTarget ( url1 , url2 ) { const formattedUrl1 = removeTrailingSlash ( removeQuery ( removeHash ( url1 ) ) ) ; const formattedUrl2 = removeTrailingSlash ( removeQuery ( removeHash ( url2 ) ) ) ; return formattedUrl1 === formattedUrl2 ; }