@jsenv/urls
Advanced tools
Comparing version 2.4.1 to 2.5.0
{ | ||
"name": "@jsenv/urls", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"license": "MIT", | ||
@@ -31,4 +31,4 @@ "repository": { | ||
"dependencies": { | ||
"@jsenv/humanize": "1.2.6" | ||
"@jsenv/humanize": "1.2.7" | ||
} | ||
} |
@@ -14,4 +14,5 @@ // tslint:disable:ordered-imports | ||
renderUrlOrRelativeUrlFilename, | ||
setUrlFilename, | ||
setUrlBasename, | ||
setUrlExtension, | ||
setUrlFilename, | ||
ensurePathnameTrailingSlash, | ||
@@ -46,1 +47,3 @@ removePathnameTrailingSlash, | ||
export { getCommonPathname } from "./common_pathname.js"; | ||
export { yieldAncestorUrls } from "./yield_ancestor_urls.js"; |
@@ -5,2 +5,6 @@ import { urlToFilename } from "./url_to_filename.js"; | ||
const filename = urlToFilename(url); | ||
return filenameToBasename(filename); | ||
}; | ||
export const filenameToBasename = (filename) => { | ||
const dotLastIndex = filename.lastIndexOf("."); | ||
@@ -7,0 +11,0 @@ const basename = |
@@ -5,2 +5,6 @@ import { urlToPathname } from "./url_to_pathname.js"; | ||
const pathname = urlToPathname(url); | ||
return pathnameToFilename(pathname); | ||
}; | ||
export const pathnameToFilename = (pathname) => { | ||
const pathnameBeforeLastSlash = pathname.endsWith("/") | ||
@@ -7,0 +11,0 @@ ? pathname.slice(0, -1) |
@@ -0,2 +1,4 @@ | ||
import { filenameToBasename } from "./url_to_basename.js"; | ||
import { urlToExtension } from "./url_to_extension.js"; | ||
import { pathnameToFilename } from "./url_to_filename.js"; | ||
import { urlToOrigin } from "./url_to_origin.js"; | ||
@@ -142,2 +144,5 @@ import { urlToResource } from "./url_to_resource.js"; | ||
const currentExtension = urlToExtension(url); | ||
if (typeof extension === "function") { | ||
extension = extension(currentExtension); | ||
} | ||
const resource = urlToResource(url); | ||
@@ -161,12 +166,20 @@ const [pathname, search] = resource.split("?"); | ||
export const setUrlFilename = (url, filename) => { | ||
const urlObject = new URL(url); | ||
let { origin, search, hash } = urlObject; | ||
// origin is "null" for "file://" urls with Node.js | ||
if (origin === "null" && urlObject.href.startsWith("file:")) { | ||
origin = "file://"; | ||
} | ||
const parentPathname = new URL("./", urlObject).pathname; | ||
return `${origin}${parentPathname}${filename}${search}${hash}`; | ||
const parentPathname = new URL("./", url).pathname; | ||
return transformUrlPathname(url, (pathname) => { | ||
if (typeof filename === "function") { | ||
filename = filename(pathnameToFilename(pathname)); | ||
} | ||
return `${parentPathname}${filename}`; | ||
}); | ||
}; | ||
export const setUrlBasename = (url, basename) => { | ||
return setUrlFilename(url, (filename) => { | ||
if (typeof basename === "function") { | ||
basename = basename(filenameToBasename(filename)); | ||
} | ||
return `${basename}${urlToExtension(url)}`; | ||
}); | ||
}; | ||
const transformUrlPathname = (url, transformer) => { | ||
@@ -173,0 +186,0 @@ if (typeof url === "string") { |
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
23916
26
691
+ Added@jsenv/humanize@1.2.7(transitive)
- Removed@jsenv/humanize@1.2.6(transitive)
Updated@jsenv/humanize@1.2.7