@chriscdn/build-url 1.0.11 → 1.0.12

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/index.cjs ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ buildUrl: () => buildUrl
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var isEmpty = (value) => value === null || value === void 0;
27
+ var buildUrl = (inputUrl, options) => {
28
+ let url;
29
+ let isValidInputUrl = false;
30
+ try {
31
+ url = new URL(inputUrl);
32
+ } catch (error) {
33
+ isValidInputUrl = true;
34
+ if (typeof inputUrl === "string") {
35
+ const host = typeof window === "undefined" ? "http://example.com" : window.location.origin;
36
+ url = new URL(`${host}/${inputUrl.replace(/^\/|\/$/g, "")}`);
37
+ } else {
38
+ url = typeof window === "undefined" ? new URL("http://example.com") : new URL(window.location.href);
39
+ }
40
+ }
41
+ const _options = typeof inputUrl === "string" ? options : inputUrl;
42
+ if (_options?.queryParams) {
43
+ for (const key in _options.queryParams) {
44
+ if (Object.prototype.hasOwnProperty.call(_options.queryParams, key)) {
45
+ const element = _options.queryParams[key];
46
+ if (isEmpty(element)) {
47
+ url.searchParams.delete(key);
48
+ } else {
49
+ url.searchParams.set(key, element);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ if (_options?.path) {
55
+ url.pathname = _options.path;
56
+ }
57
+ if (_options?.path === null) {
58
+ url.pathname = "";
59
+ }
60
+ if (_options?.hash) {
61
+ url.hash = _options.hash;
62
+ }
63
+ if (isValidInputUrl && !_options?.returnAbsoluteUrl) {
64
+ return url.pathname + url.search + url.hash;
65
+ }
66
+ return url.toString();
67
+ };
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ buildUrl
71
+ });
72
+ //# sourceMappingURL=index.cjs.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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":[]}
@@ -0,0 +1,11 @@
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.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,36 @@
1
1
  {
2
2
  "name": "@chriscdn/build-url",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
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",
9
+ "main": "./lib/index.cjs",
10
+ "module": "./lib/index.js",
11
+ "types": "./lib/index.d.ts",
10
12
  "exports": {
11
- "types": "./lib/index.d.ts",
12
- "require": "./lib/build-url.cjs",
13
- "default": "./lib/build-url.modern.js"
13
+ ".": {
14
+ "import": {
15
+ "types": "./lib/index.d.ts",
16
+ "default": "./lib/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./lib/index.d.cts",
20
+ "default": "./lib/index.cjs"
21
+ }
22
+ }
14
23
  },
15
- "main": "./lib/build-url.cjs",
16
- "module": "./lib/build-url.module.js",
17
- "unpkg": "./lib/build-url.umd.js",
18
- "types": "./lib/index.d.ts",
19
24
  "scripts": {
20
- "build": "rm -rf ./lib/ && microbundle",
21
- "dev": "microbundle watch",
25
+ "build": "tsup",
26
+ "watch": "yarn build --watch",
22
27
  "test": "vitest"
23
28
  },
24
29
  "devDependencies": {
25
- "microbundle": "^0.15.1",
26
- "vitest": "^4.0.6"
30
+ "@tsconfig/strictest": "^2.0.8",
31
+ "tsup": "^8.5.1",
32
+ "typescript": "^5.9.3",
33
+ "vitest": "^4.0.8"
27
34
  },
28
35
  "files": [
29
36
  "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"}