Files
firecrawl/apps/api/src/lib/canonical-url.ts
T

8 lines
244 B
TypeScript
Raw Normal View History

2025-01-03 22:50:53 -03:00
export function normalizeUrl(url: string) {
2025-01-03 23:16:33 -03:00
try {
const hostname = new URL(url).hostname;
return hostname.replace(/^www\./, "");
} catch (error) {
return url.replace(/^https?:\/\//, "").replace(/^www\./, "").split('/')[0];
2025-01-03 22:50:53 -03:00
}
}