summaryrefslogtreecommitdiff
path: root/std/path/win32.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/path/win32.ts')
-rw-r--r--std/path/win32.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/std/path/win32.ts b/std/path/win32.ts
index 9bba66e2b..2c262b1b6 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -898,3 +898,17 @@ export function parse(path: string): ParsedPath {
return ret;
}
+
+/** Converts a file URL to a path string.
+ *
+ * fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
+ * fromFileUrl("file:///home/foo"); // "\\home\\foo"
+ *
+ * Note that non-file URLs are treated as file URLs and irrelevant components
+ * are ignored.
+ */
+export function fromFileUrl(url: string | URL): string {
+ return new URL(url).pathname
+ .replace(/^\/(?=[A-Za-z]:\/)/, "")
+ .replace(/\//g, "\\");
+}