umami/lib/url.js

16 lines
356 B
JavaScript
Raw Normal View History

export function removeTrailingSlash(url) {
2020-09-01 05:25:31 +02:00
return url && url.length > 1 && url.endsWith('/') ? url.slice(0, -1) : url;
}
export function removeWWW(url) {
return url && url.length > 1 && url.startsWith('www.') ? url.slice(4) : url;
}
export function getDomainName(str) {
try {
return new URL(str).hostname;
2020-09-01 05:25:31 +02:00
} catch (e) {
return str;
}
}