@jsenv/urls 2.8.0 → 2.9.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.
Files changed (30) hide show
  1. package/package.json +6 -6
  2. package/src/main_node.js +3 -3
  3. package/src/main_shared.js +23 -22
  4. package/src/{file_and_path → node}/caller_position.js +1 -1
  5. package/src/{file_and_path → node}/filesystem_path_to_url.js +1 -1
  6. package/src/{file_and_path → shared}/resolve_directory_url.js +1 -1
  7. package/src/{composition → shared}/set_url_part.js +27 -23
  8. package/src/{file_and_path/url_is_inside_of.js → shared/url_is_or_is_inside_of.js} +2 -2
  9. package/src/{url_to_relative_url.js → shared/url_to_relative_url.js} +1 -1
  10. package/src/{file_and_path → shared}/yield_ancestor_urls.js +1 -1
  11. /package/src/{file_and_path → node}/url_to_filesystem_path.js +0 -0
  12. /package/src/{composition → shared}/common_pathname.js +0 -0
  13. /package/src/{data_url.js → shared/data_url.js} +0 -0
  14. /package/src/{ensure_url_trailing_slash.js → shared/ensure_url_trailing_slash.js} +0 -0
  15. /package/src/{file_and_path → shared}/is_filesystem_path.js +0 -0
  16. /package/src/{move_url.js → shared/move_url.js} +0 -0
  17. /package/src/{composition → shared}/pathname_to_extension.js +0 -0
  18. /package/src/{query_params → shared}/query_params.js +0 -0
  19. /package/src/{file_and_path → shared}/resolve_url.js +0 -0
  20. /package/src/{composition → shared}/resource_to_parts.js +0 -0
  21. /package/src/{composition → shared}/url_to_basename.js +0 -0
  22. /package/src/{composition → shared}/url_to_extension.js +0 -0
  23. /package/src/{composition → shared}/url_to_filename.js +0 -0
  24. /package/src/{composition → shared}/url_to_origin.js +0 -0
  25. /package/src/{composition → shared}/url_to_parent_url.js +0 -0
  26. /package/src/{composition → shared}/url_to_pathname.js +0 -0
  27. /package/src/{composition → shared}/url_to_resource.js +0 -0
  28. /package/src/{composition → shared}/url_to_scheme.js +0 -0
  29. /package/src/{url_trace.js → shared/url_trace.js} +0 -0
  30. /package/src/{file_and_path → shared}/windows_file_path_utils.js +0 -0
