silverwolf-x/project / packages /next /src /client /assign-location.ts
silverwolf-x's picture
download
raw
959 Bytes
import { addBasePath } from './add-base-path'
/**
* Function to correctly assign location to URL
*
* The method will add basePath, and will also correctly add location (including if it is a relative path)
* @param location Location that should be added to the url
* @param url Base URL to which the location should be assigned
*/
export function assignLocation(location: string, url: URL): URL {
if (location.startsWith('.')) {
const urlBase = url.origin + url.pathname
return new URL(
// In order for a relative path to be added to the current url correctly, the current url must end with a slash
// new URL('./relative', 'https://example.com/subdir').href -> 'https://example.com/relative'
// new URL('./relative', 'https://example.com/subdir/').href -> 'https://example.com/subdir/relative'
(urlBase.endsWith('/') ? urlBase : urlBase + '/') + location
)
}
return new URL(addBasePath(location), url.href)
}

Xet Storage Details

Size:
959 Bytes
·
Xet hash:
86eb61e4bbfe8cb608def63eb7aad284cda28e346f2ebff6f4d0a8c549e942d5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.