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.
@@ -1,15 +1,10 @@
1
- import { go } from '@blackglory/prelude';
2
1
  export function appendPathname(url, pathname) {
3
- const baseURL = go(() => {
4
- const baseURL = new URL(url);
5
- if (!baseURL.pathname.endsWith('/')) {
6
- baseURL.pathname = `${baseURL.pathname}/`;
7
- }
8
- return baseURL;
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,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAA;AAExC,MAAM,UAAU,cAAc,CAAC,GAAQ,EAAE,QAAgB;IACvD,MAAM,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;QACtB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACnC,OAAO,CAAC,QAAQ,GAAG,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAA;SAC1C;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAC5B,OAAO,CACR,CAAA;IACD,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC9B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAE1B,OAAO,MAAM,CAAA;AACf,CAAC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "url-operator",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "files": [
@@ -1,21 +1,10 @@
1
- import { go } from '@blackglory/prelude'
2
-
3
1
  export function appendPathname(url: URL, pathname: string): URL {
4
- const baseURL = go(() => {
5
- const baseURL = new URL(url)
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 newURL = new URL(
14
- pathname.replace(/^\/*/, '')
15
- , baseURL
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
  }