Files
ruvnet--RuView/ui/mobile/src/utils/urlValidator.ts
T
ruv fdc7142dfa feat: Implement RSSI service for iOS and Web platforms
- Added IosRssiService to handle synthetic RSSI data for iOS.
- Created WebRssiService to simulate RSSI scanning on the web.
- Defined shared types for WifiNetwork and RssiService in rssi.service.ts.
- Introduced simulation service to generate synthetic sensing data.
- Implemented WebSocket service for real-time data handling with reconnection logic.
- Established Zustand stores for managing application state related to MAT and pose data.
- Developed theme context and utility functions for consistent styling and formatting.
- Added type definitions for various application entities including API responses and sensing data.
- Created utility functions for color mapping and URL validation.
- Configured TypeScript settings for the mobile application.
2026-03-02 10:30:33 -05:00

26 lines
722 B
TypeScript

const ALLOWED_PROTOCOLS = new Set(['http:', 'https:', 'ws:', 'wss:']);
export interface UrlValidationResult {
valid: boolean;
error?: string;
}
export function validateServerUrl(url: string): UrlValidationResult {
if (typeof url !== 'string' || !url.trim()) {
return { valid: false, error: 'URL must be a non-empty string.' };
}
try {
const parsed = new URL(url);
if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) {
return { valid: false, error: 'URL must use http, https, ws, or wss.' };
}
if (!parsed.host) {
return { valid: false, error: 'URL must include a host.' };
}
return { valid: true };
} catch {
return { valid: false, error: 'Invalid URL format.' };
}
}