@jsenv/urls 1.2.7 → 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 +1 -1
- package/src/inline_content_url_generator.js +1 -4
- package/src/main.js +1 -1
- package/src/url_to_parent_url.js +7 -10
- package/src/url_to_pathname.js +9 -9
- package/src/url_to_relative_url.js +2 -2
- package/src/{url_to_ressource.js → url_to_resource.js} +1 -1
- package/src/url_utils.js +9 -6
package/package.json
CHANGED
|
@@ -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
|
@@ -37,5 +37,5 @@ export { urlToOrigin } from "./url_to_origin.js"
|
|
|
37
37
|
export { urlToParentUrl } from "./url_to_parent_url.js"
|
|
38
38
|
export { urlToPathname } from "./url_to_pathname.js"
|
|
39
39
|
export { urlToRelativeUrl } from "./url_to_relative_url.js"
|
|
40
|
-
export {
|
|
40
|
+
export { urlToResource } from "./url_to_resource.js"
|
|
41
41
|
export { urlToScheme } from "./url_to_scheme.js"
|
package/src/url_to_parent_url.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { urlToOrigin } from "./url_to_origin.js"
|
|
2
|
-
import {
|
|
2
|
+
import { urlToResource } from "./url_to_resource.js"
|
|
3
3
|
|
|
4
4
|
export const urlToParentUrl = (url) => {
|
|
5
|
-
const
|
|
6
|
-
const slashLastIndex =
|
|
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 =
|
|
12
|
+
const lastCharacterIndex = resource.length - 1
|
|
13
13
|
if (slashLastIndex === lastCharacterIndex) {
|
|
14
|
-
const slashPreviousIndex =
|
|
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}${
|
|
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}${
|
|
26
|
+
const parentUrl = `${origin}${resource.slice(0, slashLastIndex + 1)}`
|
|
30
27
|
return parentUrl
|
|
31
28
|
}
|
package/src/url_to_pathname.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { urlToResource } from "./url_to_resource.js"
|
|
2
2
|
|
|
3
3
|
export const urlToPathname = (url) => {
|
|
4
|
-
const
|
|
5
|
-
const pathname =
|
|
4
|
+
const resource = urlToResource(url)
|
|
5
|
+
const pathname = resourceToPathname(resource)
|
|
6
6
|
return pathname
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const searchSeparatorIndex =
|
|
9
|
+
const resourceToPathname = (resource) => {
|
|
10
|
+
const searchSeparatorIndex = resource.indexOf("?")
|
|
11
11
|
if (searchSeparatorIndex > -1) {
|
|
12
|
-
return
|
|
12
|
+
return resource.slice(0, searchSeparatorIndex)
|
|
13
13
|
}
|
|
14
|
-
const hashIndex =
|
|
14
|
+
const hashIndex = resource.indexOf("#")
|
|
15
15
|
if (hashIndex > -1) {
|
|
16
|
-
return
|
|
16
|
+
return resource.slice(0, hashIndex)
|
|
17
17
|
}
|
|
18
|
-
return
|
|
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
|
|
24
|
-
return
|
|
23
|
+
const baseUrlResourceWithoutLeadingSlash = baseUrlObject.pathname.slice(1)
|
|
24
|
+
return baseUrlResourceWithoutLeadingSlash
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const basePathname = baseUrlObject.pathname
|
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 {
|
|
3
|
+
import { urlToResource } from "./url_to_resource.js"
|
|
4
4
|
|
|
5
5
|
export const asUrlWithoutSearch = (url) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
66
|
-
const [pathname, search] =
|
|
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
|