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