This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
share2fedi/src/util.ts

28 lines
585 B
TypeScript
Raw Normal View History

2023-03-17 20:11:18 -05:00
/*!
* © 2023 Nikita Karamov
* Licensed under AGPL v3 or later
*/
/**
* Adds missing "https://" and ending slash to the URL
*
* @param url URL to normalize
* @return normalized URL
*/
export const normalizeURL = (url: string): string => {
if (!(url.startsWith("https://") || url.startsWith("http://"))) {
url = "https://" + url;
}
if (!url.endsWith("/")) {
url += "/";
}
return url;
};
2023-03-17 17:08:15 -05:00
export const extractHost = (url: string): string => {
if (!(url.startsWith("https://") || url.startsWith("http://"))) {
url = "https://" + url;
}
return new URL(url).host;
};