UNPKG

vike

Version:

(Replaces Next.js/Nuxt) 🔨 Composable framework to build advanced applications with flexibility and stability.

18 lines (17 loc) • 668 B
export { normalizeUrlArgument }; import { assertUsage } from '../../utils/assert.js'; import { isUrl, isUrlRelative } from '../../utils/parseUrl.js'; import '../assertEnvClient.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; }