@jsenv/urls
Advanced tools
Comparing version 2.2.11 to 2.3.0
{ | ||
"name": "@jsenv/urls", | ||
"version": "2.2.11", | ||
"version": "2.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -163,14 +163,22 @@ import { urlToOrigin } from "./url_to_origin.js"; | ||
export const ensurePathnameTrailingSlash = (url) => { | ||
const urlObject = new URL(url); | ||
const { pathname } = urlObject; | ||
if (pathname.endsWith("/")) { | ||
if (typeof url === "string") { | ||
const urlObject = new URL(url); | ||
const { pathname } = urlObject; | ||
if (pathname.endsWith("/")) { | ||
return url; | ||
} | ||
let { origin } = urlObject; | ||
// origin is "null" for "file://" urls with Node.js | ||
if (origin === "null" && urlObject.href.startsWith("file:")) { | ||
origin = "file://"; | ||
} | ||
const { search, hash } = urlObject; | ||
const urlWithTrailingSlash = `${origin}${pathname}/${search}${hash}`; | ||
return urlWithTrailingSlash; | ||
} | ||
if (url.pathname.endsWith("/")) { | ||
return url; | ||
} | ||
let { origin } = urlObject; | ||
// origin is "null" for "file://" urls with Node.js | ||
if (origin === "null" && urlObject.href.startsWith("file:")) { | ||
origin = "file://"; | ||
} | ||
const { search, hash } = urlObject; | ||
return `${origin}${pathname}/${search}${hash}`; | ||
url.pathname += "/"; | ||
return url; | ||
}; | ||
@@ -177,0 +185,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21045
604