mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-08 12:36:50 +03:00
feat: Introduce fe modular build system
This commit is contained in:
20
fe-app-podkop/src/validators/validateUrl.ts
Normal file
20
fe-app-podkop/src/validators/validateUrl.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { ValidationResult } from './types.js';
|
||||
|
||||
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' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user