@jsenv/urls 1.2.1 → 1.2.4
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/common_pathname.js +6 -2
- package/src/move_url.js +5 -1
package/package.json
CHANGED
package/src/common_pathname.js
CHANGED
|
@@ -7,9 +7,10 @@ export const getCommonPathname = (pathname, otherPathname) => {
|
|
|
7
7
|
let i = 0
|
|
8
8
|
const length = pathname.length
|
|
9
9
|
const otherLength = otherPathname.length
|
|
10
|
-
while (i <
|
|
10
|
+
while (i < length) {
|
|
11
11
|
const char = pathname.charAt(i)
|
|
12
12
|
const otherChar = otherPathname.charAt(i)
|
|
13
|
+
i++
|
|
13
14
|
if (char === otherChar) {
|
|
14
15
|
if (char === "/") {
|
|
15
16
|
commonPart += "/"
|
|
@@ -19,9 +20,12 @@ export const getCommonPathname = (pathname, otherPathname) => {
|
|
|
19
20
|
commonPart += char
|
|
20
21
|
}
|
|
21
22
|
} else {
|
|
23
|
+
if (char === "/" && i - 1 === otherLength) {
|
|
24
|
+
commonPart += "/"
|
|
25
|
+
commonPathname += commonPart
|
|
26
|
+
}
|
|
22
27
|
return commonPathname
|
|
23
28
|
}
|
|
24
|
-
i++
|
|
25
29
|
}
|
|
26
30
|
if (length === otherLength) {
|
|
27
31
|
commonPathname += commonPart
|
package/src/move_url.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { urlToRelativeUrl } from "./url_to_relative_url.js"
|
|
2
2
|
|
|
3
3
|
export const moveUrl = ({ url, from, to, preferAbsolute = false }) => {
|
|
4
|
-
|
|
4
|
+
let relativeUrl = urlToRelativeUrl(url, from)
|
|
5
|
+
if (relativeUrl.slice(0, 2) === "//") {
|
|
6
|
+
// restore the protocol
|
|
7
|
+
relativeUrl = new URL(relativeUrl, url).href
|
|
8
|
+
}
|
|
5
9
|
const absoluteUrl = new URL(relativeUrl, to).href
|
|
6
10
|
if (preferAbsolute) {
|
|
7
11
|
return absoluteUrl
|