mirror of
https://github.com/owncast/owncast.git
synced 2024-11-27 17:59:21 +03:00
14 lines
369 B
TypeScript
14 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;
|
|
}
|