@jsenv/urls 2.5.1 → 2.5.3
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 +3 -5
- package/src/url_to_basename.js +0 -1
- package/src/url_to_filesystem_path.js +12 -4
- package/src/url_utils.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/urls",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"/src/"
|
|
26
26
|
],
|
|
27
|
-
"
|
|
28
|
-
"test": "node --conditions=development ./scripts/test.mjs"
|
|
29
|
-
},
|
|
27
|
+
"sideEffects": false,
|
|
30
28
|
"dependencies": {
|
|
31
|
-
"@jsenv/humanize": "1.2.
|
|
29
|
+
"@jsenv/humanize": "1.2.8"
|
|
32
30
|
}
|
|
33
31
|
}
|
package/src/url_to_basename.js
CHANGED
|
@@ -7,7 +7,6 @@ export const urlToBasename = (url, removeAllExtensions) => {
|
|
|
7
7
|
return basename;
|
|
8
8
|
}
|
|
9
9
|
let currentBasename = basename;
|
|
10
|
-
// eslint-disable-next-line no-constant-condition
|
|
11
10
|
while (true) {
|
|
12
11
|
const nextBasename = filenameToBasename(basename);
|
|
13
12
|
if (nextBasename === currentBasename) {
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
|
|
3
3
|
export const urlToFileSystemPath = (url) => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const urlObject = new URL(url);
|
|
5
|
+
let urlString;
|
|
6
|
+
if (urlObject.hash) {
|
|
7
|
+
const origin =
|
|
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;
|
|
12
|
+
}
|
|
13
|
+
const fileSystemPath = fileURLToPath(urlString);
|
|
14
|
+
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
|
|
6
15
|
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|
|
7
16
|
// the trailing slash on linux but does not on windows
|
|
8
|
-
|
|
17
|
+
return fileSystemPath.slice(0, -1);
|
|
9
18
|
}
|
|
10
|
-
const fileSystemPath = fileURLToPath(urlString);
|
|
11
19
|
return fileSystemPath;
|
|
12
20
|
};
|