(filepath: string)
| 81 | } |
| 82 | |
| 83 | export function encodeFilePath(filepath: string): string { |
| 84 | // Normalize Windows paths: convert backslashes to forward slashes |
| 85 | let normalized = filepath.replace(/\\/g, "/") |
| 86 | |
| 87 | // Handle Windows absolute paths (D:/path -> /D:/path for proper file:// URLs) |
| 88 | if (/^[A-Za-z]:/.test(normalized)) { |
| 89 | normalized = "/" + normalized |
| 90 | } |
| 91 | |
| 92 | // Encode each path segment (preserving forward slashes as path separators) |
| 93 | // Keep the colon in Windows drive letters (`/C:/...`) so downstream file URL parsers |
| 94 | // can reliably detect drives. |
| 95 | return normalized |
| 96 | .split("/") |
| 97 | .map((segment, index) => { |
| 98 | if (index === 1 && /^[A-Za-z]:$/.test(segment)) return segment |
| 99 | return encodeURIComponent(segment) |
| 100 | }) |
| 101 | .join("/") |
| 102 | } |
| 103 | |
| 104 | export function createPathHelpers(scope: () => string) { |
| 105 | const normalize = (input: string) => { |
no outgoing calls
no test coverage detected