@jsenv/urls 1.2.6 → 1.2.8

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": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,8 +8,7 @@
8
8
  "directory": "packages/urls"
9
9
  },
10
10
  "publishConfig": {
11
- "access": "public",
12
- "registry": "https://registry.npmjs.org"
11
+ "access": "public"
13
12
  },
14
13
  "author": {
15
14
  "name": "dmail",
@@ -30,4 +29,4 @@
30
29
  "test": "node --conditions=development ./scripts/test.mjs"
31
30
  },
32
31
  "dependencies": {}
33
- }
32
+ }
@@ -8,10 +8,7 @@ export const generateInlineContentUrl = ({
8
8
  lineEnd,
9
9
  columnEnd,
10
10
  }) => {
11
- const generatedName =
12
- line === lineEnd
13
- ? `L${line}C${column}-L${lineEnd}C${columnEnd}`
14
- : `L${line}-L${lineEnd}`
11
+ const generatedName = `L${line}C${column}-L${lineEnd}C${columnEnd}`
15
12
  const filenameRaw = urlToFilename(url)
16
13
  const filename = `${filenameRaw}@${generatedName}${extension}`
17
14
  // ideally we should keep query params from url
package/src/main.js CHANGED
@@ -3,7 +3,6 @@ export { generateInlineContentUrl } from "./inline_content_url_generator.js"
3
3
  export {
4
4
  stringifyUrlTrace,
5
5
  stringifyUrlSite,
6
- humanizeUrl,
7
6
  showSourceLocation,
8
7
  } from "./url_trace.js"
9
8
  export {
@@ -38,5 +37,5 @@ export { urlToOrigin } from "./url_to_origin.js"
38
37
  export { urlToParentUrl } from "./url_to_parent_url.js"
39
38
  export { urlToPathname } from "./url_to_pathname.js"
40
39
  export { urlToRelativeUrl } from "./url_to_relative_url.js"
41
- export { urlToRessource } from "./url_to_ressource.js"
40
+ export { urlToResource } from "./url_to_resource.js"
42
41
  export { urlToScheme } from "./url_to_scheme.js"
@@ -1,31 +1,28 @@
1
1
  import { urlToOrigin } from "./url_to_origin.js"
2
- import { urlToRessource } from "./url_to_ressource.js"
2
+ import { urlToResource } from "./url_to_resource.js"
3
3
 
4
4
  export const urlToParentUrl = (url) => {
5
- const ressource = urlToRessource(url)
6
- const slashLastIndex = ressource.lastIndexOf("/")
5
+ const resource = urlToResource(url)
6
+ const slashLastIndex = resource.lastIndexOf("/")
7
7
  if (slashLastIndex === -1) {
8
8
  const urlAsString = String(url)
9
9
  return urlAsString
10
10
  }
11
11
 
12
- const lastCharacterIndex = ressource.length - 1
12
+ const lastCharacterIndex = resource.length - 1
13
13
  if (slashLastIndex === lastCharacterIndex) {
14
- const slashPreviousIndex = ressource.lastIndexOf(
15
- "/",
16
- lastCharacterIndex - 1,
17
- )
14
+ const slashPreviousIndex = resource.lastIndexOf("/", lastCharacterIndex - 1)
18
15
  if (slashPreviousIndex === -1) {
19
16
  const urlAsString = String(url)
20
17
  return urlAsString
21
18
  }
22
19
 
23
20
  const origin = urlToOrigin(url)
24
- const parentUrl = `${origin}${ressource.slice(0, slashPreviousIndex + 1)}`
21
+ const parentUrl = `${origin}${resource.slice(0, slashPreviousIndex + 1)}`
25
22
  return parentUrl
26
23
  }
27
24
 
28
25
  const origin = urlToOrigin(url)
29
- const parentUrl = `${origin}${ressource.slice(0, slashLastIndex + 1)}`
26
+ const parentUrl = `${origin}${resource.slice(0, slashLastIndex + 1)}`
30
27
  return parentUrl
31
28
  }
@@ -1,19 +1,19 @@
1
- import { urlToRessource } from "./url_to_ressource.js"
1
+ import { urlToResource } from "./url_to_resource.js"
2
2
 
3
3
  export const urlToPathname = (url) => {
4
- const ressource = urlToRessource(url)
5
- const pathname = ressourceToPathname(ressource)
4
+ const resource = urlToResource(url)
5
+ const pathname = resourceToPathname(resource)
6
6
  return pathname
7
7
  }
8
8
 
9
- const ressourceToPathname = (ressource) => {
10
- const searchSeparatorIndex = ressource.indexOf("?")
9
+ const resourceToPathname = (resource) => {
10
+ const searchSeparatorIndex = resource.indexOf("?")
11
11
  if (searchSeparatorIndex > -1) {
12
- return ressource.slice(0, searchSeparatorIndex)
12
+ return resource.slice(0, searchSeparatorIndex)
13
13
  }
14
- const hashIndex = ressource.indexOf("#")
14
+ const hashIndex = resource.indexOf("#")
15
15
  if (hashIndex > -1) {
16
- return ressource.slice(0, hashIndex)
16
+ return resource.slice(0, hashIndex)
17
17
  }
18
- return ressource
18
+ return resource
19
19
  }
@@ -20,8 +20,8 @@ export const urlToRelativeUrl = (url, baseUrl) => {
20
20
 
21
21
  const { pathname, hash, search } = urlObject
22
22
  if (pathname === "/") {
23
- const baseUrlRessourceWithoutLeadingSlash = baseUrlObject.pathname.slice(1)
24
- return baseUrlRessourceWithoutLeadingSlash
23
+ const baseUrlResourceWithoutLeadingSlash = baseUrlObject.pathname.slice(1)
24
+ return baseUrlResourceWithoutLeadingSlash
25
25
  }
26
26
 
27
27
  const basePathname = baseUrlObject.pathname
@@ -1,6 +1,6 @@
1
1
  import { urlToScheme } from "./url_to_scheme.js"
2
2
 
3
- export const urlToRessource = (url) => {
3
+ export const urlToResource = (url) => {
4
4
  const scheme = urlToScheme(url)
5
5
 
6
6
  if (scheme === "file") {
package/src/url_trace.js CHANGED
@@ -3,8 +3,6 @@
3
3
  // https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50
4
4
  // https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1
5
5
 
6
- import { urlToFileSystemPath } from "./url_to_filesystem_path.js"
7
-
8
6
  export const stringifyUrlTrace = (trace) => {
9
7
  let string = ""
10
8
  trace.forEach(({ type, url, line, column, source }, index) => {
@@ -41,7 +39,7 @@ export const stringifyUrlSite = (
41
39
  color,
42
40
  } = {},
43
41
  ) => {
44
- let string = `${humanizeUrl(url)}`
42
+ let string = url
45
43
 
46
44
  if (typeof line === "number") {
47
45
  string += `:${line}`
@@ -67,15 +65,6 @@ export const stringifyUrlSite = (
67
65
  ${sourceLoc}`
68
66
  }
69
67
 
70
- export const humanizeUrl = (url) => {
71
- if (url.startsWith("file://")) {
72
- // we prefer file system path because vscode reliably make them clickable
73
- // and sometimes it won't for file:// urls
74
- return urlToFileSystemPath(url)
75
- }
76
- return url
77
- }
78
-
79
68
  export const showSourceLocation = ({
80
69
  content,
81
70
  line,
package/src/url_utils.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { urlToOrigin } from "./url_to_origin.js"
2
2
  import { urlToExtension } from "./url_to_extension.js"
3
- import { urlToRessource } from "./url_to_ressource.js"
3
+ import { urlToResource } from "./url_to_resource.js"
4
4
 
5
5
  export const asUrlWithoutSearch = (url) => {
6
- const urlObject = new URL(url)
7
- urlObject.search = ""
8
- return urlObject.href
6
+ if (url.includes("?")) {
7
+ const urlObject = new URL(url)
8
+ urlObject.search = ""
9
+ return urlObject.href
10
+ }
11
+ return url
9
12
  }
10
13
 
11
14
  export const isValidUrl = (url) => {
@@ -62,8 +65,8 @@ export const injectQueryParams = (url, params) => {
62
65
  export const setUrlExtension = (url, extension) => {
63
66
  const origin = urlToOrigin(url)
64
67
  const currentExtension = urlToExtension(url)
65
- const ressource = urlToRessource(url)
66
- const [pathname, search] = ressource.split("?")
68
+ const resource = urlToResource(url)
69
+ const [pathname, search] = resource.split("?")
67
70
  const pathnameWithoutExtension = currentExtension
68
71
  ? pathname.slice(0, -currentExtension.length)
69
72
  : pathname