Download packages/app/src/utils/path-key.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 824 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/path-key.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/utils/path-key.ts
-
curl -L -o path-key.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/path-key.ts
824 Bytes
| 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 | |
| } | |