@jsenv/urls 2.2.11 → 2.3.1

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.2.11",
3
+ "version": "2.3.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,6 +28,6 @@
28
28
  "test": "node --conditions=development ./scripts/test.mjs"
29
29
  },
30
30
  "dependencies": {
31
- "@jsenv/humanize": "1.2.4"
31
+ "@jsenv/humanize": "1.2.5"
32
32
  }
33
33
  }
@@ -1,5 +1,5 @@
1
- import { isFileSystemPath } from "./is_filesystem_path.js";
2
1
  import { fileSystemPathToUrl } from "./filesystem_path_to_url.js";
2
+ import { isFileSystemPath } from "./is_filesystem_path.js";
3
3
 
4
4
  export const getCallerPosition = () => {
5
5
  const { prepareStackTrace } = Error;
package/src/main.js CHANGED
@@ -1,3 +1,5 @@
1
+ // tslint:disable:ordered-imports
2
+
1
3
  export { DATA_URL } from "./data_url.js";
2
4
  export { stringifyUrlSite } from "./url_trace.js";
3
5
  export {
@@ -1,5 +1,5 @@
1
- import { ensurePathnameTrailingSlash } from "./url_utils.js";
2
1
  import { resolveUrl } from "./resolve_url.js";
2
+ import { ensurePathnameTrailingSlash } from "./url_utils.js";
3
3
 
4
4
  export const resolveDirectoryUrl = (specifier, baseUrl) => {
5
5
  const url = resolveUrl(specifier, baseUrl);
package/src/url_utils.js CHANGED
@@ -1,5 +1,5 @@
1
- import { urlToOrigin } from "./url_to_origin.js";
2
1
  import { urlToExtension } from "./url_to_extension.js";
2
+ import { urlToOrigin } from "./url_to_origin.js";
3
3
  import { urlToResource } from "./url_to_resource.js";
4
4
 
5
5
  export const asUrlWithoutSearch = (url) => {
@@ -160,18 +160,26 @@ export const setUrlFilename = (url, filename) => {
160
160
  };
161
161
 
162
162
  export const ensurePathnameTrailingSlash = (url) => {
163
- const urlObject = new URL(url);
164
- const { pathname } = urlObject;
165
- if (pathname.endsWith("/")) {
166
- return url;
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
- let { origin } = urlObject;
169
- // origin is "null" for "file://" urls with Node.js
170
- if (origin === "null" && urlObject.href.startsWith("file:")) {
171
- origin = "file://";
178
+ if (url.pathname.endsWith("/")) {
179
+ return url;
172
180
  }
173
- const { search, hash } = urlObject;
174
- return `${origin}${pathname}/${search}${hash}`;
181
+ url.pathname += "/";
182
+ return url;
175
183
  };
176
184
 
177
185
  export const asUrlUntilPathname = (url) => {