@fluixi/utils 1.0.0-alpha.83 → 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,247 @@
1
- var g=2*Math.PI;function n(e){return Math.abs(e)<1e-10}function p(e,r){return Math.abs(e-r)<1e-10}function t(e){return{real:n(e.real)?0:e.real,imag:n(e.imag)?0:e.imag}}function l(e,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${e}`)}function m(e,r="Complex number"){if(!e||typeof e!="object")throw new Error(`${r} must be an object`);l(e.real,`${r}.real`),l(e.imag,`${r}.imag`)}function i(e,r=0){return l(e,"real"),l(r,"imag"),t({real:e,imag:r})}function M(e,r){return m(e,"First complex number"),m(r,"Second complex number"),p(e.real,r.real)&&p(e.imag,r.imag)}function c(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real+r.real,imag:e.imag+r.imag})}function d(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real-r.real,imag:e.imag-r.imag})}function f(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real*r.real-e.imag*r.imag,imag:e.real*r.imag+e.imag*r.real})}function w(e,r){m(e,"Numerator complex number"),m(r,"Denominator complex number");let o=r.real*r.real+r.imag*r.imag;if(n(o))throw new Error("Cannot divide by zero or near-zero complex number");return t({real:(e.real*r.real+e.imag*r.imag)/o,imag:(e.imag*r.real-e.real*r.imag)/o})}function C(e){m(e);let r=Math.sqrt(e.real*e.real+e.imag*e.imag);return n(r)?0:r}function E(e){return m(e),t({real:e.real,imag:-e.imag})}function s(e){return m(e),n(e.real)&&n(e.imag)?0:Math.atan2(e.imag,e.real)}function h(e){return m(e),{magnitude:C(e),angle:s(e)}}function b(e,r){if(l(e,"magnitude"),l(r,"angle"),e<-1e-10)throw new Error("Magnitude must be non-negative");let o=r%g;o>Math.PI&&(o-=g),o<=-Math.PI&&(o+=g);let a=Math.max(0,e);return t({real:a*Math.cos(o),imag:a*Math.sin(o)})}function P(e){if(m(e),n(e.real)&&n(e.imag)){let N=i(0,0);return[N,N]}let r=C(e),o=s(e),a=Math.sqrt(r),u=o/2,x=u+Math.PI;return[b(a,u),b(a,x)]}function I(e,r){if(m(e),l(r,"exponent"),n(r))return i(1,0);if(p(r,1))return i(e.real,e.imag);if(p(r,2))return f(e,e);if(n(e.real)&&n(e.imag)){if(r>0)return i(0,0);if(r<0)throw new Error("Cannot raise zero to a negative power")}let o=h(e),a=Math.pow(o.magnitude,r),u=a<-1e-10?Math.abs(a):Math.max(0,a),x=o.angle*r;return b(u,x)}function z(e){m(e);let r=C(e);if(n(r))throw new Error("Cannot take logarithm of zero or near-zero complex number");let o=s(e);return t({real:Math.log(r),imag:o})}function S(e){m(e);let r=Math.exp(e.real);return t({real:r*Math.cos(e.imag),imag:r*Math.sin(e.imag)})}function y(e){return m(e),t({real:Math.sin(e.real)*Math.cosh(e.imag),imag:Math.cos(e.real)*Math.sinh(e.imag)})}function v(e){return m(e),t({real:Math.cos(e.real)*Math.cosh(e.imag),imag:-Math.sin(e.real)*Math.sinh(e.imag)})}function O(e){return m(e),n(e.real)&&n(e.imag)}function q(e){return m(e),e.real}function F(e){return m(e),e.imag}function L(e){return m(e),t({real:-e.real,imag:-e.imag})}function $(e){m(e);let r=e.real*e.real+e.imag*e.imag;if(n(r))throw new Error("Cannot calculate reciprocal of zero or near-zero complex number");return t({real:e.real/r,imag:-e.imag/r})}export{c as addComplex,s as argumentComplex,M as complexEquals,E as conjugateComplex,v as cosComplex,i as createComplex,w as divideComplex,S as expComplex,b as fromPolarComplex,F as getImag,q as getReal,O as isZeroComplex,z as lnComplex,C as magnitudeComplex,f as multiplyComplex,L as negateComplex,I as powerComplex,$ as reciprocalComplex,y as sinComplex,P as sqrtComplex,d as subtractComplex,h as toPolarComplex};
1
+ // src/lib/maths/fn/complex.ts
2
+ var EPSILON = 1e-10;
3
+ var TWO_PI = 2 * Math.PI;
4
+ function isApproximatelyZero(value) {
5
+ return Math.abs(value) < EPSILON;
6
+ }
7
+ function approximatelyEqual(a, b) {
8
+ return Math.abs(a - b) < EPSILON;
9
+ }
10
+ function normalizeComplex(c) {
11
+ return {
12
+ real: isApproximatelyZero(c.real) ? 0 : c.real,
13
+ imag: isApproximatelyZero(c.imag) ? 0 : c.imag
14
+ };
15
+ }
16
+ function validateNumber(value, name) {
17
+ if (typeof value !== "number" || !Number.isFinite(value)) {
18
+ throw new Error(`${name} must be a finite number, got ${value}`);
19
+ }
20
+ }
21
+ function validateComplexNumber(c, name = "Complex number") {
22
+ if (!c || typeof c !== "object") {
23
+ throw new Error(`${name} must be an object`);
24
+ }
25
+ validateNumber(c.real, `${name}.real`);
26
+ validateNumber(c.imag, `${name}.imag`);
27
+ }
28
+ function createComplex(real, imag = 0) {
29
+ validateNumber(real, "real");
30
+ validateNumber(imag, "imag");
31
+ return normalizeComplex({ real, imag });
32
+ }
33
+ function complexEquals(a, b) {
34
+ validateComplexNumber(a, "First complex number");
35
+ validateComplexNumber(b, "Second complex number");
36
+ return approximatelyEqual(a.real, b.real) && approximatelyEqual(a.imag, b.imag);
37
+ }
38
+ function addComplex(a, b) {
39
+ validateComplexNumber(a, "First complex number");
40
+ validateComplexNumber(b, "Second complex number");
41
+ return normalizeComplex({
42
+ real: a.real + b.real,
43
+ imag: a.imag + b.imag
44
+ });
45
+ }
46
+ function subtractComplex(a, b) {
47
+ validateComplexNumber(a, "First complex number");
48
+ validateComplexNumber(b, "Second complex number");
49
+ return normalizeComplex({
50
+ real: a.real - b.real,
51
+ imag: a.imag - b.imag
52
+ });
53
+ }
54
+ function multiplyComplex(a, b) {
55
+ validateComplexNumber(a, "First complex number");
56
+ validateComplexNumber(b, "Second complex number");
57
+ return normalizeComplex({
58
+ real: a.real * b.real - a.imag * b.imag,
59
+ imag: a.real * b.imag + a.imag * b.real
60
+ });
61
+ }
62
+ function divideComplex(a, b) {
63
+ validateComplexNumber(a, "Numerator complex number");
64
+ validateComplexNumber(b, "Denominator complex number");
65
+ const denominator = b.real * b.real + b.imag * b.imag;
66
+ if (isApproximatelyZero(denominator)) {
67
+ throw new Error("Cannot divide by zero or near-zero complex number");
68
+ }
69
+ return normalizeComplex({
70
+ real: (a.real * b.real + a.imag * b.imag) / denominator,
71
+ imag: (a.imag * b.real - a.real * b.imag) / denominator
72
+ });
73
+ }
74
+ function magnitudeComplex(c) {
75
+ validateComplexNumber(c);
76
+ const magnitude = Math.sqrt(c.real * c.real + c.imag * c.imag);
77
+ return isApproximatelyZero(magnitude) ? 0 : magnitude;
78
+ }
79
+ function conjugateComplex(c) {
80
+ validateComplexNumber(c);
81
+ return normalizeComplex({
82
+ real: c.real,
83
+ imag: -c.imag
84
+ });
85
+ }
86
+ function argumentComplex(c) {
87
+ validateComplexNumber(c);
88
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
89
+ return 0;
90
+ }
91
+ return Math.atan2(c.imag, c.real);
92
+ }
93
+ function toPolarComplex(c) {
94
+ validateComplexNumber(c);
95
+ return {
96
+ magnitude: magnitudeComplex(c),
97
+ angle: argumentComplex(c)
98
+ };
99
+ }
100
+ function fromPolarComplex(magnitude, angle) {
101
+ validateNumber(magnitude, "magnitude");
102
+ validateNumber(angle, "angle");
103
+ if (magnitude < -EPSILON) {
104
+ throw new Error("Magnitude must be non-negative");
105
+ }
106
+ let normalizedAngle = angle % TWO_PI;
107
+ if (normalizedAngle > Math.PI) normalizedAngle -= TWO_PI;
108
+ if (normalizedAngle <= -Math.PI) normalizedAngle += TWO_PI;
109
+ const mag = Math.max(0, magnitude);
110
+ return normalizeComplex({
111
+ real: mag * Math.cos(normalizedAngle),
112
+ imag: mag * Math.sin(normalizedAngle)
113
+ });
114
+ }
115
+ function sqrtComplex(c) {
116
+ validateComplexNumber(c);
117
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
118
+ const zero = createComplex(0, 0);
119
+ return [zero, zero];
120
+ }
121
+ const magnitude = magnitudeComplex(c);
122
+ const angle = argumentComplex(c);
123
+ const rootMagnitude = Math.sqrt(magnitude);
124
+ const rootAngle1 = angle / 2;
125
+ const rootAngle2 = rootAngle1 + Math.PI;
126
+ return [
127
+ fromPolarComplex(rootMagnitude, rootAngle1),
128
+ fromPolarComplex(rootMagnitude, rootAngle2)
129
+ ];
130
+ }
131
+ function powerComplex(c, exponent) {
132
+ validateComplexNumber(c);
133
+ validateNumber(exponent, "exponent");
134
+ if (isApproximatelyZero(exponent)) {
135
+ return createComplex(1, 0);
136
+ }
137
+ if (approximatelyEqual(exponent, 1)) {
138
+ return createComplex(c.real, c.imag);
139
+ }
140
+ if (approximatelyEqual(exponent, 2)) {
141
+ return multiplyComplex(c, c);
142
+ }
143
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
144
+ if (exponent > 0) {
145
+ return createComplex(0, 0);
146
+ } else if (exponent < 0) {
147
+ throw new Error("Cannot raise zero to a negative power");
148
+ }
149
+ }
150
+ const polar = toPolarComplex(c);
151
+ const magnitude = Math.pow(polar.magnitude, exponent);
152
+ const safeMagnitude = magnitude < -EPSILON ? Math.abs(magnitude) : Math.max(0, magnitude);
153
+ const angle = polar.angle * exponent;
154
+ return fromPolarComplex(safeMagnitude, angle);
155
+ }
156
+ function lnComplex(c) {
157
+ validateComplexNumber(c);
158
+ const magnitude = magnitudeComplex(c);
159
+ if (isApproximatelyZero(magnitude)) {
160
+ throw new Error(
161
+ "Cannot take logarithm of zero or near-zero complex number"
162
+ );
163
+ }
164
+ const angle = argumentComplex(c);
165
+ return normalizeComplex({
166
+ real: Math.log(magnitude),
167
+ imag: angle
168
+ });
169
+ }
170
+ function expComplex(c) {
171
+ validateComplexNumber(c);
172
+ const expReal = Math.exp(c.real);
173
+ return normalizeComplex({
174
+ real: expReal * Math.cos(c.imag),
175
+ imag: expReal * Math.sin(c.imag)
176
+ });
177
+ }
178
+ function sinComplex(c) {
179
+ validateComplexNumber(c);
180
+ return normalizeComplex({
181
+ real: Math.sin(c.real) * Math.cosh(c.imag),
182
+ imag: Math.cos(c.real) * Math.sinh(c.imag)
183
+ });
184
+ }
185
+ function cosComplex(c) {
186
+ validateComplexNumber(c);
187
+ return normalizeComplex({
188
+ real: Math.cos(c.real) * Math.cosh(c.imag),
189
+ imag: -Math.sin(c.real) * Math.sinh(c.imag)
190
+ });
191
+ }
192
+ function isZeroComplex(c) {
193
+ validateComplexNumber(c);
194
+ return isApproximatelyZero(c.real) && isApproximatelyZero(c.imag);
195
+ }
196
+ function getReal(c) {
197
+ validateComplexNumber(c);
198
+ return c.real;
199
+ }
200
+ function getImag(c) {
201
+ validateComplexNumber(c);
202
+ return c.imag;
203
+ }
204
+ function negateComplex(c) {
205
+ validateComplexNumber(c);
206
+ return normalizeComplex({
207
+ real: -c.real,
208
+ imag: -c.imag
209
+ });
210
+ }
211
+ function reciprocalComplex(c) {
212
+ validateComplexNumber(c);
213
+ const denominator = c.real * c.real + c.imag * c.imag;
214
+ if (isApproximatelyZero(denominator)) {
215
+ throw new Error(
216
+ "Cannot calculate reciprocal of zero or near-zero complex number"
217
+ );
218
+ }
219
+ return normalizeComplex({
220
+ real: c.real / denominator,
221
+ imag: -c.imag / denominator
222
+ });
223
+ }
224
+ export {
225
+ addComplex,
226
+ argumentComplex,
227
+ complexEquals,
228
+ conjugateComplex,
229
+ cosComplex,
230
+ createComplex,
231
+ divideComplex,
232
+ expComplex,
233
+ fromPolarComplex,
234
+ getImag,
235
+ getReal,
236
+ isZeroComplex,
237
+ lnComplex,
238
+ magnitudeComplex,
239
+ multiplyComplex,
240
+ negateComplex,
241
+ powerComplex,
242
+ reciprocalComplex,
243
+ sinComplex,
244
+ sqrtComplex,
245
+ subtractComplex,
246
+ toPolarComplex
247
+ };