owncast/web/utils/urls.ts

15 lines
369 B
TypeScript
Raw Normal View History

2021-02-16 20:41:24 +01:00
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)) {
2021-02-16 20:41:24 +01:00
return false;
}
} catch(e) {
return false;
}
2021-02-16 20:41:24 +01:00
return true;
}