Files
PathEditor/src/core/validation.ts
T
Serendipity 48129a8908 feat: 重写为 Tauri + React + TypeScript (v4.0)
完全移除旧 C+IUP 代码,改用 Tauri 2.x + React 19 + TypeScript + Rust 技术栈重写。
功能与 v3.1 完全等价:

- React 前端:Tailwind CSS 4、Zustand 状态管理、i18next 国际化
- Rust 后端:winreg 注册表读写、Win32 API FFI 调用
- 核心逻辑:StringList、UndoRedoManager、PathManager、Import/Export
- 深色模式、中英文切换、键盘快捷键、合并预览
- 66 个 Vitest 单元测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 18:33:04 +08:00

36 lines
928 B
TypeScript

/**
* 路径格式验证 — 对应 C 版 import_export.c:is_valid_path_format()
*/
/** 检查路径是否符合 Windows 路径格式 */
export function is_valid_path_format(path: string): boolean {
if (!path || path.trim() === '') return false;
// UNC 路径: \\server\share
if (path.startsWith('\\\\') || path.startsWith('//')) return true;
// 驱动器字母: C:\... 或 C:/
if (/^[a-zA-Z]:[/\\]/.test(path)) return true;
// 环境变量: %VAR%
if (path.includes('%')) return true;
// 包含路径分隔符的相对路径
if (path.includes('/') || path.includes('\\')) return true;
return false;
}
/** 连接 PATH 字符串(用分号) */
export function join_path(paths: string[]): string {
return paths.join(';');
}
/** 分割 PATH 字符串 */
export function split_path(raw: string): string[] {
return raw
.split(';')
.map((s) => s.trim())
.filter((s) => s.length > 0);
}