@chriscdn/build-url 1.0.11 → 2.0.0

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/README.md CHANGED
@@ -8,7 +8,7 @@ This package is a fork of [@googlicius/build-url](https://github.com/googlicius/
8
8
 
9
9
  I forked this package for three reasons:
10
10
 
11
- - to provide an ES6 build,
11
+ - to provide an ESM build,
12
12
  - to fix [this issue](https://github.com/googlicius/build-url/issues/3), and
13
13
  - to provide a named export.
14
14
 
@@ -30,7 +30,7 @@ yarn add @chriscdn/build-url
30
30
 
31
31
  Create a url:
32
32
 
33
- ```js
33
+ ```ts
34
34
  import { buildUrl } from "@chriscdn/build-url";
35
35
 
36
36
  buildUrl("http://my-website.com/post", {
@@ -44,7 +44,7 @@ buildUrl("http://my-website.com/post", {
44
44
 
45
45
  Add another query parameter:
46
46
 
47
- ```js
47
+ ```ts
48
48
  buildUrl("http://my-website.com/post?page=2", {
49
49
  queryParams: {
50
50
  sort: "title:asc",
@@ -56,7 +56,7 @@ buildUrl("http://my-website.com/post?page=2", {
56
56
 
57
57
  Input url/path is omitted:
58
58
 
59
- ```js
59
+ ```ts
60
60
  buildUrl({
61
61
  queryParams: {
62
62
  sort: "title:asc",
@@ -68,7 +68,7 @@ buildUrl({
68
68
 
69
69
  Remove a query parameter:
70
70
 
71
- ```js
71
+ ```ts
72
72
  buildUrl("images?page=2&sort=title:asc", {
73
73
  queryParams: {
74
74
  page: null,
@@ -80,7 +80,7 @@ buildUrl("images?page=2&sort=title:asc", {
80
80
 
81
81
  Return an absolute url:
82
82
 
83
- ```js
83
+ ```ts
84
84
  // Assume that current url is: http://awesome-website.com
85
85
 
86
86
  buildUrl("/posts", {
@@ -95,4 +95,4 @@ buildUrl("/posts", {
95
95
 
96
96
  ## License
97
97
 
98
- MIT
98
+ [MIT](LICENSE)
package/lib/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export type UrlOptions = {
2
- queryParams?: {
3
- [x: string]: any;
4
- };
5
- hash?: string;
6
- path?: string | null;
7
- returnAbsoluteUrl?: boolean;
8
- };
9
- declare const buildUrl: (inputUrl?: string | UrlOptions, options?: UrlOptions) => string;
10
- export { buildUrl };
1
+ type UrlOptions = {
2
+ queryParams?: {
3
+ [x: string]: any;
4
+ };
5
+ hash?: string;
6
+ path?: string | null;
7
+ returnAbsoluteUrl?: boolean;
8
+ };
9
+ declare const buildUrl: (inputUrl?: string | UrlOptions, options?: UrlOptions) => string;
10
+
11
+ export { type UrlOptions, buildUrl };
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
1
+ // src/index.ts
2
+ var isEmpty = (value) => value === null || value === void 0;
3
+ var buildUrl = (inputUrl, options) => {
4
+ let url;
5
+ let isValidInputUrl = false;
6
+ try {
7
+ url = new URL(inputUrl);
8
+ } catch (error) {
9
+ isValidInputUrl = true;
10
+ if (typeof inputUrl === "string") {
11
+ const host = typeof window === "undefined" ? "http://example.com" : window.location.origin;
12
+ url = new URL(`${host}/${inputUrl.replace(/^\/|\/$/g, "")}`);
13
+ } else {
14
+ url = typeof window === "undefined" ? new URL("http://example.com") : new URL(window.location.href);
15
+ }
16
+ }
17
+ const _options = typeof inputUrl === "string" ? options : inputUrl;
18
+ if (_options?.queryParams) {
19
+ for (const key in _options.queryParams) {
20
+ if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {
21
+ const element = _options.queryParams[key];
22
+ if (isEmpty(element)) {
23
+ url.searchParams.delete(key);
24
+ } else {
25
+ url.searchParams.set(key, element);
26
+ }
27
+ }
28
+ }
29
+ }
30
+ if (_options?.path) {
31
+ url.pathname = _options.path;
32
+ }
33
+ if (_options?.path === null) {
34
+ url.pathname = "";
35
+ }
36
+ if (_options?.hash) {
37
+ url.hash = _options.hash;
38
+ }
39
+ if (isValidInputUrl && !_options?.returnAbsoluteUrl) {
40
+ return url.pathname + url.search + url.hash;
41
+ }
42
+ return url.toString();
43
+ };
44
+ export {
45
+ buildUrl
46
+ };
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type UrlOptions = {\n queryParams?: {\n [x: string]: any;\n };\n hash?: string;\n path?: string | null;\n returnAbsoluteUrl?: boolean;\n};\n\nconst isEmpty = (value: any) => value === null || value === undefined;\n\nconst buildUrl = (\n inputUrl?: string | UrlOptions,\n options?: UrlOptions,\n) => {\n let url: URL;\n let isValidInputUrl = false;\n\n try {\n url = new URL(inputUrl as string);\n } catch (error) {\n isValidInputUrl = true;\n\n if (typeof inputUrl === \"string\") {\n const host = typeof window === \"undefined\"\n ? \"http://example.com\"\n : window.location.origin;\n\n url = new URL(`${host}/${inputUrl.replace(/^\\/|\\/$/g, \"\")}`);\n } else {\n url = typeof window === \"undefined\"\n ? new URL(\"http://example.com\")\n : new URL(window.location.href);\n }\n }\n\n const _options = typeof inputUrl === \"string\" ? options : inputUrl;\n\n if (_options?.queryParams) {\n for (const key in _options.queryParams) {\n if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {\n const element = _options.queryParams[key];\n\n if (isEmpty(element)) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, element);\n }\n }\n }\n }\n\n if (_options?.path) {\n url.pathname = _options.path;\n }\n\n if (_options?.path === null) {\n url.pathname = \"\";\n }\n\n if (_options?.hash) {\n url.hash = _options.hash;\n }\n\n if (isValidInputUrl && !_options?.returnAbsoluteUrl) {\n return url.pathname + url.search + url.hash;\n }\n\n return url.toString();\n};\n\nexport { buildUrl };\n"],"mappings":";AASA,IAAM,UAAU,CAAC,UAAe,UAAU,QAAQ,UAAU;AAE5D,IAAM,WAAW,CACf,UACA,YACG;AACH,MAAI;AACJ,MAAI,kBAAkB;AAEtB,MAAI;AACF,UAAM,IAAI,IAAI,QAAkB;AAAA,EAClC,SAAS,OAAO;AACd,sBAAkB;AAElB,QAAI,OAAO,aAAa,UAAU;AAChC,YAAM,OAAO,OAAO,WAAW,cAC3B,uBACA,OAAO,SAAS;AAEpB,YAAM,IAAI,IAAI,GAAG,IAAI,IAAI,SAAS,QAAQ,YAAY,EAAE,CAAC,EAAE;AAAA,IAC7D,OAAO;AACL,YAAM,OAAO,WAAW,cACpB,IAAI,IAAI,oBAAoB,IAC5B,IAAI,IAAI,OAAO,SAAS,IAAI;AAAA,IAClC;AAAA,EACF;AAEA,QAAM,WAAW,OAAO,aAAa,WAAW,UAAU;AAE1D,MAAI,UAAU,aAAa;AACzB,eAAW,OAAO,SAAS,aAAa;AACtC,UAAI,OAAO,UAAU,eAAe,KAAK,SAAS,aAAa,GAAG,GAAG;AACnE,cAAM,UAAU,SAAS,YAAY,GAAG;AAExC,YAAI,QAAQ,OAAO,GAAG;AACpB,cAAI,aAAa,OAAO,GAAG;AAAA,QAC7B,OAAO;AACL,cAAI,aAAa,IAAI,KAAK,OAAO;AAAA,QACnC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,MAAM;AAClB,QAAI,WAAW,SAAS;AAAA,EAC1B;AAEA,MAAI,UAAU,SAAS,MAAM;AAC3B,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,UAAU,MAAM;AAClB,QAAI,OAAO,SAAS;AAAA,EACtB;AAEA,MAAI,mBAAmB,CAAC,UAAU,mBAAmB;AACnD,WAAO,IAAI,WAAW,IAAI,SAAS,IAAI;AAAA,EACzC;AAEA,SAAO,IAAI,SAAS;AACtB;","names":[]}
package/package.json CHANGED
@@ -1,29 +1,24 @@
1
1
  {
2
2
  "name": "@chriscdn/build-url",
3
- "version": "1.0.11",
3
+ "version": "2.0.0",
4
4
  "description": "A small utility for building URLs.",
5
5
  "repository": "https://github.com/chriscdn/build-url",
6
6
  "author": "Christopher Meyer <chris@schwiiz.org>",
7
7
  "license": "MIT",
8
8
  "type": "module",
9
- "source": "src/index.ts",
10
- "exports": {
11
- "types": "./lib/index.d.ts",
12
- "require": "./lib/build-url.cjs",
13
- "default": "./lib/build-url.modern.js"
14
- },
15
- "main": "./lib/build-url.cjs",
16
- "module": "./lib/build-url.module.js",
17
- "unpkg": "./lib/build-url.umd.js",
9
+ "main": "./lib/index.js",
18
10
  "types": "./lib/index.d.ts",
11
+ "exports": "./lib/index.js",
19
12
  "scripts": {
20
- "build": "rm -rf ./lib/ && microbundle",
21
- "dev": "microbundle watch",
13
+ "build": "tsup",
14
+ "watch": "yarn build --watch",
22
15
  "test": "vitest"
23
16
  },
24
17
  "devDependencies": {
25
- "microbundle": "^0.15.1",
26
- "vitest": "^4.0.6"
18
+ "@tsconfig/strictest": "^2.0.8",
19
+ "tsup": "^8.5.1",
20
+ "typescript": "^5.9.3",
21
+ "vitest": "^4.0.8"
27
22
  },
28
23
  "files": [
29
24
  "lib"
package/lib/build-url.cjs DELETED
@@ -1,2 +0,0 @@
1
- var e=function(e){return null==e};exports.buildUrl=function(a,r){var n,t=!1;try{n=new URL(a)}catch(e){if(t=!0,"string"==typeof a){var l="undefined"==typeof window?"http://example.com":window.location.origin;n=new URL(l+"/"+a.replace(/^\/|\/$/g,""))}else n="undefined"==typeof window?new URL("http://example.com"):new URL(window.location.href)}var o="string"==typeof a?r:a;if(null!=o&&o.queryParams)for(var h in o.queryParams)if(Object.prototype.hasOwnProperty.call(o.queryParams,h)){var i=o.queryParams[h];e(i)?n.searchParams.delete(h):n.searchParams.set(h,i)}return null!=o&&o.path&&(n.pathname=o.path),null===(null==o?void 0:o.path)&&(n.pathname=""),null!=o&&o.hash&&(n.hash=o.hash),!t||null!=o&&o.returnAbsoluteUrl?n.toString():n.pathname+n.search+n.hash};
2
- //# sourceMappingURL=build-url.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-url.cjs","sources":["../src/index.ts"],"sourcesContent":["export type UrlOptions = {\n queryParams?: {\n [x: string]: any;\n };\n hash?: string;\n path?: string | null;\n returnAbsoluteUrl?: boolean;\n};\n\nconst isEmpty = (value: any) => value === null || value === undefined;\n\nconst buildUrl = (\n inputUrl?: string | UrlOptions,\n options?: UrlOptions,\n) => {\n let url: URL;\n let isValidInputUrl = false;\n\n try {\n url = new URL(inputUrl as string);\n } catch (error) {\n isValidInputUrl = true;\n\n if (typeof inputUrl === \"string\") {\n const host = typeof window === \"undefined\"\n ? \"http://example.com\"\n : window.location.origin;\n\n url = new URL(`${host}/${inputUrl.replace(/^\\/|\\/$/g, \"\")}`);\n } else {\n url = typeof window === \"undefined\"\n ? new URL(\"http://example.com\")\n : new URL(window.location.href);\n }\n }\n\n const _options = typeof inputUrl === \"string\" ? options : inputUrl;\n\n if (_options?.queryParams) {\n for (const key in _options.queryParams) {\n if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {\n const element = _options.queryParams[key];\n\n if (isEmpty(element)) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, element);\n }\n }\n }\n }\n\n if (_options?.path) {\n url.pathname = _options.path;\n }\n\n if (_options?.path === null) {\n url.pathname = \"\";\n }\n\n if (_options?.hash) {\n url.hash = _options.hash;\n }\n\n if (isValidInputUrl && !_options?.returnAbsoluteUrl) {\n return url.pathname + url.search + url.hash;\n }\n\n return url.toString();\n};\n\nexport { buildUrl };\n"],"names":["isEmpty","value","inputUrl","options","url","isValidInputUrl","URL","error","host","window","location","origin","replace","href","_options","queryParams","key","Object","prototype","hasOwnProperty","call","element","searchParams","set","path","pathname","hash","returnAbsoluteUrl","toString","search"],"mappings":"AASA,IAAMA,EAAU,SAACC,GAAU,OAAKA,OAAqC,mBAEpD,SACfC,EACAC,GAEA,IAAIC,EACAC,GAAkB,EAEtB,IACED,EAAM,IAAIE,IAAIJ,EACf,CAAC,MAAOK,GAGP,GAFAF,GAAkB,EAEM,iBAAbH,EAAuB,CAChC,IAAMM,EAAyB,oBAAXC,OAChB,qBACAA,OAAOC,SAASC,OAEpBP,EAAM,IAAIE,IAAOE,EAAQN,IAAAA,EAASU,QAAQ,WAAY,IACvD,MACCR,EAAwB,oBAAXK,OACT,IAAIH,IAAI,sBACR,IAAIA,IAAIG,OAAOC,SAASG,KAE/B,CAED,IAAMC,EAA+B,iBAAbZ,EAAwBC,EAAUD,EAE1D,GAAIY,MAAAA,GAAAA,EAAUC,YACZ,IAAK,IAAMC,KAAOF,EAASC,YACzB,GAAIE,OAAOC,UAAUC,eAAeC,KAAKN,EAASC,YAAaC,GAAM,CACnE,IAAMK,EAAUP,EAASC,YAAYC,GAEjChB,EAAQqB,GACVjB,EAAIkB,oBAAoBN,GAExBZ,EAAIkB,aAAaC,IAAIP,EAAKK,EAE7B,CAgBL,OAZIP,MAAAA,GAAAA,EAAUU,OACZpB,EAAIqB,SAAWX,EAASU,MAGH,QAAnBV,MAAAA,OAAAA,EAAAA,EAAUU,QACZpB,EAAIqB,SAAW,IAGL,MAARX,GAAAA,EAAUY,OACZtB,EAAIsB,KAAOZ,EAASY,OAGlBrB,GAAoBS,MAAAA,GAAAA,EAAUa,kBAI3BvB,EAAIwB,WAHFxB,EAAIqB,SAAWrB,EAAIyB,OAASzB,EAAIsB,IAI3C"}
@@ -1,2 +0,0 @@
1
- const e=e=>null==e,t=(t,n)=>{let a,r=!1;try{a=new URL(t)}catch(e){if(r=!0,"string"==typeof t){const e="undefined"==typeof window?"http://example.com":window.location.origin;a=new URL(`${e}/${t.replace(/^\/|\/$/g,"")}`)}else a="undefined"==typeof window?new URL("http://example.com"):new URL(window.location.href)}const o="string"==typeof t?n:t;if(null!=o&&o.queryParams)for(const t in o.queryParams)if(Object.prototype.hasOwnProperty.call(o.queryParams,t)){const n=o.queryParams[t];e(n)?a.searchParams.delete(t):a.searchParams.set(t,n)}return null!=o&&o.path&&(a.pathname=o.path),null===(null==o?void 0:o.path)&&(a.pathname=""),null!=o&&o.hash&&(a.hash=o.hash),!r||null!=o&&o.returnAbsoluteUrl?a.toString():a.pathname+a.search+a.hash};export{t as buildUrl};
2
- //# sourceMappingURL=build-url.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-url.modern.js","sources":["../src/index.ts"],"sourcesContent":["export type UrlOptions = {\n queryParams?: {\n [x: string]: any;\n };\n hash?: string;\n path?: string | null;\n returnAbsoluteUrl?: boolean;\n};\n\nconst isEmpty = (value: any) => value === null || value === undefined;\n\nconst buildUrl = (\n inputUrl?: string | UrlOptions,\n options?: UrlOptions,\n) => {\n let url: URL;\n let isValidInputUrl = false;\n\n try {\n url = new URL(inputUrl as string);\n } catch (error) {\n isValidInputUrl = true;\n\n if (typeof inputUrl === \"string\") {\n const host = typeof window === \"undefined\"\n ? \"http://example.com\"\n : window.location.origin;\n\n url = new URL(`${host}/${inputUrl.replace(/^\\/|\\/$/g, \"\")}`);\n } else {\n url = typeof window === \"undefined\"\n ? new URL(\"http://example.com\")\n : new URL(window.location.href);\n }\n }\n\n const _options = typeof inputUrl === \"string\" ? options : inputUrl;\n\n if (_options?.queryParams) {\n for (const key in _options.queryParams) {\n if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {\n const element = _options.queryParams[key];\n\n if (isEmpty(element)) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, element);\n }\n }\n }\n }\n\n if (_options?.path) {\n url.pathname = _options.path;\n }\n\n if (_options?.path === null) {\n url.pathname = \"\";\n }\n\n if (_options?.hash) {\n url.hash = _options.hash;\n }\n\n if (isValidInputUrl && !_options?.returnAbsoluteUrl) {\n return url.pathname + url.search + url.hash;\n }\n\n return url.toString();\n};\n\nexport { buildUrl };\n"],"names":["isEmpty","value","buildUrl","inputUrl","options","url","isValidInputUrl","URL","error","host","window","location","origin","replace","href","_options","queryParams","key","Object","prototype","hasOwnProperty","call","element","searchParams","delete","set","path","pathname","hash","returnAbsoluteUrl","toString","search"],"mappings":"AASA,MAAMA,EAAWC,GAAeA,QAE1BC,EAAWA,CACfC,EACAC,KAEA,IAAIC,EACAC,GAAkB,EAEtB,IACED,EAAM,IAAIE,IAAIJ,EACf,CAAC,MAAOK,GAGP,GAFAF,GAAkB,EAEM,iBAAbH,EAAuB,CAChC,MAAMM,EAAyB,oBAAXC,OAChB,qBACAA,OAAOC,SAASC,OAEpBP,EAAM,IAAIE,IAAI,GAAGE,KAAQN,EAASU,QAAQ,WAAY,MACvD,MACCR,EAAwB,oBAAXK,OACT,IAAIH,IAAI,sBACR,IAAIA,IAAIG,OAAOC,SAASG,KAE/B,CAED,MAAMC,EAA+B,iBAAbZ,EAAwBC,EAAUD,EAE1D,GAAY,MAARY,GAAAA,EAAUC,YACZ,IAAK,MAAMC,KAAOF,EAASC,YACzB,GAAIE,OAAOC,UAAUC,eAAeC,KAAKN,EAASC,YAAaC,GAAM,CACnE,MAAMK,EAAUP,EAASC,YAAYC,GAEjCjB,EAAQsB,GACVjB,EAAIkB,aAAaC,OAAOP,GAExBZ,EAAIkB,aAAaE,IAAIR,EAAKK,EAE7B,CAgBL,OAZIP,MAAAA,GAAAA,EAAUW,OACZrB,EAAIsB,SAAWZ,EAASW,MAGH,QAAX,MAARX,OAAQ,EAARA,EAAUW,QACZrB,EAAIsB,SAAW,IAGbZ,MAAAA,GAAAA,EAAUa,OACZvB,EAAIuB,KAAOb,EAASa,OAGlBtB,GAAoBS,MAAAA,GAAAA,EAAUc,kBAI3BxB,EAAIyB,WAHFzB,EAAIsB,SAAWtB,EAAI0B,OAAS1B,EAAIuB"}
@@ -1,2 +0,0 @@
1
- var e=function(e){return null==e},a=function(a,r){var n,t=!1;try{n=new URL(a)}catch(e){if(t=!0,"string"==typeof a){var l="undefined"==typeof window?"http://example.com":window.location.origin;n=new URL(l+"/"+a.replace(/^\/|\/$/g,""))}else n="undefined"==typeof window?new URL("http://example.com"):new URL(window.location.href)}var o="string"==typeof a?r:a;if(null!=o&&o.queryParams)for(var h in o.queryParams)if(Object.prototype.hasOwnProperty.call(o.queryParams,h)){var i=o.queryParams[h];e(i)?n.searchParams.delete(h):n.searchParams.set(h,i)}return null!=o&&o.path&&(n.pathname=o.path),null===(null==o?void 0:o.path)&&(n.pathname=""),null!=o&&o.hash&&(n.hash=o.hash),!t||null!=o&&o.returnAbsoluteUrl?n.toString():n.pathname+n.search+n.hash};export{a as buildUrl};
2
- //# sourceMappingURL=build-url.module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-url.module.js","sources":["../src/index.ts"],"sourcesContent":["export type UrlOptions = {\n queryParams?: {\n [x: string]: any;\n };\n hash?: string;\n path?: string | null;\n returnAbsoluteUrl?: boolean;\n};\n\nconst isEmpty = (value: any) => value === null || value === undefined;\n\nconst buildUrl = (\n inputUrl?: string | UrlOptions,\n options?: UrlOptions,\n) => {\n let url: URL;\n let isValidInputUrl = false;\n\n try {\n url = new URL(inputUrl as string);\n } catch (error) {\n isValidInputUrl = true;\n\n if (typeof inputUrl === \"string\") {\n const host = typeof window === \"undefined\"\n ? \"http://example.com\"\n : window.location.origin;\n\n url = new URL(`${host}/${inputUrl.replace(/^\\/|\\/$/g, \"\")}`);\n } else {\n url = typeof window === \"undefined\"\n ? new URL(\"http://example.com\")\n : new URL(window.location.href);\n }\n }\n\n const _options = typeof inputUrl === \"string\" ? options : inputUrl;\n\n if (_options?.queryParams) {\n for (const key in _options.queryParams) {\n if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {\n const element = _options.queryParams[key];\n\n if (isEmpty(element)) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, element);\n }\n }\n }\n }\n\n if (_options?.path) {\n url.pathname = _options.path;\n }\n\n if (_options?.path === null) {\n url.pathname = \"\";\n }\n\n if (_options?.hash) {\n url.hash = _options.hash;\n }\n\n if (isValidInputUrl && !_options?.returnAbsoluteUrl) {\n return url.pathname + url.search + url.hash;\n }\n\n return url.toString();\n};\n\nexport { buildUrl };\n"],"names":["isEmpty","value","buildUrl","inputUrl","options","url","isValidInputUrl","URL","error","host","window","location","origin","replace","href","_options","queryParams","key","Object","prototype","hasOwnProperty","call","element","searchParams","set","path","pathname","hash","returnAbsoluteUrl","toString","search"],"mappings":"AASA,IAAMA,EAAU,SAACC,GAAU,OAAKA,OAAqC,EAE/DC,EAAW,SACfC,EACAC,GAEA,IAAIC,EACAC,GAAkB,EAEtB,IACED,EAAM,IAAIE,IAAIJ,EACf,CAAC,MAAOK,GAGP,GAFAF,GAAkB,EAEM,iBAAbH,EAAuB,CAChC,IAAMM,EAAyB,oBAAXC,OAChB,qBACAA,OAAOC,SAASC,OAEpBP,EAAM,IAAIE,IAAOE,EAAQN,IAAAA,EAASU,QAAQ,WAAY,IACvD,MACCR,EAAwB,oBAAXK,OACT,IAAIH,IAAI,sBACR,IAAIA,IAAIG,OAAOC,SAASG,KAE/B,CAED,IAAMC,EAA+B,iBAAbZ,EAAwBC,EAAUD,EAE1D,GAAIY,MAAAA,GAAAA,EAAUC,YACZ,IAAK,IAAMC,KAAOF,EAASC,YACzB,GAAIE,OAAOC,UAAUC,eAAeC,KAAKN,EAASC,YAAaC,GAAM,CACnE,IAAMK,EAAUP,EAASC,YAAYC,GAEjCjB,EAAQsB,GACVjB,EAAIkB,oBAAoBN,GAExBZ,EAAIkB,aAAaC,IAAIP,EAAKK,EAE7B,CAgBL,OAZIP,MAAAA,GAAAA,EAAUU,OACZpB,EAAIqB,SAAWX,EAASU,MAGH,QAAnBV,MAAAA,OAAAA,EAAAA,EAAUU,QACZpB,EAAIqB,SAAW,IAGL,MAARX,GAAAA,EAAUY,OACZtB,EAAIsB,KAAOZ,EAASY,OAGlBrB,GAAoBS,MAAAA,GAAAA,EAAUa,kBAI3BvB,EAAIwB,WAHFxB,EAAIqB,SAAWrB,EAAIyB,OAASzB,EAAIsB,IAI3C"}
@@ -1,2 +0,0 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).buildUrl={})}(this,function(e){var n=function(e){return null==e};e.buildUrl=function(e,t){var a,r=!1;try{a=new URL(e)}catch(n){if(r=!0,"string"==typeof e){var o="undefined"==typeof window?"http://example.com":window.location.origin;a=new URL(o+"/"+e.replace(/^\/|\/$/g,""))}else a="undefined"==typeof window?new URL("http://example.com"):new URL(window.location.href)}var l="string"==typeof e?t:e;if(null!=l&&l.queryParams)for(var i in l.queryParams)if(Object.prototype.hasOwnProperty.call(l.queryParams,i)){var u=l.queryParams[i];n(u)?a.searchParams.delete(i):a.searchParams.set(i,u)}return null!=l&&l.path&&(a.pathname=l.path),null===(null==l?void 0:l.path)&&(a.pathname=""),null!=l&&l.hash&&(a.hash=l.hash),!r||null!=l&&l.returnAbsoluteUrl?a.toString():a.pathname+a.search+a.hash}});
2
- //# sourceMappingURL=build-url.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-url.umd.js","sources":["../src/index.ts"],"sourcesContent":["export type UrlOptions = {\n queryParams?: {\n [x: string]: any;\n };\n hash?: string;\n path?: string | null;\n returnAbsoluteUrl?: boolean;\n};\n\nconst isEmpty = (value: any) => value === null || value === undefined;\n\nconst buildUrl = (\n inputUrl?: string | UrlOptions,\n options?: UrlOptions,\n) => {\n let url: URL;\n let isValidInputUrl = false;\n\n try {\n url = new URL(inputUrl as string);\n } catch (error) {\n isValidInputUrl = true;\n\n if (typeof inputUrl === \"string\") {\n const host = typeof window === \"undefined\"\n ? \"http://example.com\"\n : window.location.origin;\n\n url = new URL(`${host}/${inputUrl.replace(/^\\/|\\/$/g, \"\")}`);\n } else {\n url = typeof window === \"undefined\"\n ? new URL(\"http://example.com\")\n : new URL(window.location.href);\n }\n }\n\n const _options = typeof inputUrl === \"string\" ? options : inputUrl;\n\n if (_options?.queryParams) {\n for (const key in _options.queryParams) {\n if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {\n const element = _options.queryParams[key];\n\n if (isEmpty(element)) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, element);\n }\n }\n }\n }\n\n if (_options?.path) {\n url.pathname = _options.path;\n }\n\n if (_options?.path === null) {\n url.pathname = \"\";\n }\n\n if (_options?.hash) {\n url.hash = _options.hash;\n }\n\n if (isValidInputUrl && !_options?.returnAbsoluteUrl) {\n return url.pathname + url.search + url.hash;\n }\n\n return url.toString();\n};\n\nexport { buildUrl };\n"],"names":["isEmpty","value","inputUrl","options","url","isValidInputUrl","URL","error","host","window","location","origin","replace","href","_options","queryParams","key","Object","prototype","hasOwnProperty","call","element","searchParams","set","path","pathname","hash","returnAbsoluteUrl","toString","search"],"mappings":"kOASA,IAAMA,EAAU,SAACC,GAAU,OAAKA,OAAqC,aAEpD,SACfC,EACAC,GAEA,IAAIC,EACAC,GAAkB,EAEtB,IACED,EAAM,IAAIE,IAAIJ,EACf,CAAC,MAAOK,GAGP,GAFAF,GAAkB,EAEM,iBAAbH,EAAuB,CAChC,IAAMM,EAAyB,oBAAXC,OAChB,qBACAA,OAAOC,SAASC,OAEpBP,EAAM,IAAIE,IAAOE,EAAQN,IAAAA,EAASU,QAAQ,WAAY,IACvD,MACCR,EAAwB,oBAAXK,OACT,IAAIH,IAAI,sBACR,IAAIA,IAAIG,OAAOC,SAASG,KAE/B,CAED,IAAMC,EAA+B,iBAAbZ,EAAwBC,EAAUD,EAE1D,GAAIY,MAAAA,GAAAA,EAAUC,YACZ,IAAK,IAAMC,KAAOF,EAASC,YACzB,GAAIE,OAAOC,UAAUC,eAAeC,KAAKN,EAASC,YAAaC,GAAM,CACnE,IAAMK,EAAUP,EAASC,YAAYC,GAEjChB,EAAQqB,GACVjB,EAAIkB,oBAAoBN,GAExBZ,EAAIkB,aAAaC,IAAIP,EAAKK,EAE7B,CAgBL,OAZIP,MAAAA,GAAAA,EAAUU,OACZpB,EAAIqB,SAAWX,EAASU,MAGH,QAAnBV,MAAAA,OAAAA,EAAAA,EAAUU,QACZpB,EAAIqB,SAAW,IAGL,MAARX,GAAAA,EAAUY,OACZtB,EAAIsB,KAAOZ,EAASY,OAGlBrB,GAAoBS,MAAAA,GAAAA,EAAUa,kBAI3BvB,EAAIwB,WAHFxB,EAAIqB,SAAWrB,EAAIyB,OAASzB,EAAIsB,IAI3C"}