UNPKG

vike

Version:

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

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