@jsenv/urls 2.5.3 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,14 +2,20 @@ import { fileURLToPath } from "node:url";
|
|
|
2
2
|
|
|
3
3
|
export const urlToFileSystemPath = (url) => {
|
|
4
4
|
const urlObject = new URL(url);
|
|
5
|
-
let
|
|
6
|
-
if (urlObject.
|
|
7
|
-
|
|
8
|
-
urlObject.protocol === "file:" ? "file://" : urlObject.origin;
|
|
9
|
-
urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`;
|
|
10
|
-
} else {
|
|
11
|
-
urlString = urlObject.href;
|
|
5
|
+
let { origin, pathname, hash } = urlObject;
|
|
6
|
+
if (urlObject.protocol === "file:") {
|
|
7
|
+
origin = "file://";
|
|
12
8
|
}
|
|
9
|
+
pathname = pathname
|
|
10
|
+
.split("/")
|
|
11
|
+
.map((part) => {
|
|
12
|
+
return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
|
|
13
|
+
})
|
|
14
|
+
.join("/");
|
|
15
|
+
if (hash) {
|
|
16
|
+
pathname += `%23${encodeURIComponent(hash.slice(1))}`;
|
|
17
|
+
}
|
|
18
|
+
const urlString = `${origin}${pathname}`;
|
|
13
19
|
const fileSystemPath = fileURLToPath(urlString);
|
|
14
20
|
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
|
|
15
21
|
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|