owncast/web/utils/urls.ts
2021-02-16 11:41:24 -08:00

15 lines
369 B
TypeScript

export default function isValidUrl(url: string): boolean {
const validProtocols = ['http:', 'https:'];
try {
const validationObject = new URL(url);
if (validationObject.protocol === '' || validationObject.hostname === '' || !validProtocols.includes(validationObject.protocol)) {
return false;
}
} catch(e) {
return false;
}
return true;
}