package/package.json CHANGED
@@ -1,19 +1,17 @@
1
1
  {
2
2
  "name": "@jsenv/urls",
3
- "version": "2.8.0",
4
- "license": "MIT",
3
+ "version": "2.9.1",
5
4
  "repository": {
6
5
  "type": "git",
7
6
  "url": "https://github.com/jsenv/core",
8
7
  "directory": "packages/tooling/urls"
9
8
  },
10
- "publishConfig": {
11
- "access": "public"
12
- },
9
+ "license": "MIT",
13
10
  "author": {
14
11
  "name": "dmail",
15
12
  "email": "dmaillard06@gmail.com"
16
13
  },
14
+ "sideEffects": false,
17
15
  "type": "module",
18
16
  "exports": {
19
17
  ".": {
@@ -25,12 +23,14 @@
25
23
  "files": [
26
24
  "/src/"
27
25
  ],
28
- "sideEffects": false,
29
26
  "dependencies": {
30
27
  "@jsenv/humanize": "1.6.0"
31
28
  },
32
29
  "devDependencies": {
33
30
  "@jsenv/assert": "../assert",
34
31
  "@jsenv/urls": "../urls"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
35
  }
36
36
  }
package/src/main_node.js CHANGED
@@ -1,4 +1,4 @@
1
- export { getCallerPosition } from "./file_and_path/caller_position.js";
2
- export { fileSystemPathToUrl } from "./file_and_path/filesystem_path_to_url.js";
3
- export { urlToFileSystemPath } from "./file_and_path/url_to_filesystem_path.js";
4
1
  export * from "./main_shared.js";
2
+ export { getCallerPosition } from "./node/caller_position.js";
3
+ export { fileSystemPathToUrl } from "./node/filesystem_path_to_url.js";
4
+ export { urlToFileSystemPath } from "./node/url_to_filesystem_path.js";
@@ -1,7 +1,7 @@
1
1
  // tslint:disable:ordered-imports
2
2
 
3
- export { DATA_URL } from "./data_url.js";
4
- export { stringifyUrlSite } from "./url_trace.js";
3
+ export { DATA_URL } from "./shared/data_url.js";
4
+ export { stringifyUrlSite } from "./shared/url_trace.js";
5
5
  export {
6
6
  setUrlFilename,
7
7
  setUrlBasename,
@@ -9,7 +9,7 @@ export {
9
9
  ensurePathnameTrailingSlash,
10
10
  removePathnameTrailingSlash,
11
11
  asUrlUntilPathname,
12
- } from "./composition/set_url_part.js";
12
+ } from "./shared/set_url_part.js";
13
13
  export {
14
14
  asUrlWithoutSearch,
15
15
  asSpecifierWithoutSearch,
@@ -20,32 +20,33 @@ export {
20
20
  injectQueryParamWithoutEncoding,
21
21
  injectQueryParamIntoSpecifierWithoutEncoding,
22
22
  renderUrlOrRelativeUrlFilename,
23
- } from "./query_params/query_params.js";
23
+ } from "./shared/query_params.js";
24
+ export { moveUrl } from "./shared/move_url.js";
25
+ export { urlToRelativeUrl } from "./shared/url_to_relative_url.js";
24
26
  // composition
25
- export { moveUrl } from "./move_url.js";
26
- export { urlToBasename } from "./composition/url_to_basename.js";
27
- export { urlToExtension } from "./composition/url_to_extension.js";
28
- export { urlToFilename } from "./composition/url_to_filename.js";
29
- export { urlToOrigin } from "./composition/url_to_origin.js";
30
- export { urlToParentUrl } from "./composition/url_to_parent_url.js";
31
- export { urlToPathname } from "./composition/url_to_pathname.js";
32
- export { urlToRelativeUrl } from "./url_to_relative_url.js";
33
- export { urlToResource } from "./composition/url_to_resource.js";
34
- export { urlToScheme } from "./composition/url_to_scheme.js";
35
- export { getCommonPathname } from "./composition/common_pathname.js";
27
+ export { urlToBasename } from "./shared/url_to_basename.js";
28
+ export { urlToExtension } from "./shared/url_to_extension.js";
29
+ export { urlToFilename } from "./shared/url_to_filename.js";
30
+ export { urlToOrigin } from "./shared/url_to_origin.js";
31
+ export { urlToParentUrl } from "./shared/url_to_parent_url.js";
32
+ export { urlToPathname } from "./shared/url_to_pathname.js";
33
+ export { urlToResource } from "./shared/url_to_resource.js";
34
+ export { urlToScheme } from "./shared/url_to_scheme.js";
35
+ export { getCommonPathname } from "./shared/common_pathname.js";
36
36
  export {
37
37
  resourceToParts,
38
38
  resourceToPathname,
39
39
  resourceToExtension,
40
- } from "./composition/resource_to_parts.js";
40
+ } from "./shared/resource_to_parts.js";
41
41
  // file_and_path
42
42
  export {
43
43
  startsWithWindowsDriveLetter,
44
44
  windowsFilePathToUrl,
45
45
  replaceBackSlashesWithSlashes,
46
- } from "./file_and_path/windows_file_path_utils.js";
47
- export { isFileSystemPath } from "./file_and_path/is_filesystem_path.js";
48
- export { resolveUrl } from "./file_and_path/resolve_url.js";
49
- export { resolveDirectoryUrl } from "./file_and_path/resolve_directory_url.js";
50
- export { urlIsInsideOf } from "./file_and_path/url_is_inside_of.js";
51
- export { yieldAncestorUrls } from "./file_and_path/yield_ancestor_urls.js";
46
+ } from "./shared/windows_file_path_utils.js";
47
+ export { isFileSystemPath } from "./shared/is_filesystem_path.js";
48
+ export { resolveUrl } from "./shared/resolve_url.js";
49
+ export { resolveDirectoryUrl } from "./shared/resolve_directory_url.js";
50
+ export { urlIsOrIsInsideOf } from "./shared/url_is_or_is_inside_of.js";
51
+ export { yieldAncestorUrls } from "./shared/yield_ancestor_urls.js";
52
+ export { pathnameToExtension } from "./shared/pathname_to_extension.js";
@@ -1,5 +1,5 @@
1
+ import { isFileSystemPath } from "../shared/is_filesystem_path.js";
1
2
  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;
@@ -1,5 +1,5 @@
1
1
  import { pathToFileURL } from "node:url";
2
- import { isFileSystemPath } from "./is_filesystem_path.js";
2
+ import { isFileSystemPath } from "../shared/is_filesystem_path.js";
3
3
 
