summaryrefslogtreecommitdiff
path: root/std/path/posix.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-29 21:20:55 +0100
committerGitHub <noreply@github.com>2020-04-29 16:20:55 -0400
commitb51c863550cb377f6e720bccf4f1485ed8d97222 (patch)
treeb17087c22cecc21d1020c8580be712280aafa9ab /std/path/posix.ts
parent3e6ea6284178df0be4982d9775f47b47b14c6139 (diff)
feat(std/path): Add fromFileUrl() (#4993)
Fix: URL constructor accepts a URL object which is not a base
Diffstat (limited to 'std/path/posix.ts')
-rw-r--r--std/path/posix.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/std/path/posix.ts b/std/path/posix.ts
index ba4cf7499..156aba796 100644
--- a/std/path/posix.ts
+++ b/std/path/posix.ts
@@ -421,3 +421,14 @@ export function parse(path: string): ParsedPath {
return ret;
}
+
+/** Converts a file URL to a path string.
+ *
+ * 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;
+}