url-operator 0.3.3 → 0.3.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/lib/append-pathname.js +6 -11
- package/lib/append-pathname.js.map +1 -1
- package/package.json +1 -1
- package/src/append-pathname.ts +5 -16
package/lib/append-pathname.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { go } from '@blackglory/prelude';
|
|
2
1
|
export function appendPathname(url, pathname) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
const newURL = new URL(pathname.replace(/^\/*/, ''), baseURL);
|
|
11
|
-
newURL.search = baseURL.search;
|
|
12
|
-
newURL.hash = baseURL.hash;
|
|
2
|
+
const newURL = new URL(url);
|
|
3
|
+
if (!newURL.pathname.endsWith('/'))
|
|
4
|
+
newURL.pathname += '/';
|
|
5
|
+
const relativePathname = pathname.replace(/^\/+/, '');
|
|
6
|
+
const newPathname = new URL(relativePathname, newURL).pathname.replace(/\/+$/, '');
|
|
7
|
+
newURL.pathname = newPathname;
|
|
13
8
|
return newURL;
|
|
14
9
|
}
|
|
15
10
|
//# sourceMappingURL=append-pathname.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append-pathname.js","sourceRoot":"","sources":["../src/append-pathname.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"append-pathname.js","sourceRoot":"","sources":["../src/append-pathname.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,GAAQ,EAAE,QAAgB;IACvD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAA;IAE1D,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACrD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAClF,MAAM,CAAC,QAAQ,GAAG,WAAW,CAAA;IAE7B,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/append-pathname.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import { go } from '@blackglory/prelude'
|
|
2
|
-
|
|
3
1
|
export function appendPathname(url: URL, pathname: string): URL {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (!baseURL.pathname.endsWith('/')) {
|
|
7
|
-
baseURL.pathname = `${baseURL.pathname}/`
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return baseURL
|
|
11
|
-
})
|
|
2
|
+
const newURL = new URL(url)
|
|
3
|
+
if (!newURL.pathname.endsWith('/')) newURL.pathname += '/'
|
|
12
4
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
newURL.search = baseURL.search
|
|
18
|
-
newURL.hash = baseURL.hash
|
|
5
|
+
const relativePathname = pathname.replace(/^\/+/, '')
|
|
6
|
+
const newPathname = new URL(relativePathname, newURL).pathname.replace(/\/+$/, '')
|
|
7
|
+
newURL.pathname = newPathname
|
|
19
8
|
|
|
20
9
|
return newURL
|
|
21
10
|
}
|