mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
21 lines
536 B
TypeScript
21 lines
536 B
TypeScript
import { ValidationResult } from './types';
|
|
|
|
export function validateUrl(
|
|
url: string,
|
|
protocols: string[] = ['http:', 'https:'],
|
|
): ValidationResult {
|
|
try {
|
|
const parsedUrl = new URL(url);
|
|
|
|
if (!protocols.includes(parsedUrl.protocol)) {
|
|
return {
|
|
valid: false,
|
|
message: `${_('URL must use one of the following protocols:')} ${protocols.join(', ')}`,
|
|
};
|
|
}
|
|
return { valid: true, message: _('Valid') };
|
|
} catch (_e) {
|
|
return { valid: false, message: _('Invalid URL format') };
|
|
}
|
|
}
|