Files
aiops/frontend/src/utils/validate.ts
T
Logan.Li f45e203e21 refactor(frontend): P1-P2 架构统一 — utils/hooks/api 模块化
P1:
- utils/storage.ts、theme.ts、validate.ts + index 统一出口
- request/store/useTheme 接入 storage;清零 confirm/alert
- PipelineManager、TerminalAuditTab 拆分子模块(<700行红线)

P2:
- api/monitor、api/deploy 子目录化
- hooks/api 扩展:servers/pipelines/alerts/audit/sessionCommands
- PipelineManager、AuditOperationsTab 接入 TanStack Query
2026-06-26 00:18:14 +08:00

42 lines
1.1 KiB
TypeScript

// 通用表单校验 // Logan.Li
export function isNotEmpty(value: unknown): boolean {
if (value === null || value === undefined) return false;
return String(value).trim().length > 0;
}
export function isValidPort(port: unknown): boolean {
const n = Number(port);
return Number.isInteger(n) && n > 0 && n <= 65535;
}
export function isValidIPv4(ip: string): boolean {
const parts = ip.trim().split('.');
if (parts.length !== 4) return false;
return parts.every((p) => {
const n = Number(p);
return Number.isInteger(n) && n >= 0 && n <= 255 && String(n) === p;
});
}
export function isValidHostname(host: string): boolean {
const h = host.trim();
if (!h) return false;
return /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(h);
}
export function isValidUrl(url: string): boolean {
try {
const u = new URL(url);
return u.protocol === 'http:' || u.protocol === 'https:';
} catch {
return false;
}
}
export function parsePortList(text: string): number[] {
return text
.split(',')
.map((s) => parseInt(s.trim(), 10))
.filter((n) => isValidPort(n));
}