Provides domain normalization and Zod schemas for domain-related API requests.
// Source: https://github.com/every-app/open-seo | License: MIT | Copyright 2026 Ben Senescu
// Provided via justclaw.it.com; keep this notice with the code.
import { z } from "zod";
import { isValidDomainHost, researchScopeSchema } from "@/shared/researchScope";
/**
* Extract and validate a bare hostname from user input that may be a full URL.
* Strips protocol, www prefix, path, query-string, and hash.
*/
export function normalizeDomain(input: string): string {
let d = input.trim().toLowerCase();
// Ensure URL() can parse the input by adding a protocol if missing
if (!/^[a-z]+:\/\//.test(d)) d = `https://${d}`;
const { hostname } = new URL(d); // throws on truly invalid input
return hostname.replace(/^www\./, "");
}
/** Zod field: accepts a bare domain or full URL, outputs
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key