mirror of
https://github.com/owncast/owncast.git
synced 2024-11-23 21:28:29 +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;
|
|
}
|