@jsenv/urls
Advanced tools
Comparing version 2.5.2 to 2.5.3
{ | ||
"name": "@jsenv/urls", | ||
"version": "2.5.2", | ||
"version": "2.5.3", | ||
"license": "MIT", | ||
@@ -28,5 +28,2 @@ "repository": { | ||
"sideEffects": false, | ||
"scripts": { | ||
"test": "node --conditions=development ./scripts/test.mjs" | ||
}, | ||
"dependencies": { | ||
@@ -33,0 +30,0 @@ "@jsenv/humanize": "1.2.8" |
@@ -10,3 +10,2 @@ import { urlToFilename } from "./url_to_filename.js"; | ||
let currentBasename = basename; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -13,0 +12,0 @@ const nextBasename = filenameToBasename(basename); |
import { fileURLToPath } from "node:url"; | ||
export const urlToFileSystemPath = (url) => { | ||
let urlString = String(url); | ||
if (urlString[urlString.length - 1] === "/") { | ||
const urlObject = new URL(url); | ||
let urlString; | ||
if (urlObject.hash) { | ||
const origin = | ||
urlObject.protocol === "file:" ? "file://" : urlObject.origin; | ||
urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`; | ||
} else { | ||
urlString = urlObject.href; | ||
} | ||
const fileSystemPath = fileURLToPath(urlString); | ||
if (fileSystemPath[fileSystemPath.length - 1] === "/") { | ||
// remove trailing / so that nodejs path becomes predictable otherwise it logs | ||
// the trailing slash on linux but does not on windows | ||
urlString = urlString.slice(0, -1); | ||
return fileSystemPath.slice(0, -1); | ||
} | ||
const fileSystemPath = fileURLToPath(urlString); | ||
return fileSystemPath; | ||
}; |
@@ -21,3 +21,3 @@ import { filenameToBasename } from "./url_to_basename.js"; | ||
return true; | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -24,0 +24,0 @@ } |
24452
710