tuitio-client/src/utils.ts

20 lines
495 B
TypeScript

// Copyright (c) 2023 Tudor Stanciu
const combineUrls = (piece1: string, piece2: string): string => {
let baseElement = piece1;
if (baseElement.endsWith("/")) baseElement = baseElement.substring(0, baseElement.length - 1);
return baseElement + piece2;
};
const isValidURL = (str: string): boolean => {
let url;
try {
url = new URL(str);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
};
export { combineUrls, isValidURL };