4
4
  export const fileSystemPathToUrl = (value) => {
5
5
  if (!isFileSystemPath(value)) {
@@ -1,5 +1,5 @@
1
- import { ensurePathnameTrailingSlash } from "../composition/set_url_part.js";
2
1
  import { resolveUrl } from "./resolve_url.js";
2
+ import { ensurePathnameTrailingSlash } from "./set_url_part.js";
3
3
 
4
4
  export const resolveDirectoryUrl = (specifier, baseUrl) => {
5
5
  const url = resolveUrl(specifier, baseUrl);
@@ -1,30 +1,34 @@
1
1
  import { filenameToBasename } from "./url_to_basename.js";
2
2
  import { urlToExtension } from "./url_to_extension.js";
3
3
  import { pathnameToFilename } from "./url_to_filename.js";
4
- import { urlToOrigin } from "./url_to_origin.js";
5
- import { urlToResource } from "./url_to_resource.js";
6
4
 
7
- export const setUrlExtension = (url, extension) => {
8
- const origin = urlToOrigin(url);
9
- const currentExtension = urlToExtension(url);
10
- if (typeof extension === "function") {
11
- extension = extension(currentExtension);
12
- }
13
- const resource = urlToResource(url);
14
- const [pathname, search] = resource.split("?");
15
- const pathnameWithoutExtension = currentExtension
16
- ? pathname.slice(0, -currentExtension.length)
17
- : pathname;
18
- let newPathname;
19
- if (pathnameWithoutExtension.endsWith("/")) {
20
- newPathname = pathnameWithoutExtension.slice(0, -1);
21
- newPathname += extension;
22
- newPathname += "/";
23
- } else {
24
- newPathname = pathnameWithoutExtension;
25
- newPathname += extension;
26
- }
27
- return `${origin}${newPathname}${search ? `?${search}` : ""}`;
5
+ export const setUrlExtension = (
6
+ url,
7
+ extension,
8
+ { trailingSlash = "preserve" } = {},
9
+ ) => {
10
+ return transformUrlPathname(url, (pathname) => {
11
+ const currentExtension = urlToExtension(url);
12
+ if (typeof extension === "function") {
13
+ extension = extension(currentExtension);
14
+ }
15
+ const pathnameWithoutExtension = currentExtension
16
+ ? pathname.slice(0, -currentExtension.length)
17
+ : pathname;
18
+
19
+ if (pathnameWithoutExtension.endsWith("/")) {
20
+ let pathnameWithExtension;
21
+ pathnameWithExtension = pathnameWithoutExtension.slice(0, -1);
22
+ pathnameWithExtension += extension;
23
+ if (trailingSlash === "preserve") {
24
+ pathnameWithExtension += "/";
25
+ }
26
+ return pathnameWithExtension;
27
+ }
28
+ let pathnameWithExtension = pathnameWithoutExtension;
29
+ pathnameWithExtension += extension;
30
+ return pathnameWithExtension;
31
+ });
28
32
  };
29
33
 
30
34
  export const setUrlFilename = (url, filename) => {
@@ -1,4 +1,4 @@
1
- export const urlIsInsideOf = (url, otherUrl) => {
1
+ export const urlIsOrIsInsideOf = (url, otherUrl) => {
2
2
  const urlObject = new URL(url);
3
3
  const otherUrlObject = new URL(otherUrl);
4
4
 
@@ -9,7 +9,7 @@ export const urlIsInsideOf = (url, otherUrl) => {
9
9
  const urlPathname = urlObject.pathname;
10
10
  const otherUrlPathname = otherUrlObject.pathname;
11
11
  if (urlPathname === otherUrlPathname) {
12
- return false;
12
+ return true;
13
13
  }
14
14
 
15
15
  const isInside = urlPathname.startsWith(otherUrlPathname);
@@ -1,4 +1,4 @@
1
- import { getCommonPathname } from "./composition/common_pathname.js";
1
+ import { getCommonPathname } from "./common_pathname.js";
2
2
 
3
3
  export const urlToRelativeUrl = (
4
4
  url,
@@ -1,4 +1,4 @@
1
- import { ensurePathnameTrailingSlash } from "../composition/set_url_part.js";
1
+ import { ensurePathnameTrailingSlash } from "./set_url_part.js";
2
2
 
3
3
  export function* yieldAncestorUrls(url, rootUrl, { yieldSelf } = {}) {
4
4
  url = String(url);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes