@gridsheet/functions 3.0.0-rc.2

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 (247) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +332 -0
  4. package/dist/information/index.d.ts +4 -0
  5. package/dist/information/index.d.ts.map +1 -0
  6. package/dist/information/isblank.d.ts +9 -0
  7. package/dist/information/isblank.d.ts.map +1 -0
  8. package/dist/information/isdate.d.ts +9 -0
  9. package/dist/information/isdate.d.ts.map +1 -0
  10. package/dist/information/isemail.d.ts +9 -0
  11. package/dist/information/isemail.d.ts.map +1 -0
  12. package/dist/information/iserr.d.ts +9 -0
  13. package/dist/information/iserr.d.ts.map +1 -0
  14. package/dist/information/iserror.d.ts +9 -0
  15. package/dist/information/iserror.d.ts.map +1 -0
  16. package/dist/information/isformula.d.ts +9 -0
  17. package/dist/information/isformula.d.ts.map +1 -0
  18. package/dist/information/islogical.d.ts +9 -0
  19. package/dist/information/islogical.d.ts.map +1 -0
  20. package/dist/information/isna.d.ts +9 -0
  21. package/dist/information/isna.d.ts.map +1 -0
  22. package/dist/information/isnontext.d.ts +9 -0
  23. package/dist/information/isnontext.d.ts.map +1 -0
  24. package/dist/information/isref.d.ts +9 -0
  25. package/dist/information/isref.d.ts.map +1 -0
  26. package/dist/information/istext.d.ts +9 -0
  27. package/dist/information/istext.d.ts.map +1 -0
  28. package/dist/information/n.d.ts +9 -0
  29. package/dist/information/n.d.ts.map +1 -0
  30. package/dist/information/na.d.ts +9 -0
  31. package/dist/information/na.d.ts.map +1 -0
  32. package/dist/information/sheets.d.ts +9 -0
  33. package/dist/information/sheets.d.ts.map +1 -0
  34. package/dist/logical/ifna.d.ts +10 -0
  35. package/dist/logical/ifna.d.ts.map +1 -0
  36. package/dist/logical/ifs.d.ts +11 -0
  37. package/dist/logical/ifs.d.ts.map +1 -0
  38. package/dist/logical/index.d.ts +4 -0
  39. package/dist/logical/index.d.ts.map +1 -0
  40. package/dist/logical/xor.d.ts +9 -0
  41. package/dist/logical/xor.d.ts.map +1 -0
  42. package/dist/lookup/column.d.ts +12 -0
  43. package/dist/lookup/column.d.ts.map +1 -0
  44. package/dist/lookup/columns.d.ts +9 -0
  45. package/dist/lookup/columns.d.ts.map +1 -0
  46. package/dist/lookup/hlookup.d.ts +10 -0
  47. package/dist/lookup/hlookup.d.ts.map +1 -0
  48. package/dist/lookup/index.d.ts +4 -0
  49. package/dist/lookup/index.d.ts.map +1 -0
  50. package/dist/lookup/index.js +377 -0
  51. package/dist/lookup/indexFn.d.ts +10 -0
  52. package/dist/lookup/indexFn.d.ts.map +1 -0
  53. package/dist/lookup/match.d.ts +10 -0
  54. package/dist/lookup/match.d.ts.map +1 -0
  55. package/dist/lookup/row.d.ts +12 -0
  56. package/dist/lookup/row.d.ts.map +1 -0
  57. package/dist/lookup/rows.d.ts +9 -0
  58. package/dist/lookup/rows.d.ts.map +1 -0
  59. package/dist/lookup/sheet.d.ts +9 -0
  60. package/dist/lookup/sheet.d.ts.map +1 -0
  61. package/dist/lookup/vlookup.d.ts +10 -0
  62. package/dist/lookup/vlookup.d.ts.map +1 -0
  63. package/dist/math/__matrix_base.d.ts +15 -0
  64. package/dist/math/__matrix_base.d.ts.map +1 -0
  65. package/dist/math/acos.d.ts +9 -0
  66. package/dist/math/acos.d.ts.map +1 -0
  67. package/dist/math/asin.d.ts +9 -0
  68. package/dist/math/asin.d.ts.map +1 -0
  69. package/dist/math/atan.d.ts +9 -0
  70. package/dist/math/atan.d.ts.map +1 -0
  71. package/dist/math/atan2.d.ts +9 -0
  72. package/dist/math/atan2.d.ts.map +1 -0
  73. package/dist/math/base.d.ts +10 -0
  74. package/dist/math/base.d.ts.map +1 -0
  75. package/dist/math/cos.d.ts +9 -0
  76. package/dist/math/cos.d.ts.map +1 -0
  77. package/dist/math/countif.d.ts +9 -0
  78. package/dist/math/countif.d.ts.map +1 -0
  79. package/dist/math/countifs.d.ts +10 -0
  80. package/dist/math/countifs.d.ts.map +1 -0
  81. package/dist/math/even.d.ts +9 -0
  82. package/dist/math/even.d.ts.map +1 -0
  83. package/dist/math/exp.d.ts +10 -0
  84. package/dist/math/exp.d.ts.map +1 -0
  85. package/dist/math/fact.d.ts +9 -0
  86. package/dist/math/fact.d.ts.map +1 -0
  87. package/dist/math/index.d.ts +4 -0
  88. package/dist/math/index.d.ts.map +1 -0
  89. package/dist/math/index.js +1019 -0
  90. package/dist/math/int.d.ts +9 -0
  91. package/dist/math/int.d.ts.map +1 -0
  92. package/dist/math/iseven.d.ts +9 -0
  93. package/dist/math/iseven.d.ts.map +1 -0
  94. package/dist/math/isodd.d.ts +9 -0
  95. package/dist/math/isodd.d.ts.map +1 -0
  96. package/dist/math/lcm.d.ts +10 -0
  97. package/dist/math/lcm.d.ts.map +1 -0
  98. package/dist/math/ln.d.ts +9 -0
  99. package/dist/math/ln.d.ts.map +1 -0
  100. package/dist/math/log.d.ts +9 -0
  101. package/dist/math/log.d.ts.map +1 -0
  102. package/dist/math/log10.d.ts +9 -0
  103. package/dist/math/log10.d.ts.map +1 -0
  104. package/dist/math/mdeterm.d.ts +11 -0
  105. package/dist/math/mdeterm.d.ts.map +1 -0
  106. package/dist/math/minverse.d.ts +12 -0
  107. package/dist/math/minverse.d.ts.map +1 -0
  108. package/dist/math/mmult.d.ts +11 -0
  109. package/dist/math/mmult.d.ts.map +1 -0
  110. package/dist/math/mod.d.ts +10 -0
  111. package/dist/math/mod.d.ts.map +1 -0
  112. package/dist/math/odd.d.ts +9 -0
  113. package/dist/math/odd.d.ts.map +1 -0
  114. package/dist/math/pi.d.ts +9 -0
  115. package/dist/math/pi.d.ts.map +1 -0
  116. package/dist/math/product.d.ts +10 -0
  117. package/dist/math/product.d.ts.map +1 -0
  118. package/dist/math/radians.d.ts +9 -0
  119. package/dist/math/radians.d.ts.map +1 -0
  120. package/dist/math/rand.d.ts +9 -0
  121. package/dist/math/rand.d.ts.map +1 -0
  122. package/dist/math/round.d.ts +9 -0
  123. package/dist/math/round.d.ts.map +1 -0
  124. package/dist/math/rounddown.d.ts +9 -0
  125. package/dist/math/rounddown.d.ts.map +1 -0
  126. package/dist/math/roundup.d.ts +9 -0
  127. package/dist/math/roundup.d.ts.map +1 -0
  128. package/dist/math/sequence.d.ts +11 -0
  129. package/dist/math/sequence.d.ts.map +1 -0
  130. package/dist/math/sign.d.ts +9 -0
  131. package/dist/math/sign.d.ts.map +1 -0
  132. package/dist/math/sin.d.ts +9 -0
  133. package/dist/math/sin.d.ts.map +1 -0
  134. package/dist/math/sqrt.d.ts +9 -0
  135. package/dist/math/sqrt.d.ts.map +1 -0
  136. package/dist/math/sumif.d.ts +9 -0
  137. package/dist/math/sumif.d.ts.map +1 -0
  138. package/dist/math/sumifs.d.ts +10 -0
  139. package/dist/math/sumifs.d.ts.map +1 -0
  140. package/dist/math/sumproduct.d.ts +10 -0
  141. package/dist/math/sumproduct.d.ts.map +1 -0
  142. package/dist/math/sumsq.d.ts +9 -0
  143. package/dist/math/sumsq.d.ts.map +1 -0
  144. package/dist/math/tan.d.ts +9 -0
  145. package/dist/math/tan.d.ts.map +1 -0
  146. package/dist/math/transpose.d.ts +11 -0
  147. package/dist/math/transpose.d.ts.map +1 -0
  148. package/dist/math/trunc.d.ts +9 -0
  149. package/dist/math/trunc.d.ts.map +1 -0
  150. package/dist/math/unaryPercent.d.ts +9 -0
  151. package/dist/math/unaryPercent.d.ts.map +1 -0
  152. package/dist/math/uplus.d.ts +9 -0
  153. package/dist/math/uplus.d.ts.map +1 -0
  154. package/dist/statistics/averageif.d.ts +9 -0
  155. package/dist/statistics/averageif.d.ts.map +1 -0
  156. package/dist/statistics/averageifs.d.ts +10 -0
  157. package/dist/statistics/averageifs.d.ts.map +1 -0
  158. package/dist/statistics/correl.d.ts +10 -0
  159. package/dist/statistics/correl.d.ts.map +1 -0
  160. package/dist/statistics/covariance_s.d.ts +10 -0
  161. package/dist/statistics/covariance_s.d.ts.map +1 -0
  162. package/dist/statistics/index.d.ts +4 -0
  163. package/dist/statistics/index.d.ts.map +1 -0
  164. package/dist/statistics/index.js +663 -0
  165. package/dist/statistics/median.d.ts +10 -0
  166. package/dist/statistics/median.d.ts.map +1 -0
  167. package/dist/statistics/mode_sngl.d.ts +10 -0
  168. package/dist/statistics/mode_sngl.d.ts.map +1 -0
  169. package/dist/statistics/percentile_inc.d.ts +10 -0
  170. package/dist/statistics/percentile_inc.d.ts.map +1 -0
  171. package/dist/statistics/quartile_inc.d.ts +10 -0
  172. package/dist/statistics/quartile_inc.d.ts.map +1 -0
  173. package/dist/statistics/rank_eq.d.ts +10 -0
  174. package/dist/statistics/rank_eq.d.ts.map +1 -0
  175. package/dist/statistics/rsq.d.ts +10 -0
  176. package/dist/statistics/rsq.d.ts.map +1 -0
  177. package/dist/statistics/stdev_p.d.ts +10 -0
  178. package/dist/statistics/stdev_p.d.ts.map +1 -0
  179. package/dist/statistics/stdev_s.d.ts +10 -0
  180. package/dist/statistics/stdev_s.d.ts.map +1 -0
  181. package/dist/statistics/t_test.d.ts +10 -0
  182. package/dist/statistics/t_test.d.ts.map +1 -0
  183. package/dist/statistics/var_p.d.ts +10 -0
  184. package/dist/statistics/var_p.d.ts.map +1 -0
  185. package/dist/statistics/var_s.d.ts +10 -0
  186. package/dist/statistics/var_s.d.ts.map +1 -0
  187. package/dist/text/char.d.ts +9 -0
  188. package/dist/text/char.d.ts.map +1 -0
  189. package/dist/text/clean.d.ts +9 -0
  190. package/dist/text/clean.d.ts.map +1 -0
  191. package/dist/text/concatenate.d.ts +9 -0
  192. package/dist/text/concatenate.d.ts.map +1 -0
  193. package/dist/text/exact.d.ts +9 -0
  194. package/dist/text/exact.d.ts.map +1 -0
  195. package/dist/text/index.d.ts +4 -0
  196. package/dist/text/index.d.ts.map +1 -0
  197. package/dist/text/index.js +261 -0
  198. package/dist/text/join.d.ts +10 -0
  199. package/dist/text/join.d.ts.map +1 -0
  200. package/dist/text/lenb.d.ts +9 -0
  201. package/dist/text/lenb.d.ts.map +1 -0
  202. package/dist/text/lower.d.ts +9 -0
  203. package/dist/text/lower.d.ts.map +1 -0
  204. package/dist/text/proper.d.ts +9 -0
  205. package/dist/text/proper.d.ts.map +1 -0
  206. package/dist/text/replace.d.ts +10 -0
  207. package/dist/text/replace.d.ts.map +1 -0
  208. package/dist/text/rept.d.ts +10 -0
  209. package/dist/text/rept.d.ts.map +1 -0
  210. package/dist/text/trim.d.ts +9 -0
  211. package/dist/text/trim.d.ts.map +1 -0
  212. package/dist/text/unichar.d.ts +9 -0
  213. package/dist/text/unichar.d.ts.map +1 -0
  214. package/dist/text/unicode.d.ts +9 -0
  215. package/dist/text/unicode.d.ts.map +1 -0
  216. package/dist/text/upper.d.ts +9 -0
  217. package/dist/text/upper.d.ts.map +1 -0
  218. package/dist/time/__utils.d.ts +6 -0
  219. package/dist/time/__utils.d.ts.map +1 -0
  220. package/dist/time/date.d.ts +9 -0
  221. package/dist/time/date.d.ts.map +1 -0
  222. package/dist/time/day.d.ts +9 -0
  223. package/dist/time/day.d.ts.map +1 -0
  224. package/dist/time/days.d.ts +9 -0
  225. package/dist/time/days.d.ts.map +1 -0
  226. package/dist/time/hour.d.ts +9 -0
  227. package/dist/time/hour.d.ts.map +1 -0
  228. package/dist/time/index.d.ts +4 -0
  229. package/dist/time/index.d.ts.map +1 -0
  230. package/dist/time/index.js +212 -0
  231. package/dist/time/minute.d.ts +9 -0
  232. package/dist/time/minute.d.ts.map +1 -0
  233. package/dist/time/month.d.ts +9 -0
  234. package/dist/time/month.d.ts.map +1 -0
  235. package/dist/time/second.d.ts +9 -0
  236. package/dist/time/second.d.ts.map +1 -0
  237. package/dist/time/time.d.ts +9 -0
  238. package/dist/time/time.d.ts.map +1 -0
  239. package/dist/time/today.d.ts +9 -0
  240. package/dist/time/today.d.ts.map +1 -0
  241. package/dist/time/workday.d.ts +9 -0
  242. package/dist/time/workday.d.ts.map +1 -0
  243. package/dist/time/year.d.ts +9 -0
  244. package/dist/time/year.d.ts.map +1 -0
  245. package/dist/types.d.ts +2 -0
  246. package/dist/types.d.ts.map +1 -0
  247. package/package.json +86 -0
