firecrawl/apps/api/src/lib/canonical-url.ts
2025-01-03 23:16:33 -03:00

8 lines
244 B
TypeScript

export function normalizeUrl(url: string) {
try {
const hostname = new URL(url).hostname;
return hostname.replace(/^www\./, "");
} catch (error) {
return url.replace(/^https?:\/\//, "").replace(/^www\./, "").split('/')[0];
}
}