(urlOrPath: string)
| 213 | export function fileUrlToAbsolutePath(urlOrPath: FileUrl): string; |
| 214 | export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined; |
| 215 | export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined { |
| 216 | if (!isFileUrl(urlOrPath)) { |
| 217 | return undefined; |
| 218 | } |
| 219 | |
| 220 | urlOrPath = urlOrPath.replace('file:///', ''); |
| 221 | urlOrPath = decodeURIComponent(urlOrPath); |
| 222 | if (urlOrPath[0] !== '/' && !urlOrPath.match(/^[A-Za-z]:/)) { |
| 223 | // If it has a : before the first /, assume it's a windows path or url. |
| 224 | // Ensure unix-style path starts with /, it can be removed when file:/// was stripped. |
| 225 | // Don't add if the url still has a protocol |
| 226 | urlOrPath = '/' + urlOrPath; |
| 227 | } |
| 228 | |
| 229 | return fixDriveLetterAndSlashes(urlOrPath); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Converts a file URL to a windows network path, if possible. |
no test coverage detected