2023-03-14 20:11:11 +02:00
|
|
|
// Copyright (c) 2023 Tudor Stanciu
|
|
|
|
|
2023-02-10 01:27:38 +02:00
|
|
|
const combineUrls = (piece1: string, piece2: string): string => {
|
|
|
|
let baseElement = piece1;
|
|
|
|
if (baseElement.endsWith("/")) baseElement = baseElement.substring(0, baseElement.length - 1);
|
|
|
|
return baseElement + piece2;
|
|
|
|
};
|
|
|
|
|
2023-02-11 17:42:05 +02:00
|
|
|
const isValidURL = (str: string): boolean => {
|
2023-03-17 01:57:24 +02:00
|
|
|
let url;
|
|
|
|
try {
|
|
|
|
url = new URL(str);
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return url.protocol === "http:" || url.protocol === "https:";
|
2023-02-11 17:42:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export { combineUrls, isValidURL };
|