@jsenv/urls 2.2.11 → 2.3.0
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 +1 -1
- package/src/url_utils.js +18 -10
package/package.json
CHANGED
package/src/url_utils.js
CHANGED
|
@@ -160,18 +160,26 @@ export const setUrlFilename = (url, filename) => {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
export const ensurePathnameTrailingSlash = (url) => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
if (typeof url === "string") {
|
|
164
|
+
const urlObject = new URL(url);
|
|
165
|
+
const { pathname } = urlObject;
|
|
166
|
+
if (pathname.endsWith("/")) {
|
|
167
|
+
return url;
|
|
168
|
+
}
|
|
169
|
+
let { origin } = urlObject;
|
|
170
|
+
// origin is "null" for "file://" urls with Node.js
|
|
171
|
+
if (origin === "null" && urlObject.href.startsWith("file:")) {
|
|
172
|
+
origin = "file://";
|
|
173
|
+
}
|
|
174
|
+
const { search, hash } = urlObject;
|
|
175
|
+
const urlWithTrailingSlash = `${origin}${pathname}/${search}${hash}`;
|
|
176
|
+
return urlWithTrailingSlash;
|
|
167
177
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (origin === "null" && urlObject.href.startsWith("file:")) {
|
|
171
|
-
origin = "file://";
|
|
178
|
+
if (url.pathname.endsWith("/")) {
|
|
179
|
+
return url;
|
|
172
180
|
}
|
|
173
|
-
|
|
174
|
-
return
|
|
181
|
+
url.pathname += "/";
|
|
182
|
+
return url;
|
|
175
183
|
};
|
|
176
184
|
|
|
177
185
|
export const asUrlUntilPathname = (url) => {
|