@fluixi/utils 1.0.0-alpha.82 → 1.0.0-alpha.84

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.
Files changed (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1 +1,18 @@
1
- "use strict";var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var T=(t,e,x,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!g.call(t,n)&&n!==x&&s(t,n,{get:()=>e[n],enumerable:!(r=i(e,n))||r.enumerable});return t};var p=t=>T(s({},"__esModule",{value:!0}),t);var u={};module.exports=p(u);
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/lib/primitive/string/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -1 +1,18 @@
1
- "use strict";var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var y=(n,e,d,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of l(e))!p.call(n,t)&&t!==d&&s(n,t,{get:()=>e[t],enumerable:!(r=i(e,t))||r.enumerable});return n};var u=n=>y(s({},"__esModule",{value:!0}),n);var a={};module.exports=u(a);
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/lib/primitive/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -1 +1,327 @@
1
- "use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var R=(t,r)=>{for(var n in r)l(t,n,{get:r[n],enumerable:!0})},b=(t,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of m(r))!f.call(t,e)&&e!==n&&l(t,e,{get:()=>r[e],enumerable:!(s=p(r,e))||s.enumerable});return t};var d=t=>b(l({},"__esModule",{value:!0}),t);var I={};R(I,{addQueryParams:()=>j,buildUrl:()=>A,extractUrls:()=>B,getDomain:()=>Q,getQueryParam:()=>L,getQueryParams:()=>O,getUrlExtension:()=>q,isAbsoluteUrl:()=>g,isRelativeUrl:()=>x,isSameOrigin:()=>D,isValidUrl:()=>P,joinUrl:()=>$,matchesUrlPattern:()=>C,normalizeUrl:()=>E,parseQueryString:()=>y,parseQueryStringAdvanced:()=>S,parseUrl:()=>U,removeQueryParams:()=>w,sanitizeUrl:()=>_,toAbsoluteUrl:()=>W,toQueryString:()=>h,url_parser:()=>u});module.exports=d(I);var u=t=>{try{let r=new URL(t);return{hash:r.hash,host:r.host,hostname:r.hostname,href:r.href,origin:r.origin,pathname:r.pathname,port:r.port,search:r.search,searchParams:r.searchParams.toString(),protocol:r.protocol}}catch{return null}};function U(t){return u(t)}function P(t){try{return new URL(t),!0}catch{return!1}}function g(t){try{return new URL(t),!0}catch{return!1}}function x(t){return!g(t)}function y(t){let r={};return new URLSearchParams(t).forEach((s,e)=>{r[e]=s}),r}function S(t){let r={};return new URLSearchParams(t).forEach((s,e)=>{r[e]?Array.isArray(r[e])?r[e].push(s):r[e]=[r[e],s]:r[e]=s}),r}function h(t,r={}){let{encode:n=!0,arrayFormat:s="repeat"}=r,e=new URLSearchParams;Object.entries(t).forEach(([i,o])=>{o!=null&&(Array.isArray(o)?o.forEach(c=>{s==="brackets"?e.append(`${i}[]`,String(c)):e.append(i,String(c))}):e.append(i,String(o)))});let a=e.toString();return n||(a=decodeURIComponent(a)),a}function j(t,r){try{let n=new URL(t);return Object.entries(r).forEach(([s,e])=>{e==null?n.searchParams.delete(s):Array.isArray(e)?(n.searchParams.delete(s),e.forEach(a=>n.searchParams.append(s,String(a)))):n.searchParams.set(s,String(e))}),n.toString()}catch{return t}}function w(t,...r){try{let n=new URL(t);return r.forEach(s=>n.searchParams.delete(s)),n.toString()}catch{return t}}function L(t,r){try{return new URL(t).searchParams.get(r)}catch{return null}}function O(t,r){try{return new URL(t).searchParams.getAll(r)}catch{return[]}}function A(t){let{protocol:r="https",hostname:n,port:s,pathname:e="",query:a,hash:i}=t,o=`${r}://${n}`;return s&&(o+=`:${s}`),e&&(o+=e.startsWith("/")?e:`/${e}`),a&&Object.keys(a).length>0&&(o+=`?${h(a)}`),i&&(o+=i.startsWith("#")?i:`#${i}`),o}function $(t,...r){try{let n=new URL(t),e=[n.pathname==="/"?"":n.pathname,...r].filter(Boolean).map(a=>a.replace(/^\/+|\/+$/g,""));return n.pathname="/"+e.filter(Boolean).join("/"),n.toString()}catch{return"/"+[t,...r].filter(Boolean).map(s=>s.replace(/^\/+|\/+$/g,"")).join("/")}}function E(t,r={}){let{removeTrailingSlash:n=!0,removeDefaultPort:s=!0,sortQuery:e=!1}=r;try{let a=new URL(t);if(s&&(a.protocol==="http:"&&a.port==="80"||a.protocol==="https:"&&a.port==="443")&&(a.port=""),n&&a.pathname.endsWith("/")&&a.pathname!=="/"&&(a.pathname=a.pathname.slice(0,-1)),e){let i=Array.from(a.searchParams.entries());i.sort((o,c)=>o[0].localeCompare(c[0])),a.search=new URLSearchParams(i).toString()}return a.toString()}catch{return t}}function Q(t,r={}){let{includeSubdomain:n=!1}=r;try{let e=new URL(t).hostname;if(n)return e;let a=e.split(".");return a.length>=2?a.slice(-2).join("."):e}catch{return null}}function q(t){try{let n=new URL(t).pathname,s=n.lastIndexOf("."),e=n.lastIndexOf("/");return s>e&&s<n.length-1?n.slice(s+1):null}catch{return null}}function D(t,r){try{let n=new URL(t),s=new URL(r);return n.origin===s.origin}catch{return!1}}function W(t,r){try{return new URL(t,r).toString()}catch{return t}}function _(t){let r=["javascript:","data:","vbscript:"];try{let n=new URL(t);return r.some(s=>n.protocol===s)?null:t}catch{let n=t.toLowerCase().trim();return r.some(s=>n.startsWith(s))?null:t}}function B(t,r={}){let{unique:n=!0}=r,s=/https?:\/\/[^\s<>"{}|\\^`\]]+/gi,e=t.match(s)||[];return n?Array.from(new Set(e)):e}function C(t,r){try{let n=new URL(t),s=new URL(r);if(s.protocol!=="*:"&&n.protocol!==s.protocol||s.hostname!=="*"&&n.hostname!==s.hostname)return!1;let e=s.pathname.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*").replace(/[.+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${e}$`).test(n.pathname)}catch{return!1}}
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/lib/url/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ addQueryParams: () => addQueryParams,
24
+ buildUrl: () => buildUrl,
25
+ extractUrls: () => extractUrls,
26
+ getDomain: () => getDomain,
27
+ getQueryParam: () => getQueryParam,
28
+ getQueryParams: () => getQueryParams,
29
+ getUrlExtension: () => getUrlExtension,
30
+ isAbsoluteUrl: () => isAbsoluteUrl,
31
+ isRelativeUrl: () => isRelativeUrl,
32
+ isSameOrigin: () => isSameOrigin,
33
+ isValidUrl: () => isValidUrl,
34
+ joinUrl: () => joinUrl,
35
+ matchesUrlPattern: () => matchesUrlPattern,
36
+ normalizeUrl: () => normalizeUrl,
37
+ parseQueryString: () => parseQueryString,
38
+ parseQueryStringAdvanced: () => parseQueryStringAdvanced,
39
+ parseUrl: () => parseUrl,
40
+ removeQueryParams: () => removeQueryParams,
41
+ sanitizeUrl: () => sanitizeUrl,
42
+ toAbsoluteUrl: () => toAbsoluteUrl,
43
+ toQueryString: () => toQueryString,
44
+ url_parser: () => url_parser
45
+ });
46
+ module.exports = __toCommonJS(index_exports);
47
+
48
+ // src/lib/url/parser.ts
49
+ var url_parser = (url) => {
50
+ try {
51
+ const p = new URL(url);
52
+ return {
53
+ hash: p.hash,
54
+ host: p.host,
55
+ hostname: p.hostname,
56
+ href: p.href,
57
+ origin: p.origin,
58
+ pathname: p.pathname,
59
+ port: p.port,
60
+ search: p.search,
61
+ searchParams: p.searchParams.toString(),
62
+ protocol: p.protocol
63
+ };
64
+ } catch (e) {
65
+ return null;
66
+ }
67
+ };
68
+ function parseUrl(url) {
69
+ return url_parser(url);
70
+ }
71
+ function isValidUrl(url) {
72
+ try {
73
+ new URL(url);
74
+ return true;
75
+ } catch {
76
+ return false;
77
+ }
78
+ }
79
+ function isAbsoluteUrl(url) {
80
+ try {
81
+ new URL(url);
82
+ return true;
83
+ } catch {
84
+ return false;
85
+ }
86
+ }
87
+ function isRelativeUrl(url) {
88
+ return !isAbsoluteUrl(url);
89
+ }
90
+ function parseQueryString(queryString) {
91
+ const params = {};
92
+ const searchParams = new URLSearchParams(queryString);
93
+ searchParams.forEach((value, key) => {
94
+ params[key] = value;
95
+ });
96
+ return params;
97
+ }
98
+ function parseQueryStringAdvanced(queryString) {
99
+ const params = {};
100
+ const searchParams = new URLSearchParams(queryString);
101
+ searchParams.forEach((value, key) => {
102
+ if (params[key]) {
103
+ if (Array.isArray(params[key])) {
104
+ params[key].push(value);
105
+ } else {
106
+ params[key] = [params[key], value];
107
+ }
108
+ } else {
109
+ params[key] = value;
110
+ }
111
+ });
112
+ return params;
113
+ }
114
+ function toQueryString(params, options = {}) {
115
+ const { encode = true, arrayFormat = "repeat" } = options;
116
+ const searchParams = new URLSearchParams();
117
+ Object.entries(params).forEach(([key, value]) => {
118
+ if (value === null || value === void 0) return;
119
+ if (Array.isArray(value)) {
120
+ value.forEach((v) => {
121
+ if (arrayFormat === "brackets") {
122
+ searchParams.append(`${key}[]`, String(v));
123
+ } else {
124
+ searchParams.append(key, String(v));
125
+ }
126
+ });
127
+ } else {
128
+ searchParams.append(key, String(value));
129
+ }
130
+ });
131
+ let result = searchParams.toString();
132
+ if (!encode) {
133
+ result = decodeURIComponent(result);
134
+ }
135
+ return result;
136
+ }
137
+ function addQueryParams(url, params) {
138
+ try {
139
+ const urlObj = new URL(url);
140
+ Object.entries(params).forEach(([key, value]) => {
141
+ if (value === null || value === void 0) {
142
+ urlObj.searchParams.delete(key);
143
+ } else if (Array.isArray(value)) {
144
+ urlObj.searchParams.delete(key);
145
+ value.forEach((v) => urlObj.searchParams.append(key, String(v)));
146
+ } else {
147
+ urlObj.searchParams.set(key, String(value));
148
+ }
149
+ });
150
+ return urlObj.toString();
151
+ } catch {
152
+ return url;
153
+ }
154
+ }
155
+ function removeQueryParams(url, ...keys) {
156
+ try {
157
+ const urlObj = new URL(url);
158
+ keys.forEach((key) => urlObj.searchParams.delete(key));
159
+ return urlObj.toString();
160
+ } catch {
161
+ return url;
162
+ }
163
+ }
164
+ function getQueryParam(url, key) {
165
+ try {
166
+ const urlObj = new URL(url);
167
+ return urlObj.searchParams.get(key);
168
+ } catch {
169
+ return null;
170
+ }
171
+ }
172
+ function getQueryParams(url, key) {
173
+ try {
174
+ const urlObj = new URL(url);
175
+ return urlObj.searchParams.getAll(key);
176
+ } catch {
177
+ return [];
178
+ }
179
+ }
180
+ function buildUrl(components) {
181
+ const {
182
+ protocol = "https",
183
+ hostname,
184
+ port,
185
+ pathname = "",
186
+ query,
187
+ hash
188
+ } = components;
189
+ let url = `${protocol}://${hostname}`;
190
+ if (port) {
191
+ url += `:${port}`;
192
+ }
193
+ if (pathname) {
194
+ url += pathname.startsWith("/") ? pathname : `/${pathname}`;
195
+ }
196
+ if (query && Object.keys(query).length > 0) {
197
+ url += `?${toQueryString(query)}`;
198
+ }
199
+ if (hash) {
200
+ url += hash.startsWith("#") ? hash : `#${hash}`;
201
+ }
202
+ return url;
203
+ }
204
+ function joinUrl(base, ...paths) {
205
+ try {
206
+ const url = new URL(base);
207
+ const basePath = url.pathname === "/" ? "" : url.pathname;
208
+ const pathParts = [basePath, ...paths].filter(Boolean).map((part) => part.replace(/^\/+|\/+$/g, ""));
209
+ url.pathname = "/" + pathParts.filter(Boolean).join("/");
210
+ return url.toString();
211
+ } catch {
212
+ const parts = [base, ...paths].filter(Boolean).map((part) => part.replace(/^\/+|\/+$/g, ""));
213
+ return "/" + parts.join("/");
214
+ }
215
+ }
216
+ function normalizeUrl(url, options = {}) {
217
+ const {
218
+ removeTrailingSlash = true,
219
+ removeDefaultPort = true,
220
+ sortQuery = false
221
+ } = options;
222
+ try {
223
+ const urlObj = new URL(url);
224
+ if (removeDefaultPort) {
225
+ if (urlObj.protocol === "http:" && urlObj.port === "80" || urlObj.protocol === "https:" && urlObj.port === "443") {
226
+ urlObj.port = "";
227
+ }
228
+ }
229
+ if (removeTrailingSlash && urlObj.pathname.endsWith("/") && urlObj.pathname !== "/") {
230
+ urlObj.pathname = urlObj.pathname.slice(0, -1);
231
+ }
232
+ if (sortQuery) {
233
+ const params = Array.from(urlObj.searchParams.entries());
234
+ params.sort((a, b) => a[0].localeCompare(b[0]));
235
+ urlObj.search = new URLSearchParams(params).toString();
236
+ }
237
+ return urlObj.toString();
238
+ } catch {
239
+ return url;
240
+ }
241
+ }
242
+ function getDomain(url, options = {}) {
243
+ const { includeSubdomain = false } = options;
244
+ try {
245
+ const urlObj = new URL(url);
246
+ const hostname = urlObj.hostname;
247
+ if (includeSubdomain) {
248
+ return hostname;
249
+ }
250
+ const parts = hostname.split(".");
251
+ if (parts.length >= 2) {
252
+ return parts.slice(-2).join(".");
253
+ }
254
+ return hostname;
255
+ } catch {
256
+ return null;
257
+ }
258
+ }
259
+ function getUrlExtension(url) {
260
+ try {
261
+ const urlObj = new URL(url);
262
+ const pathname = urlObj.pathname;
263
+ const lastDot = pathname.lastIndexOf(".");
264
+ const lastSlash = pathname.lastIndexOf("/");
265
+ if (lastDot > lastSlash && lastDot < pathname.length - 1) {
266
+ return pathname.slice(lastDot + 1);
267
+ }
268
+ return null;
269
+ } catch {
270
+ return null;
271
+ }
272
+ }
273
+ function isSameOrigin(url1, url2) {
274
+ try {
275
+ const urlObj1 = new URL(url1);
276
+ const urlObj2 = new URL(url2);
277
+ return urlObj1.origin === urlObj2.origin;
278
+ } catch {
279
+ return false;
280
+ }
281
+ }
282
+ function toAbsoluteUrl(relativeUrl, baseUrl) {
283
+ try {
284
+ return new URL(relativeUrl, baseUrl).toString();
285
+ } catch {
286
+ return relativeUrl;
287
+ }
288
+ }
289
+ function sanitizeUrl(url) {
290
+ const dangerousProtocols = ["javascript:", "data:", "vbscript:"];
291
+ try {
292
+ const urlObj = new URL(url);
293
+ if (dangerousProtocols.some((proto) => urlObj.protocol === proto)) {
294
+ return null;
295
+ }
296
+ return url;
297
+ } catch {
298
+ const lower = url.toLowerCase().trim();
299
+ if (dangerousProtocols.some((proto) => lower.startsWith(proto))) {
300
+ return null;
301
+ }
302
+ return url;
303
+ }
304
+ }
305
+ function extractUrls(text, options = {}) {
306
+ const { unique = true } = options;
307
+ const urlRegex = /https?:\/\/[^\s<>"{}|\\^`\]]+/gi;
308
+ const matches = text.match(urlRegex) || [];
309
+ return unique ? Array.from(new Set(matches)) : matches;
310
+ }
311
+ function matchesUrlPattern(url, pattern) {
312
+ try {
313
+ const urlObj = new URL(url);
314
+ const patternObj = new URL(pattern);
315
+ if (patternObj.protocol !== "*:" && urlObj.protocol !== patternObj.protocol) {
316
+ return false;
317
+ }
318
+ if (patternObj.hostname !== "*" && urlObj.hostname !== patternObj.hostname) {
319
+ return false;
320
+ }
321
+ const pathPattern = patternObj.pathname.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/[.+?^${}()|[\]\\]/g, "\\$&");
322
+ const pathRegex = new RegExp(`^${pathPattern}$`);
323
+ return pathRegex.test(urlObj.pathname);
324
+ } catch {
325
+ return false;
326
+ }
327
+ }
@@ -1 +1,304 @@
1
- var l=t=>{try{let r=new URL(t);return{hash:r.hash,host:r.host,hostname:r.hostname,href:r.href,origin:r.origin,pathname:r.pathname,port:r.port,search:r.search,searchParams:r.searchParams.toString(),protocol:r.protocol}}catch{return null}};function h(t){return l(t)}function p(t){try{return new URL(t),!0}catch{return!1}}function u(t){try{return new URL(t),!0}catch{return!1}}function m(t){return!u(t)}function f(t){let r={};return new URLSearchParams(t).forEach((e,s)=>{r[s]=e}),r}function R(t){let r={};return new URLSearchParams(t).forEach((e,s)=>{r[s]?Array.isArray(r[s])?r[s].push(e):r[s]=[r[s],e]:r[s]=e}),r}function g(t,r={}){let{encode:n=!0,arrayFormat:e="repeat"}=r,s=new URLSearchParams;Object.entries(t).forEach(([i,o])=>{o!=null&&(Array.isArray(o)?o.forEach(c=>{e==="brackets"?s.append(`${i}[]`,String(c)):s.append(i,String(c))}):s.append(i,String(o)))});let a=s.toString();return n||(a=decodeURIComponent(a)),a}function b(t,r){try{let n=new URL(t);return Object.entries(r).forEach(([e,s])=>{s==null?n.searchParams.delete(e):Array.isArray(s)?(n.searchParams.delete(e),s.forEach(a=>n.searchParams.append(e,String(a)))):n.searchParams.set(e,String(s))}),n.toString()}catch{return t}}function d(t,...r){try{let n=new URL(t);return r.forEach(e=>n.searchParams.delete(e)),n.toString()}catch{return t}}function U(t,r){try{return new URL(t).searchParams.get(r)}catch{return null}}function P(t,r){try{return new URL(t).searchParams.getAll(r)}catch{return[]}}function x(t){let{protocol:r="https",hostname:n,port:e,pathname:s="",query:a,hash:i}=t,o=`${r}://${n}`;return e&&(o+=`:${e}`),s&&(o+=s.startsWith("/")?s:`/${s}`),a&&Object.keys(a).length>0&&(o+=`?${g(a)}`),i&&(o+=i.startsWith("#")?i:`#${i}`),o}function y(t,...r){try{let n=new URL(t),s=[n.pathname==="/"?"":n.pathname,...r].filter(Boolean).map(a=>a.replace(/^\/+|\/+$/g,""));return n.pathname="/"+s.filter(Boolean).join("/"),n.toString()}catch{return"/"+[t,...r].filter(Boolean).map(e=>e.replace(/^\/+|\/+$/g,"")).join("/")}}function S(t,r={}){let{removeTrailingSlash:n=!0,removeDefaultPort:e=!0,sortQuery:s=!1}=r;try{let a=new URL(t);if(e&&(a.protocol==="http:"&&a.port==="80"||a.protocol==="https:"&&a.port==="443")&&(a.port=""),n&&a.pathname.endsWith("/")&&a.pathname!=="/"&&(a.pathname=a.pathname.slice(0,-1)),s){let i=Array.from(a.searchParams.entries());i.sort((o,c)=>o[0].localeCompare(c[0])),a.search=new URLSearchParams(i).toString()}return a.toString()}catch{return t}}function j(t,r={}){let{includeSubdomain:n=!1}=r;try{let s=new URL(t).hostname;if(n)return s;let a=s.split(".");return a.length>=2?a.slice(-2).join("."):s}catch{return null}}function w(t){try{let n=new URL(t).pathname,e=n.lastIndexOf("."),s=n.lastIndexOf("/");return e>s&&e<n.length-1?n.slice(e+1):null}catch{return null}}function L(t,r){try{let n=new URL(t),e=new URL(r);return n.origin===e.origin}catch{return!1}}function O(t,r){try{return new URL(t,r).toString()}catch{return t}}function A(t){let r=["javascript:","data:","vbscript:"];try{let n=new URL(t);return r.some(e=>n.protocol===e)?null:t}catch{let n=t.toLowerCase().trim();return r.some(e=>n.startsWith(e))?null:t}}function $(t,r={}){let{unique:n=!0}=r,e=/https?:\/\/[^\s<>"{}|\\^`\]]+/gi,s=t.match(e)||[];return n?Array.from(new Set(s)):s}function E(t,r){try{let n=new URL(t),e=new URL(r);if(e.protocol!=="*:"&&n.protocol!==e.protocol||e.hostname!=="*"&&n.hostname!==e.hostname)return!1;let s=e.pathname.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*").replace(/[.+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${s}$`).test(n.pathname)}catch{return!1}}export{b as addQueryParams,x as buildUrl,$ as extractUrls,j as getDomain,U as getQueryParam,P as getQueryParams,w as getUrlExtension,u as isAbsoluteUrl,m as isRelativeUrl,L as isSameOrigin,p as isValidUrl,y as joinUrl,E as matchesUrlPattern,S as normalizeUrl,f as parseQueryString,R as parseQueryStringAdvanced,h as parseUrl,d as removeQueryParams,A as sanitizeUrl,O as toAbsoluteUrl,g as toQueryString,l as url_parser};
1
+ // src/lib/url/parser.ts
2
+ var url_parser = (url) => {
3
+ try {
4
+ const p = new URL(url);
5
+ return {
6
+ hash: p.hash,
7
+ host: p.host,
8
+ hostname: p.hostname,
9
+ href: p.href,
10
+ origin: p.origin,
11
+ pathname: p.pathname,
12
+ port: p.port,
13
+ search: p.search,
14
+ searchParams: p.searchParams.toString(),
15
+ protocol: p.protocol
16
+ };
17
+ } catch (e) {
18
+ return null;
19
+ }
20
+ };
21
+ function parseUrl(url) {
22
+ return url_parser(url);
23
+ }
24
+ function isValidUrl(url) {
25
+ try {
26
+ new URL(url);
27
+ return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+ function isAbsoluteUrl(url) {
33
+ try {
34
+ new URL(url);
35
+ return true;
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ function isRelativeUrl(url) {
41
+ return !isAbsoluteUrl(url);
42
+ }
43
+ function parseQueryString(queryString) {
44
+ const params = {};
45
+ const searchParams = new URLSearchParams(queryString);
46
+ searchParams.forEach((value, key) => {
47
+ params[key] = value;
48
+ });
49
+ return params;
50
+ }
51
+ function parseQueryStringAdvanced(queryString) {
52
+ const params = {};
53
+ const searchParams = new URLSearchParams(queryString);
54
+ searchParams.forEach((value, key) => {
55
+ if (params[key]) {
56
+ if (Array.isArray(params[key])) {
57
+ params[key].push(value);
58
+ } else {
59
+ params[key] = [params[key], value];
60
+ }
61
+ } else {
62
+ params[key] = value;
63
+ }
64
+ });
65
+ return params;
66
+ }
67
+ function toQueryString(params, options = {}) {
68
+ const { encode = true, arrayFormat = "repeat" } = options;
69
+ const searchParams = new URLSearchParams();
70
+ Object.entries(params).forEach(([key, value]) => {
71
+ if (value === null || value === void 0) return;
72
+ if (Array.isArray(value)) {
73
+ value.forEach((v) => {
74
+ if (arrayFormat === "brackets") {
75
+ searchParams.append(`${key}[]`, String(v));
76
+ } else {
77
+ searchParams.append(key, String(v));
78
+ }
79
+ });
80
+ } else {
81
+ searchParams.append(key, String(value));
82
+ }
83
+ });
84
+ let result = searchParams.toString();
85
+ if (!encode) {
86
+ result = decodeURIComponent(result);
87
+ }
88
+ return result;
89
+ }
90
+ function addQueryParams(url, params) {
91
+ try {
92
+ const urlObj = new URL(url);
93
+ Object.entries(params).forEach(([key, value]) => {
94
+ if (value === null || value === void 0) {
95
+ urlObj.searchParams.delete(key);
96
+ } else if (Array.isArray(value)) {
97
+ urlObj.searchParams.delete(key);
98
+ value.forEach((v) => urlObj.searchParams.append(key, String(v)));
99
+ } else {
100
+ urlObj.searchParams.set(key, String(value));
101
+ }
102
+ });
103
+ return urlObj.toString();
104
+ } catch {
105
+ return url;
106
+ }
107
+ }
108
+ function removeQueryParams(url, ...keys) {
109
+ try {
110
+ const urlObj = new URL(url);
111
+ keys.forEach((key) => urlObj.searchParams.delete(key));
112
+ return urlObj.toString();
113
+ } catch {
114
+ return url;
115
+ }
116
+ }
117
+ function getQueryParam(url, key) {
118
+ try {
119
+ const urlObj = new URL(url);
120
+ return urlObj.searchParams.get(key);
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+ function getQueryParams(url, key) {
126
+ try {
127
+ const urlObj = new URL(url);
128
+ return urlObj.searchParams.getAll(key);
129
+ } catch {
130
+ return [];
131
+ }
132
+ }
133
+ function buildUrl(components) {
134
+ const {
135
+ protocol = "https",
136
+ hostname,
137
+ port,
138
+ pathname = "",
139
+ query,
140
+ hash
141
+ } = components;
142
+ let url = `${protocol}://${hostname}`;
143
+ if (port) {
144
+ url += `:${port}`;
145
+ }
146
+ if (pathname) {
147
+ url += pathname.startsWith("/") ? pathname : `/${pathname}`;
148
+ }
149
+ if (query && Object.keys(query).length > 0) {
150
+ url += `?${toQueryString(query)}`;
151
+ }
152
+ if (hash) {
153
+ url += hash.startsWith("#") ? hash : `#${hash}`;
154
+ }
155
+ return url;
156
+ }
157
+ function joinUrl(base, ...paths) {
158
+ try {
159
+ const url = new URL(base);
160
+ const basePath = url.pathname === "/" ? "" : url.pathname;
161
+ const pathParts = [basePath, ...paths].filter(Boolean).map((part) => part.replace(/^\/+|\/+$/g, ""));
162
+ url.pathname = "/" + pathParts.filter(Boolean).join("/");
163
+ return url.toString();
164
+ } catch {
165
+ const parts = [base, ...paths].filter(Boolean).map((part) => part.replace(/^\/+|\/+$/g, ""));
166
+ return "/" + parts.join("/");
167
+ }
168
+ }
169
+ function normalizeUrl(url, options = {}) {
170
+ const {
171
+ removeTrailingSlash = true,
172
+ removeDefaultPort = true,
173
+ sortQuery = false
174
+ } = options;
175
+ try {
176
+ const urlObj = new URL(url);
177
+ if (removeDefaultPort) {
178
+ if (urlObj.protocol === "http:" && urlObj.port === "80" || urlObj.protocol === "https:" && urlObj.port === "443") {
179
+ urlObj.port = "";
180
+ }
181
+ }
182
+ if (removeTrailingSlash && urlObj.pathname.endsWith("/") && urlObj.pathname !== "/") {
183
+ urlObj.pathname = urlObj.pathname.slice(0, -1);
184
+ }
185
+ if (sortQuery) {
186
+ const params = Array.from(urlObj.searchParams.entries());
187
+ params.sort((a, b) => a[0].localeCompare(b[0]));
188
+ urlObj.search = new URLSearchParams(params).toString();
189
+ }
190
+ return urlObj.toString();
191
+ } catch {
192
+ return url;
193
+ }
194
+ }
195
+ function getDomain(url, options = {}) {
196
+ const { includeSubdomain = false } = options;
197
+ try {
198
+ const urlObj = new URL(url);
199
+ const hostname = urlObj.hostname;
200
+ if (includeSubdomain) {
201
+ return hostname;
202
+ }
203
+ const parts = hostname.split(".");
204
+ if (parts.length >= 2) {
205
+ return parts.slice(-2).join(".");
206
+ }
207
+ return hostname;
208
+ } catch {
209
+ return null;
210
+ }
211
+ }
212
+ function getUrlExtension(url) {
213
+ try {
214
+ const urlObj = new URL(url);
215
+ const pathname = urlObj.pathname;
216
+ const lastDot = pathname.lastIndexOf(".");
217
+ const lastSlash = pathname.lastIndexOf("/");
218
+ if (lastDot > lastSlash && lastDot < pathname.length - 1) {
219
+ return pathname.slice(lastDot + 1);
220
+ }
221
+ return null;
222
+ } catch {
223
+ return null;
224
+ }
225
+ }
226
+ function isSameOrigin(url1, url2) {
227
+ try {
228
+ const urlObj1 = new URL(url1);
229
+ const urlObj2 = new URL(url2);
230
+ return urlObj1.origin === urlObj2.origin;
231
+ } catch {
232
+ return false;
233
+ }
234
+ }
235
+ function toAbsoluteUrl(relativeUrl, baseUrl) {
236
+ try {
237
+ return new URL(relativeUrl, baseUrl).toString();
238
+ } catch {
239
+ return relativeUrl;
240
+ }
241
+ }
242
+ function sanitizeUrl(url) {
243
+ const dangerousProtocols = ["javascript:", "data:", "vbscript:"];
244
+ try {
245
+ const urlObj = new URL(url);
246
+ if (dangerousProtocols.some((proto) => urlObj.protocol === proto)) {
247
+ return null;
248
+ }
249
+ return url;
250
+ } catch {
251
+ const lower = url.toLowerCase().trim();
252
+ if (dangerousProtocols.some((proto) => lower.startsWith(proto))) {
253
+ return null;
254
+ }
255
+ return url;
256
+ }
257
+ }
258
+ function extractUrls(text, options = {}) {
259
+ const { unique = true } = options;
260
+ const urlRegex = /https?:\/\/[^\s<>"{}|\\^`\]]+/gi;
261
+ const matches = text.match(urlRegex) || [];
262
+ return unique ? Array.from(new Set(matches)) : matches;
263
+ }
264
+ function matchesUrlPattern(url, pattern) {
265
+ try {
266
+ const urlObj = new URL(url);
267
+ const patternObj = new URL(pattern);
268
+ if (patternObj.protocol !== "*:" && urlObj.protocol !== patternObj.protocol) {
269
+ return false;
270
+ }
271
+ if (patternObj.hostname !== "*" && urlObj.hostname !== patternObj.hostname) {
272
+ return false;
273
+ }
274
+ const pathPattern = patternObj.pathname.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/[.+?^${}()|[\]\\]/g, "\\$&");
275
+ const pathRegex = new RegExp(`^${pathPattern}$`);
276
+ return pathRegex.test(urlObj.pathname);
277
+ } catch {
278
+ return false;
279
+ }
280
+ }
281
+ export {
282
+ addQueryParams,
283
+ buildUrl,
284
+ extractUrls,
285
+ getDomain,
286
+ getQueryParam,
287
+ getQueryParams,
288
+ getUrlExtension,
289
+ isAbsoluteUrl,
290
+ isRelativeUrl,
291
+ isSameOrigin,
292
+ isValidUrl,
293
+ joinUrl,
294
+ matchesUrlPattern,
295
+ normalizeUrl,
296
+ parseQueryString,
297
+ parseQueryStringAdvanced,
298
+ parseUrl,
299
+ removeQueryParams,
300
+ sanitizeUrl,
301
+ toAbsoluteUrl,
302
+ toQueryString,
303
+ url_parser
304
+ };