silverwolf-x/project / packages /next /src /shared /lib /normalized-asset-prefix.ts
silverwolf-x's picture
download
raw
645 Bytes
export function normalizedAssetPrefix(assetPrefix: string | undefined): string {
// remove all leading slashes and trailing slashes
const escapedAssetPrefix = assetPrefix?.replace(/^\/+|\/+$/g, '') || false
// if an assetPrefix was '/', we return empty string
// because it could be an unnecessary trailing slash
if (!escapedAssetPrefix) {
return ''
}
if (URL.canParse(escapedAssetPrefix)) {
const url = new URL(escapedAssetPrefix).toString()
return url.endsWith('/') ? url.slice(0, -1) : url
}
// assuming assetPrefix here is a pathname-style,
// restore the leading slash
return `/${escapedAssetPrefix}`
}

Xet Storage Details

Size:
645 Bytes
·
Xet hash:
5d8d8b620106ac2cbfa1e2c6f67f2033fa7d11d7b88c5d091efb51022ad9b9d2

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