@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,282 @@
1
- var g=(t,n={})=>{let{type:l="auto",throwOnError:i=!1}=n;if(!t||typeof t!="string")return[];let s=[],a="",o=!1,d=!1,f="",y="",b=0,T=l==="auto"?(r=>r.includes("..")?"descendant":r.includes("[?(")?"filter":r.includes("[:")||r.includes("[0:")?"slice":r.includes("[,")||r.includes("[0,1]")?"union":r.includes("[*]")||r.includes(".*.")?"wildcard":r.includes("[]")?"array-wildcard":r.includes("[")&&r.includes("]")?"bracket":"dot")(t):l,h=r=>{let e=r.trim();if(e==="*"||e==="")return{type:"wildcard",value:e===""?"[]":"*",raw:e===""?"[]":r};if(e==="[]")return{type:"wildcard",value:"[]",raw:r};if(/^-?\d+$/.test(e))return{type:"index",value:parseInt(e,10),raw:r};if(e.includes(":")){let c=e.split(":").map(v=>v.trim()),u=c[0]===""?0:parseInt(c[0],10),p=c[1]===""?1/0:parseInt(c[1],10);if(isNaN(u)||isNaN(p)){if(i)throw new Error(`Invalid slice notation: ${r}`);return{type:"wildcard",value:"*",raw:r}}return{type:"slice",value:[u,p],raw:r}}if(e.includes(",")){let c=e.split(",").map(u=>{let p=parseInt(u.trim(),10);return isNaN(p)?-1:p}).filter(u=>u>=0);if(c.length===0){if(i)throw new Error(`Invalid union notation: ${r}`);return{type:"wildcard",value:"*",raw:r}}return{type:"union",value:c,raw:r}}if(e.startsWith("?(")&&e.endsWith(")")){let c=e.slice(2,-1);try{return{type:"filter",value:S(c),raw:r}}catch(u){if(i)throw u;return{type:"wildcard",value:"*",raw:r}}}return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")?{type:"property",value:e.slice(1,-1),raw:r}:{type:"property",value:e,raw:r}};for(let r=0;r<t.length;r++){let e=t[r],c=t[r+1];if((e==='"'||e==="'")&&!d){d=!0,f=e;continue}else if(e===f&&d){d=!1,f="",e==='"'||e==="'"||(o?y+=e:a+=e);continue}if(d){o?y+=e:a+=e;continue}if(e==="["&&!o){a&&(s.push({type:"property",value:a,raw:a}),a=""),o=!0,y="";continue}if(e==="]"&&o&&!d){o=!1;let p=h(y);s.push(p);continue}let u=s.length>0?s[s.length-1]:null;if(e==="."&&!o&&!d){if(c==="."){let p=t.split("..")[0];s.push({type:"property",value:p,raw:p}),s.push({type:"descendant",value:"..",raw:".."}),r++}else a&&(a==="*"?s.push({type:"wildcard",value:a,raw:a}):s.push({type:"property",value:a,raw:a}),a="");continue}if(o)y+=e;else if(u&&u.type!=="descendant")a+=e;else{let p=t.split(u?.raw)[1];p!==void 0?a=p:a+=e}}return a&&s.push({type:"property",value:a,raw:a}),s.map(r=>{if(r.type==="property"&&typeof r.value=="string"&&/^-?\d+$/.test(r.value)){let e=parseInt(r.value,10);if(!isNaN(e))return{...r,type:"index",value:e}}return r})},S=t=>{let n=t.replace(/@\.([a-zA-Z_$][\w$]*)/g,(l,i)=>`item.${i}`).replace(/@/g,"item");try{return new Function("item",`return ${n}`)}catch{throw new Error(`Invalid filter expression: ${t}`)}},x=t=>{let n=[];for(let l=0;l<t.length;l++){let i=t[l],s=l>0?t[l-1]:null;switch(i.type){case"property":/[\.\[\]\s]/.test(String(i.value))?n.push(`["${i.value}"]`):(s&&s.type!=="descendant"&&n.push("."),n.push(String(i.value)));break;case"index":n.push(`[${i.value}]`);break;case"wildcard":i.value==="[]"?n.push("[]"):n.push("[*]");break;case"slice":let[o,d]=i.value;n.push(`[${o}:${d===1/0?"":d}]`);break;case"union":let f=i.value;n.push(`[${f.join(",")}]`);break;case"filter":n.push(`[?(${i.raw?.slice(2,-1)||""})]`);break;case"descendant":n.push("..");break}}return n.join("").replace(/\.\[/g,"[")},m=(t,n={})=>{if(Array.isArray(t))return t.map(l=>m(l,n));if(!/^[a-zA-Z]/.test(t))return{valid:!1,error:"Selector starts with '.'",type:w(t)};if(!/[a-zA-Z]$/.test(t))return{valid:!1,error:"Selector end with '.'",type:w(t)};try{let l=g(t,{throwOnError:!0}),i=w(t);return n.allowedTypes&&!n.allowedTypes.includes(i)?{valid:!1,error:`Selector type ${i} not allowed. Allowed: ${n.allowedTypes.join(", ")}`,type:i}:{valid:!0,type:w(t)}}catch(l){return{valid:!1,error:l.message}}},w=t=>t.includes("..")?"descendant":t.includes("[?(")?"filter":t.includes("[:")||t.includes("[0:")?"slice":/\[[^\]]*,[^\]]*\]/.test(t)?"union":t.includes("[*]")||t.includes(".*.")?"wildcard":t.includes("[]")?"array-wildcard":t.includes("[")&&t.includes("]")?"bracket":"dot",k=(t,n)=>t.replace(/\{(\w+)\}/g,(l,i)=>i in n?String(n[i]):`{${i}}`);export{S as createFilterFunction,k as createSelector,w as detectSelectorType,g as parseSelector,x as stringifySelector,m as validateSelector};
1
+ // src/lib/object/selector.ts
2
+ var parseSelector = (selector, options = {}) => {
3
+ const { type = "auto", throwOnError = false } = options;
4
+ if (!selector || typeof selector !== "string") {
5
+ return [];
6
+ }
7
+ const segments = [];
8
+ let current = "";
9
+ let inBrackets = false;
10
+ let inQuotes = false;
11
+ let quoteChar = "";
12
+ let bracketContent = "";
13
+ let bracketDepth = 0;
14
+ const detectType = (str) => {
15
+ if (str.includes("..")) return "descendant";
16
+ if (str.includes("[?(")) return "filter";
17
+ if (str.includes("[:") || str.includes("[0:")) return "slice";
18
+ if (str.includes("[,") || str.includes("[0,1]")) return "union";
19
+ if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
20
+ if (str.includes("[]")) return "array-wildcard";
21
+ if (str.includes("[") && str.includes("]")) return "bracket";
22
+ return "dot";
23
+ };
24
+ const actualType = type === "auto" ? detectType(selector) : type;
25
+ const parseBracketContent = (content) => {
26
+ const trimmed = content.trim();
27
+ if (trimmed === "*" || trimmed === "") {
28
+ return {
29
+ type: "wildcard",
30
+ value: trimmed === "" ? "[]" : "*",
31
+ raw: trimmed === "" ? "[]" : content
32
+ };
33
+ }
34
+ if (trimmed === "[]") {
35
+ return { type: "wildcard", value: "[]", raw: content };
36
+ }
37
+ if (/^-?\d+$/.test(trimmed)) {
38
+ return { type: "index", value: parseInt(trimmed, 10), raw: content };
39
+ }
40
+ if (trimmed.includes(":")) {
41
+ const parts = trimmed.split(":").map((p) => p.trim());
42
+ const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
43
+ const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
44
+ if (isNaN(start) || isNaN(end)) {
45
+ if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
46
+ return { type: "wildcard", value: "*", raw: content };
47
+ }
48
+ return { type: "slice", value: [start, end], raw: content };
49
+ }
50
+ if (trimmed.includes(",")) {
51
+ const indices = trimmed.split(",").map((p) => {
52
+ const num = parseInt(p.trim(), 10);
53
+ return isNaN(num) ? -1 : num;
54
+ }).filter((n) => n >= 0);
55
+ if (indices.length === 0) {
56
+ if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
57
+ return { type: "wildcard", value: "*", raw: content };
58
+ }
59
+ return { type: "union", value: indices, raw: content };
60
+ }
61
+ if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
62
+ const expr = trimmed.slice(2, -1);
63
+ try {
64
+ const filterFn = createFilterFunction(expr);
65
+ return { type: "filter", value: filterFn, raw: content };
66
+ } catch (error) {
67
+ if (throwOnError) throw error;
68
+ return { type: "wildcard", value: "*", raw: content };
69
+ }
70
+ }
71
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
72
+ return { type: "property", value: trimmed.slice(1, -1), raw: content };
73
+ }
74
+ return { type: "property", value: trimmed, raw: content };
75
+ };
76
+ for (let i = 0; i < selector.length; i++) {
77
+ const char = selector[i];
78
+ const nextChar = selector[i + 1];
79
+ if ((char === '"' || char === "'") && !inQuotes) {
80
+ inQuotes = true;
81
+ quoteChar = char;
82
+ continue;
83
+ } else if (char === quoteChar && inQuotes) {
84
+ inQuotes = false;
85
+ quoteChar = "";
86
+ if (!(char === '"' || char === "'")) {
87
+ if (inBrackets) {
88
+ bracketContent += char;
89
+ } else {
90
+ current += char;
91
+ }
92
+ }
93
+ continue;
94
+ }
95
+ if (inQuotes) {
96
+ if (inBrackets) {
97
+ bracketContent += char;
98
+ } else {
99
+ current += char;
100
+ }
101
+ continue;
102
+ }
103
+ if (char === "[" && !inBrackets) {
104
+ if (current) {
105
+ segments.push({ type: "property", value: current, raw: current });
106
+ current = "";
107
+ }
108
+ inBrackets = true;
109
+ bracketContent = "";
110
+ continue;
111
+ }
112
+ if (char === "]" && inBrackets && !inQuotes) {
113
+ inBrackets = false;
114
+ const segment = parseBracketContent(bracketContent);
115
+ segments.push(segment);
116
+ continue;
117
+ }
118
+ let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
119
+ if (char === "." && !inBrackets && !inQuotes) {
120
+ if (nextChar === ".") {
121
+ const l = selector.split("..")[0];
122
+ segments.push({ type: "property", value: l, raw: l });
123
+ segments.push({ type: "descendant", value: "..", raw: ".." });
124
+ i++;
125
+ } else if (current) {
126
+ if (current === "*") {
127
+ segments.push({ type: "wildcard", value: current, raw: current });
128
+ } else {
129
+ segments.push({ type: "property", value: current, raw: current });
130
+ }
131
+ current = "";
132
+ }
133
+ continue;
134
+ }
135
+ if (inBrackets) {
136
+ bracketContent += char;
137
+ } else {
138
+ if (lastDot && lastDot.type !== "descendant") {
139
+ current += char;
140
+ } else {
141
+ const l = selector.split(lastDot?.raw)[1];
142
+ if (l !== void 0) {
143
+ current = l;
144
+ } else {
145
+ current += char;
146
+ }
147
+ }
148
+ }
149
+ }
150
+ if (current) {
151
+ segments.push({ type: "property", value: current, raw: current });
152
+ }
153
+ return segments.map((segment) => {
154
+ if (segment.type === "property" && typeof segment.value === "string") {
155
+ if (/^-?\d+$/.test(segment.value)) {
156
+ const num = parseInt(segment.value, 10);
157
+ if (!isNaN(num)) {
158
+ return { ...segment, type: "index", value: num };
159
+ }
160
+ }
161
+ }
162
+ return segment;
163
+ });
164
+ };
165
+ var createFilterFunction = (expr) => {
166
+ const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
167
+ try {
168
+ return new Function("item", `return ${safeExpr}`);
169
+ } catch (error) {
170
+ throw new Error(`Invalid filter expression: ${expr}`);
171
+ }
172
+ };
173
+ var stringifySelector = (segments) => {
174
+ const parts = [];
175
+ for (let i = 0; i < segments.length; i++) {
176
+ const segment = segments[i];
177
+ const prevSegment = i > 0 ? segments[i - 1] : null;
178
+ switch (segment.type) {
179
+ case "property":
180
+ const needsQuotes = /[\.\[\]\s]/.test(String(segment.value));
181
+ if (needsQuotes) {
182
+ parts.push(`["${segment.value}"]`);
183
+ } else {
184
+ if (prevSegment && prevSegment.type !== "descendant") {
185
+ parts.push(".");
186
+ }
187
+ parts.push(String(segment.value));
188
+ }
189
+ break;
190
+ case "index":
191
+ parts.push(`[${segment.value}]`);
192
+ break;
193
+ case "wildcard":
194
+ if (segment.value === "[]") {
195
+ parts.push("[]");
196
+ } else {
197
+ parts.push("[*]");
198
+ }
199
+ break;
200
+ case "slice":
201
+ const [start, end] = segment.value;
202
+ parts.push(`[${start}:${end === Infinity ? "" : end}]`);
203
+ break;
204
+ case "union":
205
+ const indices = segment.value;
206
+ parts.push(`[${indices.join(",")}]`);
207
+ break;
208
+ case "filter":
209
+ parts.push(`[?(${segment.raw?.slice(2, -1) || ""})]`);
210
+ break;
211
+ case "descendant":
212
+ parts.push("..");
213
+ break;
214
+ }
215
+ }
216
+ return parts.join("").replace(/\.\[/g, "[");
217
+ };
218
+ var validateSelector = (selector, options = {}) => {
219
+ if (Array.isArray(selector)) {
220
+ return selector.map(
221
+ (sel) => validateSelector(sel, options)
222
+ );
223
+ }
224
+ if (!/^[a-zA-Z]/.test(selector)) {
225
+ return {
226
+ valid: false,
227
+ error: `Selector starts with '.'`,
228
+ type: detectSelectorType(selector)
229
+ };
230
+ }
231
+ if (!/[a-zA-Z]$/.test(selector)) {
232
+ return {
233
+ valid: false,
234
+ error: `Selector end with '.'`,
235
+ type: detectSelectorType(selector)
236
+ };
237
+ }
238
+ try {
239
+ const segments = parseSelector(selector, { throwOnError: true });
240
+ const type = detectSelectorType(selector);
241
+ if (options.allowedTypes) {
242
+ if (!options.allowedTypes.includes(type)) {
243
+ return {
244
+ valid: false,
245
+ error: `Selector type ${type} not allowed. Allowed: ${options.allowedTypes.join(
246
+ ", "
247
+ )}`,
248
+ type
249
+ };
250
+ }
251
+ }
252
+ return { valid: true, type: detectSelectorType(selector) };
253
+ } catch (error) {
254
+ return { valid: false, error: error.message };
255
+ }
256
+ };
257
+ var detectSelectorType = (selector) => {
258
+ if (selector.includes("..")) return "descendant";
259
+ if (selector.includes("[?(")) return "filter";
260
+ if (selector.includes("[:") || selector.includes("[0:")) return "slice";
261
+ if (/\[[^\]]*,[^\]]*\]/.test(selector)) return "union";
262
+ if (selector.includes("[*]") || selector.includes(".*.")) return "wildcard";
263
+ if (selector.includes("[]")) return "array-wildcard";
264
+ if (selector.includes("[") && selector.includes("]")) return "bracket";
265
+ return "dot";
266
+ };
267
+ var createSelector = (template, replacements) => {
268
+ return template.replace(/\{(\w+)\}/g, (_, key) => {
269
+ if (key in replacements) {
270
+ return String(replacements[key]);
271
+ }
272
+ return `{${key}}`;
273
+ });
274
+ };
275
+ export {
276
+ createFilterFunction,
277
+ createSelector,
278
+ detectSelectorType,
279
+ parseSelector,
280
+ stringifySelector,
281
+ validateSelector
282
+ };
@@ -1 +1,209 @@
1
- "use strict";var g=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var t in n)g(e,t,{get:n[t],enumerable:!0})},$=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of w(n))!k.call(e,o)&&o!==t&&g(e,o,{get:()=>n[o],enumerable:!(r=h(n,o))||r.enumerable});return e};var C=e=>$(g({},"__esModule",{value:!0}),e);var L={};N(L,{move:()=>K,reorder:()=>J,sort:()=>T,sortBy:()=>M,sortKeys:()=>I,swap:()=>V});module.exports=C(L);function b(e){if(typeof e!="object"||e===null)return!1;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function A(e,n){if(e==null)return;let t=e;for(let r of n.split(".")){if(t==null)return;t=t[r]}return t}function R(e,n,t,r){let o=e==null,s=n==null;if(o&&s)return 0;if(o)return 1;if(s)return-1;let u=typeof e=="number"&&Number.isNaN(e),i=typeof n=="number"&&Number.isNaN(n);return u&&i?0:u?1:i?-1:e instanceof Date&&n instanceof Date?e.getTime()-n.getTime():typeof e=="boolean"&&typeof n=="boolean"?e===n?0:e?1:-1:typeof e=="number"&&typeof n=="number"?e-n:typeof e=="string"&&typeof n=="string"?e.localeCompare(n,t,r):String(e).localeCompare(String(n),t,r)}function y(e,n){return(Array.isArray(e)?e[n]??"asc":e??"asc")==="desc"?-1:1}function F(e,n){let{order:t,locale:r,localeOptions:o,nullsLast:s=!0}=n,u=y(t,0);return e.slice().sort((i,c)=>{let l=i==null,a=c==null;return l&&a?0:l?s?1:-1:a?s?-1:1:R(i,c,r,o)*u})}function E(e,n,t){let{order:r,locale:o,localeOptions:s,nullsLast:u=!0,comparator:i}=t;return i?e.slice().sort(i):e.slice().sort((c,l)=>{for(let a=0;a<n.length;a++){let d=A(c,n[a]),f=A(l,n[a]),p=d==null,O=f==null;if(p&&O)continue;if(p)return u?1:-1;if(O)return u?-1:1;let S=R(d,f,o,s);if(S!==0)return S*y(r,a)}return 0})}function j(e,n){let{order:t,priorityKeys:r=[],locale:o,localeOptions:s,deep:u}=n,i=y(t,0),c=new Set(r),l=Object.keys(e).filter(f=>!c.has(f));l.sort((f,p)=>f.localeCompare(p,o,s)*i);let a=[...r.filter(f=>f in e),...l],d={};for(let f of a)d[f]=u?m(e[f],n):e[f];return d}function m(e,n){if(Array.isArray(e)){let t=e.map(r=>m(r,n));return x(t,n)}return b(e)?j(e,n):e}function P(e,n){let t=e.length,r=new Set,o=[];for(let s of n)s>=0&&s<t&&!r.has(s)&&(o.push(e[s]),r.add(s));for(let s=0;s<t;s++)r.has(s)||o.push(e[s]);return o}function x(e,n){let{by:t,comparator:r,indices:o,order:s}=n;if(o){let i=P(e,o);return y(s,0)===-1?i.reverse():i}if(r)return e.slice().sort(r);if(t){let i=Array.isArray(t)?t:[t];return E(e,i,n)}let u=e.find(i=>i!=null);return u!=null&&b(u)?y(s,0)===-1?e.slice().reverse():e.slice():F(e,n)}function T(e,n={}){let{deep:t}=n;if(Array.isArray(e)){let r=t?e.map(o=>m(o,n)):e;return x(r,n)}return b(e)?j(e,n):e}function M(e,n,t="asc",r={}){return T(e,{...r,by:n,order:t})}function I(e,n={}){return T(e,n)}function K(e,n,t){let r=e.length;if(r===0)return e.slice();let o=Math.max(0,Math.min(r-1,n)),s=Math.max(0,Math.min(r-1,t));if(o===s)return e.slice();let u=e.slice(),[i]=u.splice(o,1);return u.splice(s,0,i),u}function V(e,n,t){let r=e.length;if(n<0||n>=r)throw new RangeError(`swap: index ${n} out of range`);if(t<0||t>=r)throw new RangeError(`swap: index ${t} out of range`);if(n===t)return e.slice();let o=e.slice();return o[n]=e[t],o[t]=e[n],o}function J(e,n,t="asc"){return T(e,{indices:n,order:t})}
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/object/sort.ts
21
+ var sort_exports = {};
22
+ __export(sort_exports, {
23
+ move: () => move,
24
+ reorder: () => reorder,
25
+ sort: () => sort,
26
+ sortBy: () => sortBy,
27
+ sortKeys: () => sortKeys,
28
+ swap: () => swap
29
+ });
30
+ module.exports = __toCommonJS(sort_exports);
31
+
32
+ // src/lib/object/utils.ts
33
+ function isPlainObject(v) {
34
+ if (typeof v !== "object" || v === null) return false;
35
+ const proto = Object.getPrototypeOf(v);
36
+ return proto === Object.prototype || proto === null;
37
+ }
38
+
39
+ // src/lib/object/sort.ts
40
+ function getAtPath(obj, path) {
41
+ if (obj == null) return void 0;
42
+ let cur = obj;
43
+ for (const segment of path.split(".")) {
44
+ if (cur == null) return void 0;
45
+ cur = cur[segment];
46
+ }
47
+ return cur;
48
+ }
49
+ function compareValues(a, b, locale, localeOptions) {
50
+ const aN = a == null;
51
+ const bN = b == null;
52
+ if (aN && bN) return 0;
53
+ if (aN) return 1;
54
+ if (bN) return -1;
55
+ const aNaN = typeof a === "number" && Number.isNaN(a);
56
+ const bNaN = typeof b === "number" && Number.isNaN(b);
57
+ if (aNaN && bNaN) return 0;
58
+ if (aNaN) return 1;
59
+ if (bNaN) return -1;
60
+ if (a instanceof Date && b instanceof Date) {
61
+ return a.getTime() - b.getTime();
62
+ }
63
+ if (typeof a === "boolean" && typeof b === "boolean") {
64
+ return a === b ? 0 : a ? 1 : -1;
65
+ }
66
+ if (typeof a === "number" && typeof b === "number") {
67
+ return a - b;
68
+ }
69
+ if (typeof a === "string" && typeof b === "string") {
70
+ return a.localeCompare(b, locale, localeOptions);
71
+ }
72
+ return String(a).localeCompare(String(b), locale, localeOptions);
73
+ }
74
+ function dirFor(order, i) {
75
+ const o = Array.isArray(order) ? order[i] ?? "asc" : order ?? "asc";
76
+ return o === "desc" ? -1 : 1;
77
+ }
78
+ function sortPrimitiveArray(arr, options) {
79
+ const { order, locale, localeOptions, nullsLast = true } = options;
80
+ const dir = dirFor(order, 0);
81
+ return arr.slice().sort((a, b) => {
82
+ const aN = a == null;
83
+ const bN = b == null;
84
+ if (aN && bN) return 0;
85
+ if (aN) return nullsLast ? 1 : -1;
86
+ if (bN) return nullsLast ? -1 : 1;
87
+ return compareValues(a, b, locale, localeOptions) * dir;
88
+ });
89
+ }
90
+ function sortObjectArray(arr, keys, options) {
91
+ const { order, locale, localeOptions, nullsLast = true, comparator } = options;
92
+ if (comparator) {
93
+ return arr.slice().sort(comparator);
94
+ }
95
+ return arr.slice().sort((a, b) => {
96
+ for (let i = 0; i < keys.length; i++) {
97
+ const aVal = getAtPath(a, keys[i]);
98
+ const bVal = getAtPath(b, keys[i]);
99
+ const aN = aVal == null;
100
+ const bN = bVal == null;
101
+ if (aN && bN) continue;
102
+ if (aN) return nullsLast ? 1 : -1;
103
+ if (bN) return nullsLast ? -1 : 1;
104
+ const cmp = compareValues(aVal, bVal, locale, localeOptions);
105
+ if (cmp !== 0) return cmp * dirFor(order, i);
106
+ }
107
+ return 0;
108
+ });
109
+ }
110
+ function sortRecord(record, options) {
111
+ const { order, priorityKeys = [], locale, localeOptions, deep } = options;
112
+ const dir = dirFor(order, 0);
113
+ const prioritySet = new Set(priorityKeys);
114
+ const rest = Object.keys(record).filter((k) => !prioritySet.has(k));
115
+ rest.sort(
116
+ (a, b) => a.localeCompare(b, locale, localeOptions) * dir
117
+ );
118
+ const ordered = [...priorityKeys.filter((k) => k in record), ...rest];
119
+ const result = {};
120
+ for (const key of ordered) {
121
+ result[key] = deep ? sortDeep(record[key], options) : record[key];
122
+ }
123
+ return result;
124
+ }
125
+ function sortDeep(value, options) {
126
+ if (Array.isArray(value)) {
127
+ const deepSorted = value.map((item) => sortDeep(item, options));
128
+ return sortArrayValue(deepSorted, options);
129
+ }
130
+ if (isPlainObject(value)) {
131
+ return sortRecord(value, options);
132
+ }
133
+ return value;
134
+ }
135
+ function applyIndices(arr, indices) {
136
+ const len = arr.length;
137
+ const used = /* @__PURE__ */ new Set();
138
+ const result = [];
139
+ for (const idx of indices) {
140
+ if (idx >= 0 && idx < len && !used.has(idx)) {
141
+ result.push(arr[idx]);
142
+ used.add(idx);
143
+ }
144
+ }
145
+ for (let i = 0; i < len; i++) {
146
+ if (!used.has(i)) result.push(arr[i]);
147
+ }
148
+ return result;
149
+ }
150
+ function sortArrayValue(arr, options) {
151
+ const { by, comparator, indices, order } = options;
152
+ if (indices) {
153
+ const permuted = applyIndices(arr, indices);
154
+ return dirFor(order, 0) === -1 ? permuted.reverse() : permuted;
155
+ }
156
+ if (comparator) {
157
+ return arr.slice().sort(comparator);
158
+ }
159
+ if (by) {
160
+ const keys = Array.isArray(by) ? by : [by];
161
+ return sortObjectArray(arr, keys, options);
162
+ }
163
+ const firstReal = arr.find((x) => x != null);
164
+ if (firstReal != null && isPlainObject(firstReal)) {
165
+ return dirFor(order, 0) === -1 ? arr.slice().reverse() : arr.slice();
166
+ }
167
+ return sortPrimitiveArray(arr, options);
168
+ }
169
+ function sort(input, options = {}) {
170
+ const { deep } = options;
171
+ if (Array.isArray(input)) {
172
+ const items = deep ? input.map((item) => sortDeep(item, options)) : input;
173
+ return sortArrayValue(items, options);
174
+ }
175
+ if (isPlainObject(input)) {
176
+ return sortRecord(input, options);
177
+ }
178
+ return input;
179
+ }
180
+ function sortBy(arr, by, order = "asc", options = {}) {
181
+ return sort(arr, { ...options, by, order });
182
+ }
183
+ function sortKeys(record, options = {}) {
184
+ return sort(record, options);
185
+ }
186
+ function move(arr, from, to) {
187
+ const len = arr.length;
188
+ if (len === 0) return arr.slice();
189
+ const f = Math.max(0, Math.min(len - 1, from));
190
+ const t = Math.max(0, Math.min(len - 1, to));
191
+ if (f === t) return arr.slice();
192
+ const result = arr.slice();
193
+ const [item] = result.splice(f, 1);
194
+ result.splice(t, 0, item);
195
+ return result;
196
+ }
197
+ function swap(arr, i, j) {
198
+ const len = arr.length;
199
+ if (i < 0 || i >= len) throw new RangeError(`swap: index ${i} out of range`);
200
+ if (j < 0 || j >= len) throw new RangeError(`swap: index ${j} out of range`);
201
+ if (i === j) return arr.slice();
202
+ const result = arr.slice();
203
+ result[i] = arr[j];
204
+ result[j] = arr[i];
205
+ return result;
206
+ }
207
+ function reorder(arr, indices, order = "asc") {
208
+ return sort(arr, { indices, order });
209
+ }