UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

16 lines (15 loc) 583 B
export { normalizeUrlArgument }; import { assertUsage, isUrl, isUrlRelative } from './utils.js'; function normalizeUrlArgument(url, fnName) { // Succinct error message to save client-side KBs const errMsg = `URL ${url} passed to ${fnName}() is invalid`; assertUsage(isUrl(url), errMsg); if (url.startsWith(location.origin)) { // Use normalizeClientSideUrl() instead? url = url.slice(location.origin.length); } assertUsage(url.startsWith('/') || isUrlRelative(url), // `errMsg` used the original `url` value errMsg); return url; }