@@ -0,0 +1,663 @@
1
+ import { BaseFunction as A, conditionArg as x, ensureString as M, eachMatrix as g, stripTable as T, check as R, FormulaError as d, Table as w, createBooleanMask as q, ensureNumber as f } from "@gridsheet/react-core";
2
+ const k = "Returns the average of a series of cells that meet a condition.";
3
+ class S extends A {
4
+ constructor() {
5
+ super(...arguments), this.example = 'AVERAGEIF(A1:A10,">20")', this.description = k, this.defs = [
6
+ { name: "range", description: "A condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
7
+ x,
8
+ {
9
+ name: "average_range",
10
+ description: "A range to be averaged.",
11
+ takesMatrix: !0,
12
+ acceptedTypes: ["matrix"],
13
+ optional: !0
14
+ }
15
+ ], this.category = "statistics";
16
+ }
17
+ main(t, n, r) {
18
+ const e = M(n), a = [], i = [];
19
+ g(
20
+ t,
21
+ (s) => {
22
+ a.push(s);
23
+ },
24
+ this.at
25
+ ), r && g(
26
+ r,
27
+ (s) => {
28
+ i.push(s);
29
+ },
30
+ this.at
31
+ );
32
+ let u = 0, o = 0;
33
+ if (a.forEach((s, l) => {
34
+ const h = T({ value: (r ? i[l] : s) ?? 0 });
35
+ typeof h == "number" && R(s, e) && (u += h, o++);
36
+ }), o === 0)
37
+ throw new d("#DIV/0!", "No cells match the condition.");
38
+ return u / o;
39
+ }
40
+ }
41
+ const I = "Returns the average of a range depending on multiple criteria.";
42
+ class V extends A {
43
+ constructor() {
44
+ super(...arguments), this.example = 'AVERAGEIFS(A1:A10, B1:B10, ">20")', this.description = I, this.defs = [
45
+ { name: "average_range", description: "The range to be averaged.", takesMatrix: !0, acceptedTypes: ["matrix"] },
46
+ { name: "range1", description: "First condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
47
+ { ...x, name: "condition1" },
48
+ {
49
+ name: "range2",
50
+ description: "Additional condition range.",
51
+ takesMatrix: !0,
52
+ acceptedTypes: ["matrix"],
53
+ optional: !0,
54
+ variadic: !0
55
+ },
56
+ { ...x, name: "condition2", optional: !0, variadic: !0 }
57
+ ], this.category = "statistics";
58
+ }
59
+ validate(t) {
60
+ const n = super.validate(t);
61
+ if ((n.length - 1) % 2 !== 0)
62
+ throw new d("#N/A", "AVERAGEIFS requires average_range and at least one range/condition pair.");
63
+ if (!(n[0] instanceof w))
64
+ throw new d("#VALUE!", "First argument of AVERAGEIFS must be a range.");
65
+ const r = n[0].getNumRows(), e = n[0].getNumCols(), a = [], i = [];
66
+ for (let s = 1; s < n.length; s += 2) {
67
+ if (!(n[s] instanceof w))
68
+ throw new d("#VALUE!", `Argument ${s + 1} of AVERAGEIFS must be a range.`);
69
+ if (n[s].getNumRows() !== r || n[s].getNumCols() !== e)
70
+ throw new d("#VALUE!", "Array arguments to AVERAGEIFS are of different size.");
71
+ a.push(n[s]), i.push(M(n[s + 1]));
72
+ }
73
+ const u = n[0], o = q(a, i, this.at);
74
+ return [u, o];
75
+ }
76
+ main(t, n) {
77
+ let r = 0, e = 0;
78
+ return g(
79
+ t,
80
+ (a, i) => {
81
+ if (i && n[i.y][i.x]) {
82
+ const u = T({ value: a ?? 0 });
83
+ typeof u == "number" && (r += u, e++);
84
+ }
85
+ },
86
+ this.at
87
+ ), e === 0 ? new d("#DIV/0!", "No matching cells found for AVERAGEIFS.") : r / e;
88
+ }
89
+ }
90
+ const F = "Returns the median value in a numeric dataset.";
91
+ class D extends A {
92
+ constructor() {
93
+ super(...arguments), this.example = "MEDIAN(A1:A100)", this.description = F, this.defs = [
94
+ {
95
+ name: "value",
96
+ description: "Numbers or ranges to compute the median of.",
97
+ takesMatrix: !0,
98
+ acceptedTypes: ["number", "matrix"],
99
+ variadic: !0
100
+ }
101
+ ], this.category = "statistics";
102
+ }
103
+ validate(t) {
104
+ const n = [];
105
+ for (const r of t)
106
+ g(
107
+ r,
108
+ (e) => {
109
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
110
+ },
111
+ this.at
112
+ );
113
+ if (n.length === 0)
114
+ throw new d("#NUM!", "MEDIAN requires at least one numeric value.");
115
+ return [n];
116
+ }
117
+ main(t) {
118
+ t.sort((r, e) => r - e);
119
+ const n = Math.floor(t.length / 2);
120
+ return t.length % 2 === 0 ? (t[n - 1] + t[n]) / 2 : t[n];
121
+ }
122
+ }
123
+ const B = "Returns the standard deviation based on a sample.";
124
+ class C extends A {
125
+ constructor() {
126
+ super(...arguments), this.example = "STDEV.S(A1:A100)", this.description = B, this.defs = [
127
+ {
128
+ name: "value",
129
+ description: "Numbers or ranges representing the sample.",
130
+ takesMatrix: !0,
131
+ acceptedTypes: ["number", "matrix"],
132
+ variadic: !0
133
+ }
134
+ ], this.category = "statistics";
135
+ }
136
+ validate(t) {
137
+ const n = [];
138
+ for (const r of t)
139
+ g(
140
+ r,
141
+ (e) => {
142
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
143
+ },
144
+ this.at
145
+ );
146
+ if (n.length < 2)
147
+ throw new d("#DIV/0!", "STDEV.S requires at least 2 numeric values.");
148
+ return [n];
149
+ }
150
+ main(t) {
151
+ const n = t.reduce((e, a) => e + a, 0) / t.length, r = t.reduce((e, a) => e + (a - n) ** 2, 0) / (t.length - 1);
152
+ return Math.sqrt(r);
153
+ }
154
+ }
155
+ const P = "Returns the standard deviation based on the entire population.";
156
+ class $ extends A {
157
+ constructor() {
158
+ super(...arguments), this.example = "STDEV.P(A1:A100)", this.description = P, this.defs = [
159
+ {
160
+ name: "value",
161
+ description: "Numbers or ranges representing the entire population.",
162
+ takesMatrix: !0,
163
+ acceptedTypes: ["number", "matrix"],
164
+ variadic: !0
165
+ }
166
+ ], this.category = "statistics";
167
+ }
168
+ validate(t) {
169
+ const n = [];
170
+ for (const r of t)
171
+ g(
172
+ r,
173
+ (e) => {
174
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
175
+ },
176
+ this.at
177
+ );
178
+ if (n.length < 1)
179
+ throw new d("#DIV/0!", "STDEV.P requires at least 1 numeric value.");
180
+ return [n];
181
+ }
182
+ main(t) {
183
+ const n = t.reduce((e, a) => e + a, 0) / t.length, r = t.reduce((e, a) => e + (a - n) ** 2, 0) / t.length;
184
+ return Math.sqrt(r);
185
+ }
186
+ }
187
+ const v = "Returns the variance based on a sample.";
188
+ class U extends A {
189
+ constructor() {
190
+ super(...arguments), this.example = "VAR.S(A1:A100)", this.description = v, this.defs = [
191
+ {
192
+ name: "value",
193
+ description: "Numbers or ranges representing the sample.",
194
+ takesMatrix: !0,
195
+ acceptedTypes: ["number", "matrix"],
196
+ variadic: !0
197
+ }
198
+ ], this.category = "statistics";
199
+ }
200
+ validate(t) {
201
+ const n = [];
202
+ for (const r of t)
203
+ g(
204
+ r,
205
+ (e) => {
206
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
207
+ },
208
+ this.at
209
+ );
210
+ if (n.length < 2)
211
+ throw new d("#DIV/0!", "VAR.S requires at least 2 numeric values.");
212
+ return [n];
213
+ }
214
+ main(t) {
215
+ const n = t.reduce((r, e) => r + e, 0) / t.length;
216
+ return t.reduce((r, e) => r + (e - n) ** 2, 0) / (t.length - 1);
217
+ }
218
+ }
219
+ const L = "Returns the variance based on the entire population.";
220
+ class Q extends A {
221
+ constructor() {
222
+ super(...arguments), this.example = "VAR.P(A1:A100)", this.description = L, this.defs = [
223
+ {
224
+ name: "value",
225
+ description: "Numbers or ranges representing the entire population.",
226
+ takesMatrix: !0,
227
+ acceptedTypes: ["number", "matrix"],
228
+ variadic: !0
229
+ }
230
+ ], this.category = "statistics";
231
+ }
232
+ validate(t) {
233
+ const n = [];
234
+ for (const r of t)
235
+ g(
236
+ r,
237
+ (e) => {
238
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
239
+ },
240
+ this.at
241
+ );
242
+ if (n.length < 1)
243
+ throw new d("#DIV/0!", "VAR.P requires at least 1 numeric value.");
244
+ return [n];
245
+ }
246
+ main(t) {
247
+ const n = t.reduce((r, e) => r + e, 0) / t.length;
248
+ return t.reduce((r, e) => r + (e - n) ** 2, 0) / t.length;
249
+ }
250
+ }
251
+ const _ = "Returns the k-th percentile of values in a range, where k is in the range 0 to 1, inclusive.";
252
+ class G extends A {
253
+ constructor() {
254
+ super(...arguments), this.example = "PERCENTILE.INC(A1:A100, 0.9)", this.description = _, this.defs = [
255
+ {
256
+ name: "data",
257
+ description: "The array or range of data to consider.",
258
+ takesMatrix: !0,
259
+ acceptedTypes: ["matrix"]
260
+ },
261
+ { name: "percentile", description: "The percentile value between 0 and 1, inclusive.", acceptedTypes: ["number"] }
262
+ ], this.category = "statistics";
263
+ }
264
+ validate(t) {
265
+ const n = f(t[1]);
266
+ if (n < 0 || n > 1)
267
+ throw new d("#NUM!", "Percentile must be between 0 and 1.");
268
+ const r = [];
269
+ if (g(
270
+ t[0],
271
+ (e) => {
272
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
273
+ },
274
+ this.at
275
+ ), r.length === 0)
276
+ throw new d("#NUM!", "PERCENTILE.INC requires at least one numeric value.");
277
+ return [r, n];
278
+ }
279
+ main(t, n) {
280
+ t.sort((i, u) => i - u);
281
+ const r = n * (t.length - 1), e = Math.floor(r), a = Math.ceil(r);
282
+ return t[e] + (t[a] - t[e]) * (r - e);
283
+ }
284
+ }
285
+ const O = "Returns the quartile of a dataset, based on percentile values from 0 to 1, inclusive.";
286
+ class X extends A {
287
+ constructor() {
288
+ super(...arguments), this.example = "QUARTILE.INC(A1:A100, 1)", this.description = O, this.defs = [
289
+ {
290
+ name: "data",
291
+ description: "The array or range of data to consider.",
292
+ takesMatrix: !0,
293
+ acceptedTypes: ["matrix"]
294
+ },
295
+ {
296
+ name: "quartile_number",
297
+ description: "Which quartile to return: 0 (min), 1 (Q1), 2 (median), 3 (Q3), 4 (max).",
298
+ acceptedTypes: ["number"]
299
+ }
300
+ ], this.category = "statistics";
301
+ }
302
+ validate(t) {
303
+ const n = Math.floor(f(t[1]));
304
+ if (n < 0 || n > 4)
305
+ throw new d("#NUM!", "Quartile number must be between 0 and 4.");
306
+ const r = [];
307
+ if (g(
308
+ t[0],
309
+ (e) => {
310
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
311
+ },
312
+ this.at
313
+ ), r.length === 0)
314
+ throw new d("#NUM!", "QUARTILE.INC requires at least one numeric value.");
315
+ return [r, n];
316
+ }
317
+ main(t, n) {
318
+ t.sort((u, o) => u - o);
319
+ const e = n / 4 * (t.length - 1), a = Math.floor(e), i = Math.ceil(e);
320
+ return t[a] + (t[i] - t[a]) * (e - a);
321
+ }
322
+ }
323
+ const Y = "Returns the rank of a number in a list of numbers. If more than one value has the same rank, the top rank of that set of values is returned.";
324
+ class K extends A {
325
+ constructor() {
326
+ super(...arguments), this.example = "RANK.EQ(A1, A1:A100)", this.description = Y, this.defs = [
327
+ { name: "value", description: "The value whose rank will be determined.", acceptedTypes: ["number"] },
328
+ {
329
+ name: "data",
330
+ description: "The array or range of data to consider.",
331
+ takesMatrix: !0,
332
+ acceptedTypes: ["matrix"]
333
+ },
334
+ {
335
+ name: "is_ascending",
336
+ description: "Whether to rank in ascending order. Default is FALSE (descending).",
337
+ acceptedTypes: ["boolean"],
338
+ optional: !0
339
+ }
340
+ ], this.category = "statistics";
341
+ }
342
+ validate(t) {
343
+ const n = f(t[0]), r = [];
344
+ if (g(
345
+ t[1],
346
+ (a) => {
347
+ a == null || a === "" || typeof a == "boolean" || (typeof a == "number" || typeof a == "string" && !isNaN(Number(a))) && r.push(f(a));
348
+ },
349
+ this.at
350
+ ), r.length === 0)
351
+ throw new d("#NUM!", "RANK.EQ requires at least one numeric value in data.");
352
+ if (!r.includes(n))
353
+ throw new d("#N/A", "Value not found in data range.");
354
+ const e = t[2] ?? !1;
355
+ return [n, r, e];
356
+ }
357
+ main(t, n, r) {
358
+ return n.sort((e, a) => r ? e - a : a - e), n.indexOf(t) + 1;
359
+ }
360
+ }
361
+ const W = "Returns the correlation coefficient of two datasets.";
362
+ class j extends A {
363
+ constructor() {
364
+ super(...arguments), this.example = "CORREL(A1:A100, B1:B100)", this.description = W, this.defs = [
365
+ {
366
+ name: "data_y",
367
+ description: "The range representing the dependent data.",
368
+ takesMatrix: !0,
369
+ acceptedTypes: ["matrix"]
370
+ },
371
+ {
372
+ name: "data_x",
373
+ description: "The range representing the independent data.",
374
+ takesMatrix: !0,
375
+ acceptedTypes: ["matrix"]
376
+ }
377
+ ], this.category = "statistics";
378
+ }
379
+ validate(t) {
380
+ const n = [], r = [];
381
+ if (g(
382
+ t[0],
383
+ (e) => {
384
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
385
+ },
386
+ this.at
387
+ ), g(
388
+ t[1],
389
+ (e) => {
390
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
391
+ },
392
+ this.at
393
+ ), n.length !== r.length || n.length < 2)
394
+ throw new d("#N/A", "CORREL requires two ranges of equal length with at least 2 values.");
395
+ return [n, r];
396
+ }
397
+ main(t, n) {
398
+ const r = t.length, e = t.reduce((l, h) => l + h, 0) / r, a = n.reduce((l, h) => l + h, 0) / r;
399
+ let i = 0, u = 0, o = 0;
400
+ for (let l = 0; l < r; l++) {
401
+ const h = t[l] - e, p = n[l] - a;
402
+ i += h * p, u += h * h, o += p * p;
403
+ }
404
+ const s = Math.sqrt(u * o);
405
+ if (s === 0)
406
+ throw new d("#DIV/0!", "Standard deviation of one dataset is zero.");
407
+ return i / s;
408
+ }
409
+ }
410
+ const H = "Returns the sample covariance, the average of the products of deviations for each data point pair in two datasets.";
411
+ class J extends A {
412
+ constructor() {
413
+ super(...arguments), this.example = "COVARIANCE.S(A1:A100, B1:B100)", this.description = H, this.defs = [
414
+ {
415
+ name: "data_y",
416
+ description: "The range representing the first dataset.",
417
+ takesMatrix: !0,
418
+ acceptedTypes: ["matrix"]
419
+ },
420
+ {
421
+ name: "data_x",
422
+ description: "The range representing the second dataset.",
423
+ takesMatrix: !0,
424
+ acceptedTypes: ["matrix"]
425
+ }
426
+ ], this.category = "statistics";
427
+ }
428
+ validate(t) {
429
+ const n = [], r = [];
430
+ if (g(
431
+ t[0],
432
+ (e) => {
433
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
434
+ },
435
+ this.at
436
+ ), g(
437
+ t[1],
438
+ (e) => {
439
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
440
+ },
441
+ this.at
442
+ ), n.length !== r.length || n.length < 2)
443
+ throw new d("#N/A", "COVARIANCE.S requires two ranges of equal length with at least 2 values.");
444
+ return [n, r];
445
+ }
446
+ main(t, n) {
447
+ const r = t.length, e = t.reduce((i, u) => i + u, 0) / r, a = n.reduce((i, u) => i + u, 0) / r;
448
+ return t.reduce((i, u, o) => i + (u - e) * (n[o] - a), 0) / (r - 1);
449
+ }
450
+ }
451
+ const Z = "Returns the most commonly occurring value in a dataset. If there are multiple modes, the smallest is returned.";
452
+ class z extends A {
453
+ constructor() {
454
+ super(...arguments), this.example = "MODE.SNGL(A1:A100)", this.description = Z, this.defs = [
455
+ {
456
+ name: "value",
457
+ description: "Numbers or ranges to compute the mode of.",
458
+ takesMatrix: !0,
459
+ acceptedTypes: ["number", "matrix"],
460
+ variadic: !0
461
+ }
462
+ ], this.category = "statistics";
463
+ }
464
+ validate(t) {
465
+ const n = [];
466
+ for (const r of t)
467
+ g(
468
+ r,
469
+ (e) => {
470
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
471
+ },
472
+ this.at
473
+ );
474
+ if (n.length === 0)
475
+ throw new d("#N/A", "MODE.SNGL requires at least one numeric value.");
476
+ return [n];
477
+ }
478
+ main(t) {
479
+ const n = /* @__PURE__ */ new Map();
480
+ for (const a of t)
481
+ n.set(a, (n.get(a) ?? 0) + 1);
482
+ const r = Math.max(...n.values());
483
+ if (r < 2)
484
+ throw new d("#N/A", "No value appears more than once.");
485
+ const e = [...n.entries()].filter(([, a]) => a === r).map(([a]) => a);
486
+ return Math.min(...e);
487
+ }
488
+ }
489
+ const ee = "Returns the square of the Pearson product-moment correlation coefficient (R²).";
490
+ class te extends A {
491
+ constructor() {
492
+ super(...arguments), this.example = "RSQ(A1:A10, B1:B10)", this.description = ee, this.defs = [
493
+ {
494
+ name: "data_y",
495
+ description: "The range representing the dependent data.",
496
+ takesMatrix: !0,
497
+ acceptedTypes: ["matrix"]
498
+ },
499
+ {
500
+ name: "data_x",
501
+ description: "The range representing the independent data.",
502
+ takesMatrix: !0,
503
+ acceptedTypes: ["matrix"]
504
+ }
505
+ ], this.category = "statistics";
506
+ }
507
+ validate(t) {
508
+ const n = [], r = [];
509
+ if (g(
510
+ t[0],
511
+ (e) => {
512
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
513
+ },
514
+ this.at
515
+ ), g(
516
+ t[1],
517
+ (e) => {
518
+ e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
519
+ },
520
+ this.at
521
+ ), n.length !== r.length)
522
+ throw new d("#N/A", "RSQ requires two ranges of equal length.");
523
+ if (n.length < 2)
524
+ throw new d("#N/A", "RSQ requires at least 2 data points.");
525
+ return [n, r];
526
+ }
527
+ main(t, n) {
528
+ const r = t.length, e = t.reduce((h, p) => h + p, 0) / r, a = n.reduce((h, p) => h + p, 0) / r;
529
+ let i = 0, u = 0, o = 0;
530
+ for (let h = 0; h < r; h++) {
531
+ const p = t[h] - e, m = n[h] - a;
532
+ i += p * m, u += p * p, o += m * m;
533
+ }
534
+ const s = Math.sqrt(u * o);
535
+ if (s === 0)
536
+ throw new d("#DIV/0!", "Standard deviation of one dataset is zero.");
537
+ const l = i / s;
538
+ return l * l;
539
+ }
540
+ }
541
+ const ne = `Returns the probability associated with a Student's t-test.
542
+ tails: 1 (one-tailed) or 2 (two-tailed).
543
+ type: 1 (paired), 2 (two-sample equal variance), 3 (two-sample unequal variance).`;
544
+ function E(c, t, n) {
545
+ if (c <= 0)
546
+ return 0;
547
+ if (c >= 1)
548
+ return 1;
549
+ if (c > (t + 1) / (t + n + 2))
550
+ return 1 - E(1 - c, n, t);
551
+ const r = b(t) + b(n) - b(t + n), e = Math.exp(Math.log(c) * t + Math.log(1 - c) * n - r) / t, a = 200, i = 3e-7;
552
+ let u = 1, o = 1, s = 1 - (t + n) * c / (t + 1);
553
+ Math.abs(s) < 1e-30 && (s = 1e-30), s = 1 / s, u = s;
554
+ for (let l = 1; l <= a; l++) {
555
+ let h = l * (n - l) * c / ((t + 2 * l - 1) * (t + 2 * l));
556
+ s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s, u *= s * o, h = -(t + l) * (t + n + l) * c / ((t + 2 * l) * (t + 2 * l + 1)), s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s;
557
+ const p = s * o;
558
+ if (u *= p, Math.abs(p - 1) < i)
559
+ break;
560
+ }
561
+ return e * u;
562
+ }
563
+ function b(c) {
564
+ const n = [
565
+ 0.9999999999998099,
566
+ 676.5203681218851,
567
+ -1259.1392167224028,
568
+ 771.3234287776531,
569
+ -176.6150291621406,
570
+ 12.507343278686905,
571
+ -0.13857109526572012,
572
+ 9984369578019572e-21,
573
+ 15056327351493116e-23
574
+ ];
575
+ if (c < 0.5)
576
+ return Math.log(Math.PI / Math.sin(Math.PI * c)) - b(1 - c);
577
+ c--;
578
+ let r = n[0];
579
+ for (let a = 1; a < 9; a++)
580
+ r += n[a] / (c + a);
581
+ const e = c + 7 + 0.5;
582
+ return 0.5 * Math.log(2 * Math.PI) + (c + 0.5) * Math.log(e) - e + Math.log(r);
583
+ }
584
+ function re(c, t) {
585
+ const n = t / (t + c * c);
586
+ return E(n, t / 2, 0.5);
587
+ }
588
+ class ae extends A {
589
+ constructor() {
590
+ super(...arguments), this.example = "T.TEST(A1:A100, B1:B100, 2, 2)", this.description = ne, this.defs = [
591
+ { name: "range1", description: "The first sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
592
+ { name: "range2", description: "The second sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
593
+ { name: "tails", description: "The number of distribution tails: 1 or 2.", acceptedTypes: ["number"] },
594
+ {
595
+ name: "type",
596
+ description: "The type of t-test: 1 (paired), 2 (equal variance), 3 (unequal variance).",
597
+ acceptedTypes: ["number"]
598
+ }
599
+ ], this.category = "statistics";
600
+ }
601
+ validate(t) {
602
+ const n = Math.floor(f(t[2])), r = Math.floor(f(t[3]));
603
+ if (n !== 1 && n !== 2)
604
+ throw new d("#NUM!", "tails must be 1 or 2.");
605
+ if (r < 1 || r > 3)
606
+ throw new d("#NUM!", "type must be 1, 2, or 3.");
607
+ const e = [], a = [];
608
+ if (g(
609
+ t[0],
610
+ (i) => {
611
+ i == null || i === "" || typeof i == "boolean" || e.push(f(i));
612
+ },
613
+ this.at
614
+ ), g(
615
+ t[1],
616
+ (i) => {
617
+ i == null || i === "" || typeof i == "boolean" || a.push(f(i));
618
+ },
619
+ this.at
620
+ ), r === 1) {
621
+ if (e.length !== a.length || e.length < 2)
622
+ throw new d("#N/A", "Paired T.TEST requires equal-length ranges with at least 2 values.");
623
+ } else if (e.length < 2 || a.length < 2)
624
+ throw new d("#DIV/0!", `T.TEST type ${r} requires at least 2 values per range.`);
625
+ return [e, a, n, r];
626
+ }
627
+ main(t, n, r, e) {
628
+ let a, i;
629
+ if (e === 1) {
630
+ const o = t.map((p, m) => p - n[m]), s = o.length, l = o.reduce((p, m) => p + m, 0) / s, h = o.reduce((p, m) => p + (m - l) ** 2, 0) / (s - 1);
631
+ a = l / Math.sqrt(h / s), i = s - 1;
632
+ } else if (e === 2) {
633
+ const o = t.reduce((m, y) => m + y, 0) / t.length, s = n.reduce((m, y) => m + y, 0) / n.length, l = t.reduce((m, y) => m + (y - o) ** 2, 0) / (t.length - 1), h = n.reduce((m, y) => m + (y - s) ** 2, 0) / (n.length - 1), p = ((t.length - 1) * l + (n.length - 1) * h) / (t.length + n.length - 2);
634
+ a = (o - s) / Math.sqrt(p * (1 / t.length + 1 / n.length)), i = t.length + n.length - 2;
635
+ } else {
636
+ const o = t.reduce((y, N) => y + N, 0) / t.length, s = n.reduce((y, N) => y + N, 0) / n.length, l = t.reduce((y, N) => y + (N - o) ** 2, 0) / (t.length - 1), h = n.reduce((y, N) => y + (N - s) ** 2, 0) / (n.length - 1), p = l / t.length, m = h / n.length;
637
+ a = (o - s) / Math.sqrt(p + m), i = (p + m) ** 2 / (p ** 2 / (t.length - 1) + m ** 2 / (n.length - 1));
638
+ }
639
+ const u = re(Math.abs(a), i);
640
+ return r === 1 ? u / 2 : u;
641
+ }
642
+ }
643
+ const ie = {
644
+ averageif: S,
645
+ averageifs: V,
646
+ median: D,
647
+ "stdev.s": C,
648
+ "stdev.p": $,
649
+ "var.s": U,
650
+ "var.p": Q,
651
+ "percentile.inc": G,
652
+ "quartile.inc": X,
653
+ "rank.eq": K,
654
+ correl: j,
655
+ "covariance.s": J,
656
+ "mode.sngl": z,
657
+ rsq: te,
658
+ "t.test": ae
659
+ };
660
+ export {
661
+ ie as default,
662
+ ie as statisticsFunctions
663
+ };
@@ -0,0 +1,10 @@
1
+ import { BaseFunction, FunctionArgumentDefinition, FunctionCategory } from '@gridsheet/react-core';
2
+ export declare class MedianFunction extends BaseFunction {
3
+ example: string;
4
+ description: string;
5
+ defs: FunctionArgumentDefinition[];
6
+ category: FunctionCategory;
7
+ protected validate(args: any[]): any[];
8
+ protected main(nums: number[]): number;
9
+ }
10
+ //# sourceMappingURL=median.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"median.d.ts","sourceRoot":"","sources":["../../src/statistics/median.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,0BAA0B,EAAc,MAAM,uBAAuB,CAAC;AAElG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,SAAqB;IAC5B,WAAW,SAAe;IAC1B,IAAI,EAAE,0BAA0B,EAAE,CAQhC;IACF,QAAQ,EAAE,gBAAgB,CAAgB;IAE1C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE;IAsBtC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE;CAK9B"}
@@ -0,0 +1,10 @@
1
+ import { BaseFunction, FunctionArgumentDefinition, FunctionCategory } from '@gridsheet/react-core';
2
+ export declare class ModeSnglFunction extends BaseFunction {
3
+ example: string;
4
+ description: string;
5
+ defs: FunctionArgumentDefinition[];
6
+ category: FunctionCategory;
7
+ protected validate(args: any[]): any[];
8
+ protected main(nums: number[]): number;
9
+ }
10
+ //# sourceMappingURL=mode_sngl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mode_sngl.d.ts","sourceRoot":"","sources":["../../src/statistics/mode_sngl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,0BAA0B,EAAc,MAAM,uBAAuB,CAAC;AAElG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,SAAwB;IAC/B,WAAW,SAAe;IAC1B,IAAI,EAAE,0BAA0B,EAAE,CAQhC;IACF,QAAQ,EAAE,gBAAgB,CAAgB;IAE1C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE;IAsBtC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE;CAY9B"}