Skip to main content
Home
This release is 35 versions behind 1.1.4 — the latest version of @std/path. Jump to latest
Works with
This package works with Cloudflare Workers, Deno, Browsers
This package works with Cloudflare Workers
This package works with Deno
This package works with Browsers
JSR Score94%
Downloads107,185/wk
Published2 years ago (0.211.0)

Utilities for working with file system paths

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import * as posix from "./posix/mod.ts"; import * as windows from "./windows/mod.ts"; import { assertEquals, assertThrows } from "jsr:@std/assert@^0.211.0"; Deno.test("posix.fromFileUrl()", function () { assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo"); assertEquals(posix.fromFileUrl("file:///"), "/"); assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo"); assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar"); assertEquals(posix.fromFileUrl("file:///%"), "/%"); assertEquals(posix.fromFileUrl("file://localhost/foo"), "/foo"); assertEquals(posix.fromFileUrl("file:///C:"), "/C:"); assertEquals(posix.fromFileUrl("file:///C:/"), "/C:/"); assertEquals(posix.fromFileUrl("file:///C:/Users/"), "/C:/Users/"); assertEquals(posix.fromFileUrl("file:///C:foo/bar"), "/C:foo/bar"); assertThrows( () => posix.fromFileUrl("http://localhost/foo"), TypeError, "Must be a file URL.", ); assertThrows( () => posix.fromFileUrl("abcd://localhost/foo"), TypeError, "Must be a file URL.", ); }); Deno.test("windows.fromFileUrl()", function () { assertEquals(windows.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo"); assertEquals(windows.fromFileUrl("file:///"), "\\"); assertEquals(windows.fromFileUrl("file:///home/foo"), "\\home\\foo"); assertEquals( windows.fromFileUrl("file:///home/foo%20bar"), "\\home\\foo bar", ); assertEquals(windows.fromFileUrl("file:///%"), "\\%"); assertEquals( windows.fromFileUrl("file://127.0.0.1/foo"), "\\\\127.0.0.1\\foo", ); assertEquals(windows.fromFileUrl("file://localhost/foo"), "\\foo"); assertEquals(windows.fromFileUrl("file:///C:"), "C:\\"); assertEquals(windows.fromFileUrl("file:///C:/"), "C:\\"); // Drop the hostname if a drive letter is parsed. assertEquals(windows.fromFileUrl("file://localhost/C:/"), "C:\\"); assertEquals(windows.fromFileUrl("file:///C:/Users/"), "C:\\Users\\"); assertEquals(windows.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar"); assertThrows( () => windows.fromFileUrl("http://localhost/foo"), TypeError, "Must be a file URL.", ); assertThrows( () => windows.fromFileUrl("abcd://localhost/foo"), TypeError, "Must be a file URL.", ); });