@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/urls",
3
- "version": "2.5.1",
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
- "scripts": {
28
- "test": "node --conditions=development ./scripts/test.mjs"
29
- },
27
+ "sideEffects": false,
30
28
  "dependencies": {
31
- "@jsenv/humanize": "1.2.7"
29
+ "@jsenv/humanize": "1.2.8"
32
30
  }
33
31
  }
@@ -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
- let urlString = String(url);
5
- if (urlString[urlString.length - 1] === "/") {
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
- urlString = urlString.slice(0, -1);
17
+ return fileSystemPath.slice(0, -1);
9
18
  }
10
- const fileSystemPath = fileURLToPath(urlString);
11
19
  return fileSystemPath;
12
20
  };
package/src/url_utils.js CHANGED
@@ -18,7 +18,7 @@ export const isValidUrl = (url) => {
18
18
  // eslint-disable-next-line no-new
19
19
  new URL(url);
20
20
  return true;
21
- } catch (e) {
21
+ } catch {
22
22
  return false;
23
23
  }
24
24
  };