Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233/** Parse the single supported custom-domain form into its canonical origin. */export function customDomainOrigin(value: unknown): string | null { if (typeof value !== "string" || value.length > 253) return null; try { const url = new URL(value); const hostname = url.hostname; if ( url.protocol !== "https:" || url.origin !== value || url.port || url.username || url.password || url.pathname !== "/" || url.search || url.hash || hostname !== hostname.toLowerCase() || hostname.endsWith(".workers.dev") || hostname === "workers.dev" || hostname.includes("*") || !hostname.includes(".") || /^\d+(?:\.\d+){3}$/.test(hostname) || hostname.includes(":") || !hostname .split(".") .every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label)) ) return null; return url.origin; } catch { return null; }}