/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/utils/path-key.ts
24 строки
824 B
Luke Parker
fix(desktop): Path mismatches cause sessions missing + strong ID + existing data fix (#25013)
30 апр 2026, 01:39
Не верифицирован
30 апр 2026, 01:39
d7b7be1
Код
Авторство
О чём код?
export type PathKey = string & { _brand: "PathKey" } const isDrive = (value: string) => { if (value.length !== 2) return false const code = value.charCodeAt(0) return value[1] === ":" && ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) } const trimTrailingSlashes = (value: string) => { for (let i = value.length - 1; i >= 0; i--) { if (value[i] !== "/") return value.slice(0, i + 1) } return "" } const isWindowsPath = (value: string) => value[1] === ":" || value.startsWith("\\\\") export const pathKey = (path: string) => { const value = isWindowsPath(path) ? path.replaceAll("\\", "/") : path const trimmed = trimTrailingSlashes(value) if (!trimmed && value.startsWith("/")) return "/" as PathKey if (isDrive(trimmed)) return `${trimmed}/` as PathKey return trimmed as PathKey }