@nubisco/ui 5.59.1 → 5.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Blueprint-CQxC02e5.cjs → Blueprint-B1vqK1QL.cjs} +1 -1
- package/dist/{Blueprint-Dnliv-77.js → Blueprint-CRTuGw8u.js} +1 -1
- package/dist/Spreadsheet-Bg1gxM7t.cjs +4 -0
- package/dist/Spreadsheet-Cdl14I3Q.js +2326 -0
- package/dist/all.cjs +1 -1
- package/dist/all.mjs +15 -14
- package/dist/components/Blueprint.cjs +1 -1
- package/dist/components/Blueprint.mjs +1 -1
- package/dist/components/Spreadsheet.cjs +1 -1
- package/dist/components/Spreadsheet.d.ts +105 -2
- package/dist/components/Spreadsheet.mjs +1 -1
- package/dist/components/Spreadsheet.vue.d.ts +23 -2
- package/dist/components/Spreadsheet.vue.d.ts.map +1 -1
- package/dist/components/spreadsheet/sheetLook.d.ts +39 -0
- package/dist/components/spreadsheet/sheetLook.d.ts.map +1 -0
- package/dist/composables/useNbStrings.composable.cjs +1 -1
- package/dist/composables/useNbStrings.composable.d.ts +6 -0
- package/dist/composables/useNbStrings.composable.d.ts.map +1 -1
- package/dist/composables/useNbStrings.composable.mjs +4 -0
- package/dist/formula/criteria.d.ts +15 -0
- package/dist/formula/criteria.d.ts.map +1 -0
- package/dist/formula/dates.d.ts +31 -0
- package/dist/formula/dates.d.ts.map +1 -0
- package/dist/formula/evaluator.d.ts +11 -0
- package/dist/formula/evaluator.d.ts.map +1 -0
- package/dist/formula/format.d.ts +7 -0
- package/dist/formula/format.d.ts.map +1 -0
- package/dist/formula/functions/date.d.ts +3 -0
- package/dist/formula/functions/date.d.ts.map +1 -0
- package/dist/formula/functions/define.d.ts +16 -0
- package/dist/formula/functions/define.d.ts.map +1 -0
- package/dist/formula/functions/index.d.ts +9 -0
- package/dist/formula/functions/index.d.ts.map +1 -0
- package/dist/formula/functions/information.d.ts +3 -0
- package/dist/formula/functions/information.d.ts.map +1 -0
- package/dist/formula/functions/logical.d.ts +3 -0
- package/dist/formula/functions/logical.d.ts.map +1 -0
- package/dist/formula/functions/lookup.d.ts +3 -0
- package/dist/formula/functions/lookup.d.ts.map +1 -0
- package/dist/formula/functions/math.d.ts +13 -0
- package/dist/formula/functions/math.d.ts.map +1 -0
- package/dist/formula/functions/statistical.d.ts +3 -0
- package/dist/formula/functions/statistical.d.ts.map +1 -0
- package/dist/formula/functions/text.d.ts +3 -0
- package/dist/formula/functions/text.d.ts.map +1 -0
- package/dist/formula/index.cjs +1 -0
- package/dist/formula/index.d.ts +15 -0
- package/dist/formula/index.d.ts.map +1 -0
- package/dist/formula/index.mjs +2 -0
- package/dist/formula/parser.d.ts +10 -0
- package/dist/formula/parser.d.ts.map +1 -0
- package/dist/formula/references.d.ts +14 -0
- package/dist/formula/references.d.ts.map +1 -0
- package/dist/formula/refs.d.ts +20 -0
- package/dist/formula/refs.d.ts.map +1 -0
- package/dist/formula/sheet.d.ts +10 -0
- package/dist/formula/sheet.d.ts.map +1 -0
- package/dist/formula/syntax.d.ts +14 -0
- package/dist/formula/syntax.d.ts.map +1 -0
- package/dist/formula/tokenizer.d.ts +13 -0
- package/dist/formula/tokenizer.d.ts.map +1 -0
- package/dist/formula/types.d.ts +155 -0
- package/dist/formula/types.d.ts.map +1 -0
- package/dist/formula/values.d.ts +46 -0
- package/dist/formula/values.d.ts.map +1 -0
- package/dist/formula-Co-gRJ5f.cjs +1 -0
- package/dist/formula-QEIwkjmo.js +2577 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +9 -8
- package/dist/{main-zCF9LQQU.js → main-DJ43_gPi.js} +1 -1
- package/dist/{main-I6bzKhGk.cjs → main-NxnoNUx0.cjs} +1 -1
- package/dist/main.d.ts +2 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/styles/Spreadsheet.css +1 -1
- package/dist/ui.css +1 -1
- package/dist/utils/csv.helper.cjs +5 -0
- package/dist/utils/csv.helper.d.ts +22 -0
- package/dist/utils/csv.helper.d.ts.map +1 -0
- package/dist/utils/csv.helper.mjs +46 -0
- package/package.json +7 -1
- package/src/utils/csv.helper.ts +96 -0
- package/dist/Spreadsheet-BwGhq9vm.cjs +0 -4
- package/dist/Spreadsheet-C9MeO5MD.js +0 -1455
- /package/dist/{pixi-scene-D1jzgzHL.js → pixi-scene-CShpsLDx.js} +0 -0
- /package/dist/{pixi-scene-BGTSD1-G.cjs → pixi-scene-OJo1IXN4.cjs} +0 -0
|
@@ -0,0 +1,2577 @@
|
|
|
1
|
+
//#region src/formula/refs.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = "", n = Math.floor(e) + 1;
|
|
4
|
+
for (; n > 0;) {
|
|
5
|
+
let e = (n - 1) % 26;
|
|
6
|
+
t = String.fromCharCode(65 + e) + t, n = Math.floor((n - 1) / 26);
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
function t(e) {
|
|
11
|
+
if (!/^[A-Za-z]+$/.test(e)) return -1;
|
|
12
|
+
let t = 0;
|
|
13
|
+
for (let n of e.toUpperCase()) t = t * 26 + (n.charCodeAt(0) - 64);
|
|
14
|
+
return t - 1;
|
|
15
|
+
}
|
|
16
|
+
var n = /^\$?([A-Za-z]{1,3})\$?([1-9][0-9]*)$/;
|
|
17
|
+
function r(e) {
|
|
18
|
+
let r = n.exec(e);
|
|
19
|
+
return r ? {
|
|
20
|
+
row: Number(r[2]) - 1,
|
|
21
|
+
col: t(r[1])
|
|
22
|
+
} : null;
|
|
23
|
+
}
|
|
24
|
+
function i(t, n) {
|
|
25
|
+
return e(n) + String(t + 1);
|
|
26
|
+
}
|
|
27
|
+
function a(e) {
|
|
28
|
+
let n = e.split(":");
|
|
29
|
+
if (n.length !== 2) return null;
|
|
30
|
+
let [i, a] = n, s = r(i), c = r(a);
|
|
31
|
+
if (s && c) return o(s.row, s.col, c.row, c.col);
|
|
32
|
+
let l = /^\$?([A-Za-z]{1,3})$/.exec(i), u = /^\$?([A-Za-z]{1,3})$/.exec(a);
|
|
33
|
+
if (l && u) {
|
|
34
|
+
let e = t(l[1]), n = t(u[1]);
|
|
35
|
+
return {
|
|
36
|
+
r1: 0,
|
|
37
|
+
r2: Infinity,
|
|
38
|
+
c1: Math.min(e, n),
|
|
39
|
+
c2: Math.max(e, n)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
let d = /^\$?([1-9][0-9]*)$/.exec(i), f = /^\$?([1-9][0-9]*)$/.exec(a);
|
|
43
|
+
if (d && f) {
|
|
44
|
+
let e = Number(d[1]) - 1, t = Number(f[1]) - 1;
|
|
45
|
+
return {
|
|
46
|
+
r1: Math.min(e, t),
|
|
47
|
+
r2: Math.max(e, t),
|
|
48
|
+
c1: 0,
|
|
49
|
+
c2: Infinity
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function o(e, t, n, r) {
|
|
55
|
+
return {
|
|
56
|
+
r1: Math.min(e, n),
|
|
57
|
+
r2: Math.max(e, n),
|
|
58
|
+
c1: Math.min(t, r),
|
|
59
|
+
c2: Math.max(t, r)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/formula/dates.ts
|
|
64
|
+
var s = 864e5, c = Date.UTC(1899, 11, 30);
|
|
65
|
+
function l(e, t, n) {
|
|
66
|
+
let r = new Date(c);
|
|
67
|
+
return r.setUTCFullYear(e, t - 1, n), r.getTime();
|
|
68
|
+
}
|
|
69
|
+
function u(e, t, n, r = 0, i = 0, a = 0) {
|
|
70
|
+
return Math.round((l(Math.trunc(e), Math.trunc(t), Math.trunc(n)) - c) / s) + (r * 3600 + i * 60 + a) / 86400;
|
|
71
|
+
}
|
|
72
|
+
function d(e) {
|
|
73
|
+
let t = Math.round(e * 86400), n = Math.floor(t / 86400), r = t - n * 86400, i = new Date(c + n * s);
|
|
74
|
+
return {
|
|
75
|
+
year: i.getUTCFullYear(),
|
|
76
|
+
month: i.getUTCMonth() + 1,
|
|
77
|
+
day: i.getUTCDate(),
|
|
78
|
+
hours: Math.floor(r / 3600),
|
|
79
|
+
minutes: Math.floor(r % 3600 / 60),
|
|
80
|
+
seconds: r % 60,
|
|
81
|
+
weekday: i.getUTCDay()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function f(e, t) {
|
|
85
|
+
return d(u(e, t + 1, 0)).day;
|
|
86
|
+
}
|
|
87
|
+
var p = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?)?$/, m = /^(\d{1,2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?$/;
|
|
88
|
+
function h(e, t, n) {
|
|
89
|
+
let r = Number(e), i = Number(t), a = n === void 0 ? 0 : Number(n);
|
|
90
|
+
return r > 23 || i > 59 || a >= 60 ? null : (r * 3600 + i * 60 + a) / 86400;
|
|
91
|
+
}
|
|
92
|
+
function g(e) {
|
|
93
|
+
let t = e.trim(), n = m.exec(t);
|
|
94
|
+
if (n) return h(n[1], n[2], n[3]);
|
|
95
|
+
let r = p.exec(t);
|
|
96
|
+
if (!r) return null;
|
|
97
|
+
let i = Number(r[1]), a = Number(r[2]), o = Number(r[3]);
|
|
98
|
+
if (a < 1 || a > 12 || o < 1 || o > f(i, a)) return null;
|
|
99
|
+
let s = u(i, a, o);
|
|
100
|
+
if (r[4] === void 0) return s;
|
|
101
|
+
let c = h(r[4], r[5], r[6]);
|
|
102
|
+
return c === null ? null : s + c;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/formula/tokenizer.ts
|
|
106
|
+
var _ = Object.freeze({
|
|
107
|
+
decimal: ".",
|
|
108
|
+
separator: ","
|
|
109
|
+
}), v = [
|
|
110
|
+
"#DIV/0!",
|
|
111
|
+
"#VALUE!",
|
|
112
|
+
"#REF!",
|
|
113
|
+
"#NAME?",
|
|
114
|
+
"#N/A",
|
|
115
|
+
"#NUM!",
|
|
116
|
+
"#NULL!",
|
|
117
|
+
"#ERROR!"
|
|
118
|
+
], y = "(?![A-Za-z0-9_.$(])", ee = RegExp(`^\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*:\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*${y}`), te = RegExp(`^\\$?[A-Za-z]{1,3}:\\$?[A-Za-z]{1,3}${y}`), ne = RegExp(`^\\$?[1-9][0-9]*:\\$?[1-9][0-9]*${y}`), re = RegExp(`^\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*${y}`), ie = /^[A-Za-z_][A-Za-z0-9_.]*/, ae = /^\s+/, oe = [
|
|
119
|
+
"<>",
|
|
120
|
+
"<=",
|
|
121
|
+
">=",
|
|
122
|
+
"+",
|
|
123
|
+
"-",
|
|
124
|
+
"*",
|
|
125
|
+
"/",
|
|
126
|
+
"^",
|
|
127
|
+
"&",
|
|
128
|
+
"%",
|
|
129
|
+
"=",
|
|
130
|
+
"<",
|
|
131
|
+
">",
|
|
132
|
+
":"
|
|
133
|
+
];
|
|
134
|
+
function se(e) {
|
|
135
|
+
let t = e === "." ? "\\." : ",";
|
|
136
|
+
return RegExp(`^(?:[0-9]+(?:${t}[0-9]*)?|${t}[0-9]+)(?:[eE][+-]?[0-9]+)?`);
|
|
137
|
+
}
|
|
138
|
+
var ce = {
|
|
139
|
+
".": se("."),
|
|
140
|
+
",": se(",")
|
|
141
|
+
};
|
|
142
|
+
function le(e) {
|
|
143
|
+
return e.separator === ";" ? "\\" : ",";
|
|
144
|
+
}
|
|
145
|
+
function b(e, t = _) {
|
|
146
|
+
let n = [], r = ce[t.decimal] ?? ce["."], i = le(t), a = 0, o = 0, s = (t, r) => {
|
|
147
|
+
n.push({
|
|
148
|
+
type: t,
|
|
149
|
+
text: e.slice(o, o + r),
|
|
150
|
+
start: o,
|
|
151
|
+
end: o + r
|
|
152
|
+
}), o += r;
|
|
153
|
+
};
|
|
154
|
+
for (; o < e.length;) {
|
|
155
|
+
let n = e.slice(o), c = n[0], l;
|
|
156
|
+
if (l = ae.exec(n)) s("whitespace", l[0].length);
|
|
157
|
+
else if (c === "\"") {
|
|
158
|
+
let e = 1, t = !1;
|
|
159
|
+
for (; e < n.length;) if (n[e] === "\"") if (n[e + 1] === "\"") e += 2;
|
|
160
|
+
else {
|
|
161
|
+
t = !0, e++;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
else e++;
|
|
165
|
+
s(t ? "string" : "invalid", e);
|
|
166
|
+
} else if (c === "#") {
|
|
167
|
+
let e = n.toUpperCase(), t = v.find((t) => e.startsWith(t));
|
|
168
|
+
s(t ? "error" : "invalid", t ? t.length : 1);
|
|
169
|
+
} else if (l = ne.exec(n)) s("range", l[0].length);
|
|
170
|
+
else if (l = r.exec(n)) s("number", l[0].length);
|
|
171
|
+
else if ((l = ee.exec(n)) || (l = te.exec(n))) s("range", l[0].length);
|
|
172
|
+
else if (l = re.exec(n)) s("reference", l[0].length);
|
|
173
|
+
else if (l = ie.exec(n)) {
|
|
174
|
+
let t = l[0], n = e[o + t.length], r = t.toUpperCase();
|
|
175
|
+
s(n === "(" ? "function" : r === "TRUE" || r === "FALSE" ? "boolean" : "name", t.length);
|
|
176
|
+
} else if (c === "(" || c === ")") s("paren", 1);
|
|
177
|
+
else if (c === "{" || c === "}") a = c === "{" ? a + 1 : Math.max(0, a - 1), s("brace", 1);
|
|
178
|
+
else if (a > 0 && c === i) s("separator", 1);
|
|
179
|
+
else if (a > 0 && c === ";") s("rowSeparator", 1);
|
|
180
|
+
else if (c === t.separator) s("separator", 1);
|
|
181
|
+
else {
|
|
182
|
+
let e = oe.find((e) => n.startsWith(e));
|
|
183
|
+
s(e ? "operator" : "invalid", e ? e.length : 1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return n;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/formula/values.ts
|
|
190
|
+
var ue = {
|
|
191
|
+
"#DIV/0!": "Division by zero",
|
|
192
|
+
"#VALUE!": "Wrong type of value",
|
|
193
|
+
"#REF!": "Invalid reference",
|
|
194
|
+
"#NAME?": "Unknown name",
|
|
195
|
+
"#N/A": "Value not available",
|
|
196
|
+
"#NUM!": "Invalid number",
|
|
197
|
+
"#NULL!": "Empty intersection",
|
|
198
|
+
"#ERROR!": "Formula could not be read"
|
|
199
|
+
};
|
|
200
|
+
function x(e, t) {
|
|
201
|
+
return {
|
|
202
|
+
error: e,
|
|
203
|
+
message: t ?? ue[e]
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function de(e) {
|
|
207
|
+
return typeof e == "string" && e.length > 1 && e[0] === "=";
|
|
208
|
+
}
|
|
209
|
+
function S(e) {
|
|
210
|
+
return typeof e == "object" && !!e && "error" in e && v.includes(e.error);
|
|
211
|
+
}
|
|
212
|
+
function C(e) {
|
|
213
|
+
return typeof e == "object" && !!e && e.kind === "matrix";
|
|
214
|
+
}
|
|
215
|
+
function w(e, t, n) {
|
|
216
|
+
return {
|
|
217
|
+
kind: "matrix",
|
|
218
|
+
rows: e,
|
|
219
|
+
cols: t,
|
|
220
|
+
get: (e, r) => n[e * t + r] ?? null
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function fe(e, t) {
|
|
224
|
+
let n = t.r2 === Infinity ? e.extent.rows - 1 : t.r2, r = t.c2 === Infinity ? e.extent.cols - 1 : t.c2, { r1: i, c1: a } = t;
|
|
225
|
+
return {
|
|
226
|
+
kind: "matrix",
|
|
227
|
+
rows: Math.max(0, n - i + 1),
|
|
228
|
+
cols: Math.max(0, r - a + 1),
|
|
229
|
+
get: (t, n) => e.cell(i + t, a + n),
|
|
230
|
+
origin: {
|
|
231
|
+
row: i,
|
|
232
|
+
col: a
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function T(e) {
|
|
237
|
+
return C(e) ? e : w(1, 1, [e]);
|
|
238
|
+
}
|
|
239
|
+
function E(e, t) {
|
|
240
|
+
for (let n = 0; n < e.rows; n++) for (let r = 0; r < e.cols; r++) if (t(e.get(n, r), n, r) === !0) return;
|
|
241
|
+
}
|
|
242
|
+
function D(e) {
|
|
243
|
+
return C(e) ? e.rows === 1 && e.cols === 1 ? e.get(0, 0) : x("#VALUE!", "A range cannot be used as a single value") : e;
|
|
244
|
+
}
|
|
245
|
+
var pe = /^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?%?$/;
|
|
246
|
+
function O(e) {
|
|
247
|
+
let t = e.trim();
|
|
248
|
+
return pe.test(t) ? t.endsWith("%") ? Number(t.slice(0, -1)) / 100 : Number(t) : null;
|
|
249
|
+
}
|
|
250
|
+
function k(e) {
|
|
251
|
+
if (e === null) return 0;
|
|
252
|
+
if (typeof e == "number") return e;
|
|
253
|
+
if (typeof e == "boolean") return e ? 1 : 0;
|
|
254
|
+
if (typeof e == "string") {
|
|
255
|
+
let t = O(e) ?? g(e);
|
|
256
|
+
return t === null ? x("#VALUE!", "Text cannot be used as a number") : t;
|
|
257
|
+
}
|
|
258
|
+
return e;
|
|
259
|
+
}
|
|
260
|
+
function me(e) {
|
|
261
|
+
return Number.isInteger(e) && Math.abs(e) < 1e21 ? String(e) : String(Number(e.toPrecision(15))).toUpperCase();
|
|
262
|
+
}
|
|
263
|
+
function A(e) {
|
|
264
|
+
return e === null ? "" : typeof e == "string" ? e : typeof e == "number" ? me(e) : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e;
|
|
265
|
+
}
|
|
266
|
+
function j(e) {
|
|
267
|
+
if (e === null) return !1;
|
|
268
|
+
if (typeof e == "boolean") return e;
|
|
269
|
+
if (typeof e == "number") return e !== 0;
|
|
270
|
+
if (typeof e == "string") {
|
|
271
|
+
let t = e.toUpperCase();
|
|
272
|
+
return t === "TRUE" ? !0 : t === "FALSE" ? !1 : x("#VALUE!", "Text cannot be used as TRUE or FALSE");
|
|
273
|
+
}
|
|
274
|
+
return e;
|
|
275
|
+
}
|
|
276
|
+
var M = (e) => k(D(e)), N = (e) => A(D(e)), P = (e) => j(D(e));
|
|
277
|
+
function F(e, t, n) {
|
|
278
|
+
let r = e[t];
|
|
279
|
+
return r == null ? n : M(r);
|
|
280
|
+
}
|
|
281
|
+
function he(e) {
|
|
282
|
+
return typeof e == "number" ? 0 : typeof e == "string" ? 1 : 2;
|
|
283
|
+
}
|
|
284
|
+
function I(e, t) {
|
|
285
|
+
if (e === null && t === null) return 0;
|
|
286
|
+
let n = (e) => typeof e == "number" ? 0 : typeof e == "string" ? "" : !1, r = e === null ? n(t) : e, i = t === null ? n(r) : t, a = he(r) - he(i);
|
|
287
|
+
if (a !== 0) return Math.sign(a);
|
|
288
|
+
if (typeof r == "string") {
|
|
289
|
+
let e = r.toLowerCase(), t = i.toLowerCase();
|
|
290
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
291
|
+
}
|
|
292
|
+
return Math.sign(Number(r) - Number(i));
|
|
293
|
+
}
|
|
294
|
+
function L(e) {
|
|
295
|
+
let t = [];
|
|
296
|
+
for (let n of e) if (C(n)) {
|
|
297
|
+
let e = null;
|
|
298
|
+
if (E(n, (n) => {
|
|
299
|
+
if (typeof n == "number") t.push(n);
|
|
300
|
+
else if (S(n)) return e = n, !0;
|
|
301
|
+
}), e) return e;
|
|
302
|
+
} else if (n !== null) {
|
|
303
|
+
let e = k(n);
|
|
304
|
+
if (S(e)) return e;
|
|
305
|
+
t.push(e);
|
|
306
|
+
}
|
|
307
|
+
return t;
|
|
308
|
+
}
|
|
309
|
+
function R(e) {
|
|
310
|
+
return typeof e == "number" && !Number.isFinite(e) ? x("#NUM!", "The result is not a finite number") : e;
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/formula/syntax.ts
|
|
314
|
+
function ge(e) {
|
|
315
|
+
try {
|
|
316
|
+
if (new Intl.NumberFormat(e).formatToParts(1.5).find((e) => e.type === "decimal")?.value === ",") return {
|
|
317
|
+
decimal: ",",
|
|
318
|
+
separator: ";"
|
|
319
|
+
};
|
|
320
|
+
} catch {}
|
|
321
|
+
return { ..._ };
|
|
322
|
+
}
|
|
323
|
+
function _e(e, t, n) {
|
|
324
|
+
if (t.decimal === n.decimal && t.separator === n.separator) return e;
|
|
325
|
+
let r = 0;
|
|
326
|
+
return b(e, t).map((e) => (e.type === "brace" && (r = e.text === "{" ? r + 1 : Math.max(0, r - 1)), e.type === "number" ? e.text.replace(t.decimal, n.decimal) : e.type === "separator" ? r > 0 ? le(n) : n.separator : e.text)).join("");
|
|
327
|
+
}
|
|
328
|
+
function ve(e, t) {
|
|
329
|
+
return _e(e, t, _);
|
|
330
|
+
}
|
|
331
|
+
function ye(e, t) {
|
|
332
|
+
return _e(e, _, t);
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/formula/references.ts
|
|
336
|
+
function be(e, t = _) {
|
|
337
|
+
let n = [];
|
|
338
|
+
for (let i of b(e, t)) if (i.type === "reference") {
|
|
339
|
+
let e = r(i.text);
|
|
340
|
+
if (!e) continue;
|
|
341
|
+
n.push({
|
|
342
|
+
start: i.start,
|
|
343
|
+
end: i.end,
|
|
344
|
+
text: i.text,
|
|
345
|
+
range: {
|
|
346
|
+
r1: e.row,
|
|
347
|
+
c1: e.col,
|
|
348
|
+
r2: e.row,
|
|
349
|
+
c2: e.col
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
} else if (i.type === "range") {
|
|
353
|
+
let e = a(i.text);
|
|
354
|
+
e && n.push({
|
|
355
|
+
start: i.start,
|
|
356
|
+
end: i.end,
|
|
357
|
+
text: i.text,
|
|
358
|
+
range: e
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return n;
|
|
362
|
+
}
|
|
363
|
+
var xe = /^(\$?)([A-Za-z]{1,3})?(\$?)([1-9][0-9]*)?$/;
|
|
364
|
+
function Se(e) {
|
|
365
|
+
let n = xe.exec(e);
|
|
366
|
+
if (!n || !n[2] && !n[4]) return null;
|
|
367
|
+
let r = {};
|
|
368
|
+
if (n[2] && (r.col = {
|
|
369
|
+
index: t(n[2]),
|
|
370
|
+
absolute: n[1] === "$"
|
|
371
|
+
}), n[4]) {
|
|
372
|
+
let e = n[2] ? n[3] === "$" : n[1] === "$" || n[3] === "$";
|
|
373
|
+
r.row = {
|
|
374
|
+
index: Number(n[4]) - 1,
|
|
375
|
+
absolute: e
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return r;
|
|
379
|
+
}
|
|
380
|
+
function Ce(t) {
|
|
381
|
+
let n = "";
|
|
382
|
+
return t.col && (n += (t.col.absolute ? "$" : "") + e(t.col.index)), t.row && (n += (t.row.absolute ? "$" : "") + String(t.row.index + 1)), n;
|
|
383
|
+
}
|
|
384
|
+
function we(e, t, n) {
|
|
385
|
+
return e.col && !e.col.absolute && (e.col.index += n), e.row && !e.row.absolute && (e.row.index += t), (!e.col || e.col.index >= 0) && (!e.row || e.row.index >= 0);
|
|
386
|
+
}
|
|
387
|
+
function Te(e, t, n) {
|
|
388
|
+
let r = e.split(":").map(Se);
|
|
389
|
+
if (r.some((e) => e === null)) return e;
|
|
390
|
+
let i = r;
|
|
391
|
+
for (let e of i) if (!we(e, t, n)) return "#REF!";
|
|
392
|
+
if (i.length === 2) {
|
|
393
|
+
let [e, t] = i;
|
|
394
|
+
e.row && t.row && e.row.index > t.row.index && ([e.row, t.row] = [t.row, e.row]), e.col && t.col && e.col.index > t.col.index && ([e.col, t.col] = [t.col, e.col]);
|
|
395
|
+
}
|
|
396
|
+
return i.map(Ce).join(":");
|
|
397
|
+
}
|
|
398
|
+
function Ee(e, t, n) {
|
|
399
|
+
return t === 0 && n === 0 ? e : b(e).map((e) => e.type === "reference" || e.type === "range" ? Te(e.text, t, n) : e.text).join("");
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/formula/functions/define.ts
|
|
403
|
+
function z(e) {
|
|
404
|
+
return (t) => {
|
|
405
|
+
let n = [];
|
|
406
|
+
for (let e of t) {
|
|
407
|
+
let t = M(e);
|
|
408
|
+
if (S(t)) return t;
|
|
409
|
+
n.push(t);
|
|
410
|
+
}
|
|
411
|
+
return e(...n);
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function B(...e) {
|
|
415
|
+
for (let t of e) if (S(t)) return t;
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/formula/functions/date.ts
|
|
420
|
+
function V(e) {
|
|
421
|
+
if (e === void 0) return x("#VALUE!", "A date is missing");
|
|
422
|
+
let t = M(e);
|
|
423
|
+
return S(t) ? t : t < 0 ? x("#NUM!", "Dates before 1899-12-30 are not supported") : t;
|
|
424
|
+
}
|
|
425
|
+
var H = (e) => (t) => {
|
|
426
|
+
let n = V(t[0]);
|
|
427
|
+
return S(n) ? n : e(n);
|
|
428
|
+
};
|
|
429
|
+
function De(e) {
|
|
430
|
+
let t = /* @__PURE__ */ new Set();
|
|
431
|
+
if (e == null) return t;
|
|
432
|
+
let n = C(e) ? [] : [e];
|
|
433
|
+
C(e) && E(e, (e) => void n.push(e));
|
|
434
|
+
for (let e of n) {
|
|
435
|
+
if (e === null) continue;
|
|
436
|
+
let n = k(e);
|
|
437
|
+
if (S(n)) return n;
|
|
438
|
+
t.add(Math.floor(n));
|
|
439
|
+
}
|
|
440
|
+
return t;
|
|
441
|
+
}
|
|
442
|
+
var Oe = (e) => {
|
|
443
|
+
let t = (e % 7 + 7) % 7;
|
|
444
|
+
return t === 0 || t === 1;
|
|
445
|
+
};
|
|
446
|
+
function ke(e, t) {
|
|
447
|
+
let { year: n, month: r, day: i } = d(Math.floor(e)), a = n * 12 + (r - 1) + Math.trunc(t), o = Math.floor(a / 12), s = a - o * 12 + 1;
|
|
448
|
+
return u(o, s, Math.min(i, f(o, s)));
|
|
449
|
+
}
|
|
450
|
+
function Ae(e, t) {
|
|
451
|
+
let n = d(Math.floor(e)).weekday;
|
|
452
|
+
return t === 1 ? n + 1 : t === 2 ? (n + 6) % 7 + 1 : t === 3 ? (n + 6) % 7 : t >= 11 && t <= 17 ? (n - (t - 10) % 7 + 7) % 7 + 1 : x("#NUM!", "The return type is not supported");
|
|
453
|
+
}
|
|
454
|
+
function je(e) {
|
|
455
|
+
let t = Math.floor(e), n = t - (d(t).weekday + 6) % 7 + 3, r = u(d(n).year, 1, 1);
|
|
456
|
+
return Math.floor((n - r) / 7) + 1;
|
|
457
|
+
}
|
|
458
|
+
function Me(e, t) {
|
|
459
|
+
if (t === 21) return je(e);
|
|
460
|
+
let n = t === 1 || t === 17 ? 0 : t === 2 || t === 11 ? 1 : t >= 12 && t <= 16 ? t - 10 : -1;
|
|
461
|
+
if (n < 0) return x("#NUM!", "The return type is not supported");
|
|
462
|
+
let r = Math.floor(e), i = u(d(r).year, 1, 1), a = (d(i).weekday - n + 7) % 7;
|
|
463
|
+
return Math.floor((r - i + a) / 7) + 1;
|
|
464
|
+
}
|
|
465
|
+
function Ne(e, t, n) {
|
|
466
|
+
let r = d(Math.floor(e)), i = d(Math.floor(t)), a = (i.year - r.year) * 12 + (i.month - r.month) - (i.day < r.day ? 1 : 0);
|
|
467
|
+
switch (n.toUpperCase()) {
|
|
468
|
+
case "Y": return Math.floor(a / 12);
|
|
469
|
+
case "M": return a;
|
|
470
|
+
case "D": return Math.floor(t) - Math.floor(e);
|
|
471
|
+
case "YM": return a % 12;
|
|
472
|
+
case "MD": return i.day >= r.day ? i.day - r.day : f(i.year, i.month - 1) - r.day + i.day;
|
|
473
|
+
case "YD": {
|
|
474
|
+
let e = u(i.year, r.month, r.day);
|
|
475
|
+
return e > Math.floor(t) && (e = u(i.year - 1, r.month, r.day)), Math.floor(t) - e;
|
|
476
|
+
}
|
|
477
|
+
default: return x("#NUM!", "The unit must be Y, M, D, MD, YM or YD");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
var Pe = (e) => e % 4 == 0 && e % 100 != 0 || e % 400 == 0;
|
|
481
|
+
function Fe(e, t, n) {
|
|
482
|
+
let r = Math.floor(e), i = Math.floor(t);
|
|
483
|
+
r > i && ([r, i] = [i, r]);
|
|
484
|
+
let a = d(r), o = d(i), s = i - r;
|
|
485
|
+
switch (n) {
|
|
486
|
+
case 0: {
|
|
487
|
+
let e = a.day, t = o.day, n = (e) => e.month === 2 && e.day === f(e.year, 2);
|
|
488
|
+
return e === 31 && t === 31 ? (e = 30, t = 30) : e === 31 ? e = 30 : e === 30 && t === 31 ? t = 30 : n(a) && n(o) ? (e = 30, t = 30) : n(a) && (e = 30), ((o.year - a.year) * 360 + (o.month - a.month) * 30 + (t - e)) / 360;
|
|
489
|
+
}
|
|
490
|
+
case 1: {
|
|
491
|
+
if (a.year === o.year || o.year === a.year + 1 && (a.month > o.month || a.month === o.month && a.day >= o.day)) {
|
|
492
|
+
let e = 365;
|
|
493
|
+
if (a.year === o.year) e = Pe(a.year) ? 366 : 365;
|
|
494
|
+
else for (let t of [a.year, o.year]) {
|
|
495
|
+
if (!Pe(t)) continue;
|
|
496
|
+
let n = u(t, 2, 29);
|
|
497
|
+
n >= r && n <= i && (e = 366);
|
|
498
|
+
}
|
|
499
|
+
return s / e;
|
|
500
|
+
}
|
|
501
|
+
let e = o.year - a.year + 1;
|
|
502
|
+
return s / ((u(o.year + 1, 1, 1) - u(a.year, 1, 1)) / e);
|
|
503
|
+
}
|
|
504
|
+
case 2: return s / 360;
|
|
505
|
+
case 3: return s / 365;
|
|
506
|
+
case 4: {
|
|
507
|
+
let e = Math.min(a.day, 30), t = Math.min(o.day, 30);
|
|
508
|
+
return ((o.year - a.year) * 360 + (o.month - a.month) * 30 + (t - e)) / 360;
|
|
509
|
+
}
|
|
510
|
+
default: return x("#NUM!", "The basis must be 0 to 4");
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function Ie(e) {
|
|
514
|
+
let t = /* @__PURE__ */ new Date(), n = u(t.getFullYear(), t.getMonth() + 1, t.getDate());
|
|
515
|
+
return e ? n + (t.getHours() * 3600 + t.getMinutes() * 60 + t.getSeconds() + t.getMilliseconds() / 1e3) / 86400 : n;
|
|
516
|
+
}
|
|
517
|
+
function Le(e) {
|
|
518
|
+
let t = D(e);
|
|
519
|
+
if (S(t)) return t;
|
|
520
|
+
if (typeof t != "string") return x("#VALUE!", "Expected a date as text");
|
|
521
|
+
let n = g(t);
|
|
522
|
+
return n === null ? x("#VALUE!", "The text is not a date") : n;
|
|
523
|
+
}
|
|
524
|
+
var Re = [
|
|
525
|
+
{
|
|
526
|
+
name: "DATE",
|
|
527
|
+
category: "date",
|
|
528
|
+
syntax: "DATE(year, month, day)",
|
|
529
|
+
description: "Returns the serial number of a date, rolling over months and days out of range.",
|
|
530
|
+
minArgs: 3,
|
|
531
|
+
maxArgs: 3,
|
|
532
|
+
call: (e) => {
|
|
533
|
+
let t = M(e[0]), n = M(e[1]), r = M(e[2]), i = B(t, n, r);
|
|
534
|
+
if (i) return i;
|
|
535
|
+
let a = Math.trunc(t);
|
|
536
|
+
if (a >= 0 && a < 1900 && (a += 1900), a < 0 || a > 9999) return x("#NUM!", "The year must be 0 to 9999");
|
|
537
|
+
let o = u(a, n, r);
|
|
538
|
+
return o < 0 ? x("#NUM!", "Dates before 1899-12-30 are not supported") : o;
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: "TIME",
|
|
543
|
+
category: "date",
|
|
544
|
+
syntax: "TIME(hours, minutes, seconds)",
|
|
545
|
+
description: "Returns a time of day as a fraction of a day.",
|
|
546
|
+
minArgs: 3,
|
|
547
|
+
maxArgs: 3,
|
|
548
|
+
call: (e) => {
|
|
549
|
+
let t = e.map(M), n = B(...t);
|
|
550
|
+
if (n) return n;
|
|
551
|
+
let [r, i, a] = t.map(Math.trunc), o = r * 3600 + i * 60 + a;
|
|
552
|
+
return o < 0 ? x("#NUM!", "A time cannot be negative") : o % 86400 / 86400;
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: "TODAY",
|
|
557
|
+
category: "date",
|
|
558
|
+
syntax: "TODAY()",
|
|
559
|
+
description: "Returns today's date, recalculated on every change.",
|
|
560
|
+
minArgs: 0,
|
|
561
|
+
maxArgs: 0,
|
|
562
|
+
call: () => Ie(!1)
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: "NOW",
|
|
566
|
+
category: "date",
|
|
567
|
+
syntax: "NOW()",
|
|
568
|
+
description: "Returns the current date and time, recalculated on every change.",
|
|
569
|
+
minArgs: 0,
|
|
570
|
+
maxArgs: 0,
|
|
571
|
+
call: () => Ie(!0)
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: "YEAR",
|
|
575
|
+
category: "date",
|
|
576
|
+
syntax: "YEAR(date)",
|
|
577
|
+
description: "Returns the year of a date.",
|
|
578
|
+
minArgs: 1,
|
|
579
|
+
maxArgs: 1,
|
|
580
|
+
call: H((e) => d(e).year)
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
name: "MONTH",
|
|
584
|
+
category: "date",
|
|
585
|
+
syntax: "MONTH(date)",
|
|
586
|
+
description: "Returns the month of a date, 1 to 12.",
|
|
587
|
+
minArgs: 1,
|
|
588
|
+
maxArgs: 1,
|
|
589
|
+
call: H((e) => d(e).month)
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
name: "DAY",
|
|
593
|
+
category: "date",
|
|
594
|
+
syntax: "DAY(date)",
|
|
595
|
+
description: "Returns the day of the month of a date, 1 to 31.",
|
|
596
|
+
minArgs: 1,
|
|
597
|
+
maxArgs: 1,
|
|
598
|
+
call: H((e) => d(e).day)
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
name: "HOUR",
|
|
602
|
+
category: "date",
|
|
603
|
+
syntax: "HOUR(time)",
|
|
604
|
+
description: "Returns the hour of a time, 0 to 23.",
|
|
605
|
+
minArgs: 1,
|
|
606
|
+
maxArgs: 1,
|
|
607
|
+
call: H((e) => d(e).hours)
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: "MINUTE",
|
|
611
|
+
category: "date",
|
|
612
|
+
syntax: "MINUTE(time)",
|
|
613
|
+
description: "Returns the minute of a time, 0 to 59.",
|
|
614
|
+
minArgs: 1,
|
|
615
|
+
maxArgs: 1,
|
|
616
|
+
call: H((e) => d(e).minutes)
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
name: "SECOND",
|
|
620
|
+
category: "date",
|
|
621
|
+
syntax: "SECOND(time)",
|
|
622
|
+
description: "Returns the second of a time, 0 to 59.",
|
|
623
|
+
minArgs: 1,
|
|
624
|
+
maxArgs: 1,
|
|
625
|
+
call: H((e) => d(e).seconds)
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
name: "WEEKDAY",
|
|
629
|
+
category: "date",
|
|
630
|
+
syntax: "WEEKDAY(date, [type])",
|
|
631
|
+
description: "Returns the day of the week: type 1 counts Sunday as 1, type 2 Monday as 1, type 3 Monday as 0.",
|
|
632
|
+
minArgs: 1,
|
|
633
|
+
maxArgs: 2,
|
|
634
|
+
call: (e) => {
|
|
635
|
+
let t = V(e[0]), n = F(e, 1, 1);
|
|
636
|
+
return B(t, n) ?? Ae(t, Math.trunc(n));
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
name: "WEEKNUM",
|
|
641
|
+
category: "date",
|
|
642
|
+
syntax: "WEEKNUM(date, [type])",
|
|
643
|
+
description: "Returns the week of the year, with weeks starting on Sunday (type 1) or Monday (type 2).",
|
|
644
|
+
minArgs: 1,
|
|
645
|
+
maxArgs: 2,
|
|
646
|
+
call: (e) => {
|
|
647
|
+
let t = V(e[0]), n = F(e, 1, 1);
|
|
648
|
+
return B(t, n) ?? Me(t, Math.trunc(n));
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: "ISOWEEKNUM",
|
|
653
|
+
category: "date",
|
|
654
|
+
syntax: "ISOWEEKNUM(date)",
|
|
655
|
+
description: "Returns the ISO 8601 week of the year, where weeks start on Monday.",
|
|
656
|
+
minArgs: 1,
|
|
657
|
+
maxArgs: 1,
|
|
658
|
+
call: H(je)
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: "EDATE",
|
|
662
|
+
category: "date",
|
|
663
|
+
syntax: "EDATE(start_date, months)",
|
|
664
|
+
description: "Returns the date a number of months before or after another.",
|
|
665
|
+
minArgs: 2,
|
|
666
|
+
maxArgs: 2,
|
|
667
|
+
call: (e) => {
|
|
668
|
+
let t = V(e[0]), n = M(e[1]);
|
|
669
|
+
return B(t, n) ?? ke(t, n);
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
name: "EOMONTH",
|
|
674
|
+
category: "date",
|
|
675
|
+
syntax: "EOMONTH(start_date, months)",
|
|
676
|
+
description: "Returns the last day of the month a number of months before or after a date.",
|
|
677
|
+
minArgs: 2,
|
|
678
|
+
maxArgs: 2,
|
|
679
|
+
call: (e) => {
|
|
680
|
+
let t = V(e[0]), n = M(e[1]), r = B(t, n);
|
|
681
|
+
if (r) return r;
|
|
682
|
+
let { year: i, month: a } = d(ke(t, n));
|
|
683
|
+
return u(i, a + 1, 0);
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
name: "DAYS",
|
|
688
|
+
category: "date",
|
|
689
|
+
syntax: "DAYS(end_date, start_date)",
|
|
690
|
+
description: "Returns the number of days between two dates.",
|
|
691
|
+
minArgs: 2,
|
|
692
|
+
maxArgs: 2,
|
|
693
|
+
call: (e) => {
|
|
694
|
+
let t = V(e[0]), n = V(e[1]);
|
|
695
|
+
return B(t, n) ?? Math.floor(t) - Math.floor(n);
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
name: "DATEDIF",
|
|
700
|
+
category: "date",
|
|
701
|
+
syntax: "DATEDIF(start_date, end_date, unit)",
|
|
702
|
+
description: "Returns the whole years (Y), months (M) or days (D) between two dates, or the remainders MD, YM and YD.",
|
|
703
|
+
minArgs: 3,
|
|
704
|
+
maxArgs: 3,
|
|
705
|
+
call: (e) => {
|
|
706
|
+
let t = V(e[0]), n = V(e[1]), r = D(e[2]);
|
|
707
|
+
return B(t, n, r) || (typeof r == "string" ? t > n ? x("#NUM!", "The start date is after the end date") : Ne(t, n, r) : x("#VALUE!", "The unit must be text"));
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
name: "DATEVALUE",
|
|
712
|
+
category: "date",
|
|
713
|
+
syntax: "DATEVALUE(text)",
|
|
714
|
+
description: "Converts an ISO date written as text into its serial number.",
|
|
715
|
+
minArgs: 1,
|
|
716
|
+
maxArgs: 1,
|
|
717
|
+
call: (e) => {
|
|
718
|
+
let t = Le(e[0]);
|
|
719
|
+
return S(t) ? t : Math.floor(t);
|
|
720
|
+
}
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
name: "TIMEVALUE",
|
|
724
|
+
category: "date",
|
|
725
|
+
syntax: "TIMEVALUE(text)",
|
|
726
|
+
description: "Converts a time written as text into a fraction of a day.",
|
|
727
|
+
minArgs: 1,
|
|
728
|
+
maxArgs: 1,
|
|
729
|
+
call: (e) => {
|
|
730
|
+
let t = Le(e[0]);
|
|
731
|
+
return S(t) ? t : t - Math.floor(t);
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
name: "NETWORKDAYS",
|
|
736
|
+
category: "date",
|
|
737
|
+
syntax: "NETWORKDAYS(start_date, end_date, [holidays])",
|
|
738
|
+
description: "Counts the weekdays between two dates, inclusive, leaving out holidays.",
|
|
739
|
+
minArgs: 2,
|
|
740
|
+
maxArgs: 3,
|
|
741
|
+
call: (e) => {
|
|
742
|
+
let t = V(e[0]), n = V(e[1]), r = De(e[2]), i = B(t, n, r);
|
|
743
|
+
if (i) return i;
|
|
744
|
+
let a = Math.floor(t), o = Math.floor(n), [s, c] = a <= o ? [a, o] : [o, a], l = 0;
|
|
745
|
+
for (let e = s; e <= c; e++) !Oe(e) && !r.has(e) && l++;
|
|
746
|
+
return a <= o ? l : -l;
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
name: "WORKDAY",
|
|
751
|
+
category: "date",
|
|
752
|
+
syntax: "WORKDAY(start_date, days, [holidays])",
|
|
753
|
+
description: "Returns the date a number of weekdays after or before a date, skipping holidays.",
|
|
754
|
+
minArgs: 2,
|
|
755
|
+
maxArgs: 3,
|
|
756
|
+
call: (e) => {
|
|
757
|
+
let t = V(e[0]), n = M(e[1]), r = De(e[2]), i = B(t, n, r);
|
|
758
|
+
if (i) return i;
|
|
759
|
+
let a = Math.trunc(n);
|
|
760
|
+
if (Math.abs(a) > 1e6) return x("#NUM!", "Too many days");
|
|
761
|
+
let o = a < 0 ? -1 : 1, s = Math.floor(t);
|
|
762
|
+
for (; a !== 0;) s += o, !Oe(s) && !r.has(s) && (a -= o);
|
|
763
|
+
return s < 0 ? x("#NUM!", "Dates before 1899-12-30 are not supported") : s;
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
name: "YEARFRAC",
|
|
768
|
+
category: "date",
|
|
769
|
+
syntax: "YEARFRAC(start_date, end_date, [basis])",
|
|
770
|
+
description: "Returns the fraction of a year between two dates, by a day count basis from 0 to 4.",
|
|
771
|
+
minArgs: 2,
|
|
772
|
+
maxArgs: 3,
|
|
773
|
+
call: (e) => {
|
|
774
|
+
let t = V(e[0]), n = V(e[1]), r = F(e, 2, 0);
|
|
775
|
+
return B(t, n, r) || Fe(t, n, Math.trunc(r));
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
], U = (e) => (t) => {
|
|
779
|
+
let n = t[0];
|
|
780
|
+
return C(n) && n.rows * n.cols !== 1 ? x("#VALUE!", "A range cannot be used as a single value") : e(D(n));
|
|
781
|
+
}, ze = [
|
|
782
|
+
{
|
|
783
|
+
name: "ISBLANK",
|
|
784
|
+
category: "information",
|
|
785
|
+
syntax: "ISBLANK(value)",
|
|
786
|
+
description: "Returns TRUE when a cell is empty.",
|
|
787
|
+
minArgs: 1,
|
|
788
|
+
maxArgs: 1,
|
|
789
|
+
call: U((e) => e === null)
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
name: "ISNUMBER",
|
|
793
|
+
category: "information",
|
|
794
|
+
syntax: "ISNUMBER(value)",
|
|
795
|
+
description: "Returns TRUE when a value is a number.",
|
|
796
|
+
minArgs: 1,
|
|
797
|
+
maxArgs: 1,
|
|
798
|
+
call: U((e) => typeof e == "number")
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: "ISTEXT",
|
|
802
|
+
category: "information",
|
|
803
|
+
syntax: "ISTEXT(value)",
|
|
804
|
+
description: "Returns TRUE when a value is text.",
|
|
805
|
+
minArgs: 1,
|
|
806
|
+
maxArgs: 1,
|
|
807
|
+
call: U((e) => typeof e == "string")
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
name: "ISLOGICAL",
|
|
811
|
+
category: "information",
|
|
812
|
+
syntax: "ISLOGICAL(value)",
|
|
813
|
+
description: "Returns TRUE when a value is TRUE or FALSE.",
|
|
814
|
+
minArgs: 1,
|
|
815
|
+
maxArgs: 1,
|
|
816
|
+
call: U((e) => typeof e == "boolean")
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
name: "ISERROR",
|
|
820
|
+
category: "information",
|
|
821
|
+
syntax: "ISERROR(value)",
|
|
822
|
+
description: "Returns TRUE when a value is any error.",
|
|
823
|
+
minArgs: 1,
|
|
824
|
+
maxArgs: 1,
|
|
825
|
+
call: U((e) => S(e))
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: "ISNA",
|
|
829
|
+
category: "information",
|
|
830
|
+
syntax: "ISNA(value)",
|
|
831
|
+
description: "Returns TRUE when a value is the #N/A error.",
|
|
832
|
+
minArgs: 1,
|
|
833
|
+
maxArgs: 1,
|
|
834
|
+
call: U((e) => S(e) && e.error === "#N/A")
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
name: "NA",
|
|
838
|
+
category: "information",
|
|
839
|
+
syntax: "NA()",
|
|
840
|
+
description: "Returns the #N/A error, for a value that is not available.",
|
|
841
|
+
minArgs: 0,
|
|
842
|
+
maxArgs: 0,
|
|
843
|
+
call: () => x("#N/A")
|
|
844
|
+
}
|
|
845
|
+
];
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region src/formula/functions/logical.ts
|
|
848
|
+
function Be(e) {
|
|
849
|
+
let t = [];
|
|
850
|
+
for (let n of e) if (C(n)) {
|
|
851
|
+
let e = null;
|
|
852
|
+
if (E(n, (n) => {
|
|
853
|
+
if (S(n)) return e = n, !0;
|
|
854
|
+
(typeof n == "boolean" || typeof n == "number") && t.push(j(n));
|
|
855
|
+
}), e) return e;
|
|
856
|
+
} else if (n !== null) {
|
|
857
|
+
let e = j(n);
|
|
858
|
+
if (S(e)) return e;
|
|
859
|
+
t.push(e);
|
|
860
|
+
}
|
|
861
|
+
return t.length === 0 ? x("#VALUE!", "There are no logical values") : t;
|
|
862
|
+
}
|
|
863
|
+
var W = (e) => (t) => {
|
|
864
|
+
let n = Be(t);
|
|
865
|
+
return S(n) ? n : e(n);
|
|
866
|
+
};
|
|
867
|
+
function Ve(e) {
|
|
868
|
+
let t = C(e) && e.rows * e.cols === 1 ? e.get(0, 0) : e;
|
|
869
|
+
return S(t) ? t : null;
|
|
870
|
+
}
|
|
871
|
+
var He = [
|
|
872
|
+
{
|
|
873
|
+
name: "IF",
|
|
874
|
+
category: "logical",
|
|
875
|
+
syntax: "IF(condition, [value_if_true], [value_if_false])",
|
|
876
|
+
description: "Returns one value when a condition is true and another when it is false.",
|
|
877
|
+
minArgs: 2,
|
|
878
|
+
maxArgs: 3,
|
|
879
|
+
lazy: (e, t, n) => {
|
|
880
|
+
let r = P(n(e[0]));
|
|
881
|
+
return S(r) ? r : r ? n(e[1]) : e[2] === void 0 ? !1 : n(e[2]);
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
name: "IFS",
|
|
886
|
+
category: "logical",
|
|
887
|
+
syntax: "IFS(condition1, value1, [condition2, value2, ...])",
|
|
888
|
+
description: "Returns the value paired with the first condition that is true.",
|
|
889
|
+
minArgs: 2,
|
|
890
|
+
maxArgs: Infinity,
|
|
891
|
+
lazy: (e, t, n) => {
|
|
892
|
+
if (e.length % 2 != 0) return x("#N/A", "IFS expects conditions and values in pairs");
|
|
893
|
+
for (let t = 0; t < e.length; t += 2) {
|
|
894
|
+
let r = P(n(e[t]));
|
|
895
|
+
if (S(r)) return r;
|
|
896
|
+
if (r) return n(e[t + 1]);
|
|
897
|
+
}
|
|
898
|
+
return x("#N/A", "No condition was true");
|
|
899
|
+
}
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
name: "IFERROR",
|
|
903
|
+
category: "logical",
|
|
904
|
+
syntax: "IFERROR(value, value_if_error)",
|
|
905
|
+
description: "Returns a value, or a fallback when the value is any error.",
|
|
906
|
+
minArgs: 2,
|
|
907
|
+
maxArgs: 2,
|
|
908
|
+
lazy: (e, t, n) => {
|
|
909
|
+
let r = n(e[0]);
|
|
910
|
+
return Ve(r) ? n(e[1]) : r;
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
name: "IFNA",
|
|
915
|
+
category: "logical",
|
|
916
|
+
syntax: "IFNA(value, value_if_na)",
|
|
917
|
+
description: "Returns a value, or a fallback when the value is #N/A.",
|
|
918
|
+
minArgs: 2,
|
|
919
|
+
maxArgs: 2,
|
|
920
|
+
lazy: (e, t, n) => {
|
|
921
|
+
let r = n(e[0]);
|
|
922
|
+
return Ve(r)?.error === "#N/A" ? n(e[1]) : r;
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
name: "AND",
|
|
927
|
+
category: "logical",
|
|
928
|
+
syntax: "AND(value1, [value2, ...])",
|
|
929
|
+
description: "Returns TRUE when every value is true.",
|
|
930
|
+
minArgs: 1,
|
|
931
|
+
maxArgs: Infinity,
|
|
932
|
+
call: W((e) => e.every(Boolean))
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
name: "OR",
|
|
936
|
+
category: "logical",
|
|
937
|
+
syntax: "OR(value1, [value2, ...])",
|
|
938
|
+
description: "Returns TRUE when at least one value is true.",
|
|
939
|
+
minArgs: 1,
|
|
940
|
+
maxArgs: Infinity,
|
|
941
|
+
call: W((e) => e.some(Boolean))
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
name: "XOR",
|
|
945
|
+
category: "logical",
|
|
946
|
+
syntax: "XOR(value1, [value2, ...])",
|
|
947
|
+
description: "Returns TRUE when an odd number of values are true.",
|
|
948
|
+
minArgs: 1,
|
|
949
|
+
maxArgs: Infinity,
|
|
950
|
+
call: W((e) => e.filter(Boolean).length % 2 == 1)
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
name: "NOT",
|
|
954
|
+
category: "logical",
|
|
955
|
+
syntax: "NOT(value)",
|
|
956
|
+
description: "Returns the opposite of a logical value.",
|
|
957
|
+
minArgs: 1,
|
|
958
|
+
maxArgs: 1,
|
|
959
|
+
call: (e) => {
|
|
960
|
+
let t = P(e[0]);
|
|
961
|
+
return S(t) ? t : !t;
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
name: "SWITCH",
|
|
966
|
+
category: "logical",
|
|
967
|
+
syntax: "SWITCH(expression, case1, value1, [case2, value2, ...], [default])",
|
|
968
|
+
description: "Compares a value with a list of cases and returns the value of the first match.",
|
|
969
|
+
minArgs: 3,
|
|
970
|
+
maxArgs: Infinity,
|
|
971
|
+
lazy: (e, t, n) => {
|
|
972
|
+
let r = D(n(e[0]));
|
|
973
|
+
if (S(r)) return r;
|
|
974
|
+
let i = Math.floor((e.length - 1) / 2);
|
|
975
|
+
for (let t = 0; t < i; t++) {
|
|
976
|
+
let i = D(n(e[1 + t * 2]));
|
|
977
|
+
if (S(i)) return i;
|
|
978
|
+
if (typeof i == typeof r && I(r, i) === 0) return n(e[2 + t * 2]);
|
|
979
|
+
}
|
|
980
|
+
return (e.length - 1) % 2 == 1 ? n(e[e.length - 1]) : x("#N/A", "No case matched");
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
name: "TRUE",
|
|
985
|
+
category: "logical",
|
|
986
|
+
syntax: "TRUE()",
|
|
987
|
+
description: "Returns the logical value TRUE.",
|
|
988
|
+
minArgs: 0,
|
|
989
|
+
maxArgs: 0,
|
|
990
|
+
call: () => !0
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
name: "FALSE",
|
|
994
|
+
category: "logical",
|
|
995
|
+
syntax: "FALSE()",
|
|
996
|
+
description: "Returns the logical value FALSE.",
|
|
997
|
+
minArgs: 0,
|
|
998
|
+
maxArgs: 0,
|
|
999
|
+
call: () => !1
|
|
1000
|
+
}
|
|
1001
|
+
];
|
|
1002
|
+
//#endregion
|
|
1003
|
+
//#region src/formula/criteria.ts
|
|
1004
|
+
function Ue(e, t = !0) {
|
|
1005
|
+
let n = "";
|
|
1006
|
+
for (let t = 0; t < e.length; t++) {
|
|
1007
|
+
let r = e[t];
|
|
1008
|
+
r === "~" && t + 1 < e.length ? n += We(e[++t]) : r === "*" ? n += "[\\s\\S]*" : r === "?" ? n += "[\\s\\S]" : n += We(r);
|
|
1009
|
+
}
|
|
1010
|
+
return new RegExp(t ? `^${n}$` : n, "i");
|
|
1011
|
+
}
|
|
1012
|
+
function We(e) {
|
|
1013
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1014
|
+
}
|
|
1015
|
+
var Ge = (e) => e === null || e === "";
|
|
1016
|
+
function Ke(e) {
|
|
1017
|
+
if (e === null) return Ge;
|
|
1018
|
+
if (typeof e == "number" || typeof e == "boolean") return (t) => typeof t == typeof e && t === e;
|
|
1019
|
+
if (S(e)) return (t) => S(t) && t.error === e.error;
|
|
1020
|
+
let t = /^(<=|>=|<>|<|>|=)?([\s\S]*)$/.exec(e), n = t?.[1] ?? "", r = t?.[2] ?? "";
|
|
1021
|
+
if (r === "") return n === "" || n === "=" ? Ge : n === "<>" ? (e) => !Ge(e) : () => !1;
|
|
1022
|
+
let i = O(r) ?? g(r), a = r.toUpperCase(), o = i === null ? a === "TRUE" ? !0 : a === "FALSE" ? !1 : r : i;
|
|
1023
|
+
if (n === "" || n === "=" || n === "<>") {
|
|
1024
|
+
let e = typeof o == "string" ? (() => {
|
|
1025
|
+
let e = Ue(o);
|
|
1026
|
+
return (t) => typeof t == "string" && e.test(t);
|
|
1027
|
+
})() : (e) => typeof e == typeof o && e === o;
|
|
1028
|
+
return n === "<>" ? (t) => !e(t) : e;
|
|
1029
|
+
}
|
|
1030
|
+
return (e) => {
|
|
1031
|
+
if (e === null || S(e) || typeof e != typeof o) return !1;
|
|
1032
|
+
let t = I(e, o);
|
|
1033
|
+
switch (n) {
|
|
1034
|
+
case "<": return t < 0;
|
|
1035
|
+
case ">": return t > 0;
|
|
1036
|
+
case "<=": return t <= 0;
|
|
1037
|
+
default: return t >= 0;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/formula/functions/lookup.ts
|
|
1043
|
+
var qe = () => x("#N/A", "The value was not found");
|
|
1044
|
+
function Je(e) {
|
|
1045
|
+
return e.cols === 1 ? {
|
|
1046
|
+
length: e.rows,
|
|
1047
|
+
at: (t) => e.get(t, 0)
|
|
1048
|
+
} : e.rows === 1 ? {
|
|
1049
|
+
length: e.cols,
|
|
1050
|
+
at: (t) => e.get(0, t)
|
|
1051
|
+
} : null;
|
|
1052
|
+
}
|
|
1053
|
+
function Ye(e, t) {
|
|
1054
|
+
if (typeof e == "string" && t && /[*?~]/.test(e)) {
|
|
1055
|
+
let t = Ue(e);
|
|
1056
|
+
return (e) => typeof e == "string" && t.test(e);
|
|
1057
|
+
}
|
|
1058
|
+
return (t) => t !== null && !S(t) && typeof t == typeof e && I(t, e) === 0;
|
|
1059
|
+
}
|
|
1060
|
+
function Xe(e, t, n, r) {
|
|
1061
|
+
if (n === 0) {
|
|
1062
|
+
let n = Ye(t, r);
|
|
1063
|
+
for (let t = 0; t < e.length; t++) if (n(e.at(t))) return t;
|
|
1064
|
+
return -1;
|
|
1065
|
+
}
|
|
1066
|
+
let i = -1;
|
|
1067
|
+
for (let r = 0; r < e.length; r++) {
|
|
1068
|
+
let a = e.at(r);
|
|
1069
|
+
if (a === null || S(a) || typeof a != typeof t) continue;
|
|
1070
|
+
let o = I(a, t);
|
|
1071
|
+
if (o === 0) return r;
|
|
1072
|
+
if (n === 1 && o < 0 || n === -1 && o > 0) i = r;
|
|
1073
|
+
else break;
|
|
1074
|
+
}
|
|
1075
|
+
return i;
|
|
1076
|
+
}
|
|
1077
|
+
function Ze(e, t) {
|
|
1078
|
+
let n = D(e[0]), r = T(e[1]), i = M(e[2]), a = e[3] === void 0 || e[3] === null ? !0 : P(e[3]), o = B(n, i, a);
|
|
1079
|
+
if (o) return o;
|
|
1080
|
+
let s = Math.trunc(i), c = t ? r.cols : r.rows;
|
|
1081
|
+
if (s < 1) return x("#VALUE!", "The index must be at least 1");
|
|
1082
|
+
if (s > c) return x("#REF!", "The index is outside the table");
|
|
1083
|
+
let l = Xe(t ? {
|
|
1084
|
+
length: r.rows,
|
|
1085
|
+
at: (e) => r.get(e, 0)
|
|
1086
|
+
} : {
|
|
1087
|
+
length: r.cols,
|
|
1088
|
+
at: (e) => r.get(0, e)
|
|
1089
|
+
}, n, a ? 1 : 0, !0);
|
|
1090
|
+
return l < 0 ? qe() : t ? r.get(l, s - 1) : r.get(s - 1, l);
|
|
1091
|
+
}
|
|
1092
|
+
function G(e, t, n, r, i) {
|
|
1093
|
+
return {
|
|
1094
|
+
kind: "matrix",
|
|
1095
|
+
rows: r,
|
|
1096
|
+
cols: i,
|
|
1097
|
+
get: (r, i) => e.get(t + r, n + i),
|
|
1098
|
+
origin: e.origin ? {
|
|
1099
|
+
row: e.origin.row + t,
|
|
1100
|
+
col: e.origin.col + n
|
|
1101
|
+
} : void 0
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
function Qe(e, t, n) {
|
|
1105
|
+
return e == null ? t.at ? t.at[n] + 1 : x("#VALUE!", "There is no current cell") : C(e) && e.origin ? e.origin[n] + 1 : x("#VALUE!", "A reference is needed");
|
|
1106
|
+
}
|
|
1107
|
+
var $e = [
|
|
1108
|
+
{
|
|
1109
|
+
name: "VLOOKUP",
|
|
1110
|
+
category: "lookup",
|
|
1111
|
+
syntax: "VLOOKUP(key, table, column, [approximate])",
|
|
1112
|
+
description: "Finds a key in the first column of a table and returns the value in another column of that row.",
|
|
1113
|
+
minArgs: 3,
|
|
1114
|
+
maxArgs: 4,
|
|
1115
|
+
call: (e) => Ze(e, !0)
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
name: "HLOOKUP",
|
|
1119
|
+
category: "lookup",
|
|
1120
|
+
syntax: "HLOOKUP(key, table, row, [approximate])",
|
|
1121
|
+
description: "Finds a key in the first row of a table and returns the value in another row of that column.",
|
|
1122
|
+
minArgs: 3,
|
|
1123
|
+
maxArgs: 4,
|
|
1124
|
+
call: (e) => Ze(e, !1)
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
name: "INDEX",
|
|
1128
|
+
category: "lookup",
|
|
1129
|
+
syntax: "INDEX(range, row, [column])",
|
|
1130
|
+
description: "Returns the value at a row and column of a range, counting from 1.",
|
|
1131
|
+
minArgs: 2,
|
|
1132
|
+
maxArgs: 3,
|
|
1133
|
+
call: (e) => {
|
|
1134
|
+
let t = T(e[0]), n = M(e[1]), r = F(e, 2, 0), i = B(n, r);
|
|
1135
|
+
if (i) return i;
|
|
1136
|
+
t.rows === 1 && (e[2] === void 0 || e[2] === null) && (r = n, n = 1);
|
|
1137
|
+
let a = Math.trunc(n), o = Math.trunc(r);
|
|
1138
|
+
return a < 0 || o < 0 || a > t.rows || o > t.cols ? x("#REF!", "The position is outside the range") : a === 0 && o === 0 ? t : a === 0 ? G(t, 0, o - 1, t.rows, 1) : o === 0 ? t.cols === 1 ? G(t, a - 1, 0, 1, 1) : G(t, a - 1, 0, 1, t.cols) : G(t, a - 1, o - 1, 1, 1);
|
|
1139
|
+
}
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
name: "MATCH",
|
|
1143
|
+
category: "lookup",
|
|
1144
|
+
syntax: "MATCH(key, range, [match_type])",
|
|
1145
|
+
description: "Returns the position of a key in a row or column: 1 for sorted ascending, 0 for exact, -1 for sorted descending.",
|
|
1146
|
+
minArgs: 2,
|
|
1147
|
+
maxArgs: 3,
|
|
1148
|
+
call: (e) => {
|
|
1149
|
+
let t = D(e[0]), n = F(e, 2, 1), r = B(t, n);
|
|
1150
|
+
if (r) return r;
|
|
1151
|
+
let i = Je(T(e[1]));
|
|
1152
|
+
if (!i) return x("#N/A", "The range must be one row or one column");
|
|
1153
|
+
let a = Xe(i, t, Math.sign(n), !0);
|
|
1154
|
+
return a < 0 ? qe() : a + 1;
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
name: "XLOOKUP",
|
|
1159
|
+
category: "lookup",
|
|
1160
|
+
syntax: "XLOOKUP(key, lookup_range, return_range, [if_not_found], [match_mode], [search_mode])",
|
|
1161
|
+
description: "Finds a key in a range and returns the matching item of another range, with a fallback when nothing matches.",
|
|
1162
|
+
minArgs: 3,
|
|
1163
|
+
maxArgs: 6,
|
|
1164
|
+
lazy: (e, t, n) => {
|
|
1165
|
+
let r = D(n(e[0])), i = T(n(e[1])), a = T(n(e[2])), o = e[4] ? M(n(e[4])) : 0, s = e[5] ? M(n(e[5])) : 1, c = B(r, o, s);
|
|
1166
|
+
if (c) return c;
|
|
1167
|
+
let l = Je(i);
|
|
1168
|
+
if (!l) return x("#VALUE!", "The lookup range must be one row or one column");
|
|
1169
|
+
let u = i.cols === 1;
|
|
1170
|
+
if (u ? a.rows !== l.length : a.cols !== l.length) return x("#VALUE!", "The ranges differ in size");
|
|
1171
|
+
let d = o, f = [];
|
|
1172
|
+
for (let e = 0; e < l.length; e++) f.push(e);
|
|
1173
|
+
s < 0 && f.reverse();
|
|
1174
|
+
let p = Ye(r, d === 2), m = -1, h = -1;
|
|
1175
|
+
for (let e of f) {
|
|
1176
|
+
let t = l.at(e);
|
|
1177
|
+
if (p(t)) {
|
|
1178
|
+
m = e;
|
|
1179
|
+
break;
|
|
1180
|
+
}
|
|
1181
|
+
if (d !== -1 && d !== 1 || t === null || S(t) || typeof t != typeof r || I(t, r) !== d) continue;
|
|
1182
|
+
let n = h < 0 ? null : l.at(h);
|
|
1183
|
+
(n === null || I(t, n) === -d) && (h = e);
|
|
1184
|
+
}
|
|
1185
|
+
return m < 0 && (m = h), m < 0 ? e[3] && e[3].type !== "missing" ? n(e[3]) : qe() : u ? G(a, m, 0, 1, a.cols) : G(a, 0, m, a.rows, 1);
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
name: "CHOOSE",
|
|
1190
|
+
category: "lookup",
|
|
1191
|
+
syntax: "CHOOSE(index, value1, [value2, ...])",
|
|
1192
|
+
description: "Returns the value at a position in a list of values, counting from 1.",
|
|
1193
|
+
minArgs: 2,
|
|
1194
|
+
maxArgs: Infinity,
|
|
1195
|
+
lazy: (e, t, n) => {
|
|
1196
|
+
let r = M(n(e[0]));
|
|
1197
|
+
if (S(r)) return r;
|
|
1198
|
+
let i = Math.trunc(r);
|
|
1199
|
+
return i < 1 || i >= e.length ? x("#VALUE!", "The index is outside the list") : n(e[i]);
|
|
1200
|
+
}
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
name: "ROWS",
|
|
1204
|
+
category: "lookup",
|
|
1205
|
+
syntax: "ROWS(range)",
|
|
1206
|
+
description: "Returns the number of rows in a range.",
|
|
1207
|
+
minArgs: 1,
|
|
1208
|
+
maxArgs: 1,
|
|
1209
|
+
call: (e) => T(e[0]).rows
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
name: "COLUMNS",
|
|
1213
|
+
category: "lookup",
|
|
1214
|
+
syntax: "COLUMNS(range)",
|
|
1215
|
+
description: "Returns the number of columns in a range.",
|
|
1216
|
+
minArgs: 1,
|
|
1217
|
+
maxArgs: 1,
|
|
1218
|
+
call: (e) => T(e[0]).cols
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
name: "ROW",
|
|
1222
|
+
category: "lookup",
|
|
1223
|
+
syntax: "ROW([reference])",
|
|
1224
|
+
description: "Returns the row number of a reference, or of the current cell.",
|
|
1225
|
+
minArgs: 0,
|
|
1226
|
+
maxArgs: 1,
|
|
1227
|
+
call: (e, t) => Qe(e[0], t, "row")
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
name: "COLUMN",
|
|
1231
|
+
category: "lookup",
|
|
1232
|
+
syntax: "COLUMN([reference])",
|
|
1233
|
+
description: "Returns the column number of a reference, or of the current cell.",
|
|
1234
|
+
minArgs: 0,
|
|
1235
|
+
maxArgs: 1,
|
|
1236
|
+
call: (e, t) => Qe(e[0], t, "col")
|
|
1237
|
+
}
|
|
1238
|
+
], et = (e) => Number(e.toPrecision(15));
|
|
1239
|
+
function K(e, t, n) {
|
|
1240
|
+
let r = Math.trunc(n), i = 10 ** Math.abs(r), a = Math.sign(t);
|
|
1241
|
+
return r >= 0 ? a * e(et(Math.abs(t) * i)) / i : a * e(et(Math.abs(t) / i)) * i;
|
|
1242
|
+
}
|
|
1243
|
+
var tt = (e) => Math.floor(e + .5);
|
|
1244
|
+
function nt(e, t) {
|
|
1245
|
+
let n = [];
|
|
1246
|
+
if (e.length % 2 != 0) return x("#N/A", "Each criteria range needs a criterion");
|
|
1247
|
+
let r = t?.rows, i = t?.cols;
|
|
1248
|
+
for (let t = 0; t < e.length; t += 2) {
|
|
1249
|
+
let a = T(e[t]), o = T(e[t + 1]);
|
|
1250
|
+
if (r === void 0 || i === void 0) r = a.rows, i = a.cols;
|
|
1251
|
+
else if (a.rows !== r || a.cols !== i) return x("#VALUE!", "The ranges differ in size");
|
|
1252
|
+
n.push({
|
|
1253
|
+
range: a,
|
|
1254
|
+
test: Ke(o.get(0, 0))
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
return (e, t) => n.every(({ range: n, test: r }) => r(n.get(e, t)));
|
|
1258
|
+
}
|
|
1259
|
+
function rt(e, t, n, r) {
|
|
1260
|
+
let i = T(e), a = [];
|
|
1261
|
+
for (let e = 0; e < n; e++) for (let n = 0; n < r; n++) {
|
|
1262
|
+
if (!t(e, n)) continue;
|
|
1263
|
+
let r = e < i.rows && n < i.cols ? i.get(e, n) : null;
|
|
1264
|
+
if (S(r)) return r;
|
|
1265
|
+
typeof r == "number" && a.push(r);
|
|
1266
|
+
}
|
|
1267
|
+
return a;
|
|
1268
|
+
}
|
|
1269
|
+
var it = (e) => e.reduce((e, t) => e + t, 0);
|
|
1270
|
+
function at(e) {
|
|
1271
|
+
let t = T(e[0]), n = Ke(T(e[1]).get(0, 0));
|
|
1272
|
+
return rt(e[2] === void 0 || e[2] === null ? e[0] : e[2], (e, r) => n(t.get(e, r)), t.rows, t.cols);
|
|
1273
|
+
}
|
|
1274
|
+
function ot(e) {
|
|
1275
|
+
let t = T(e[0]), n = nt(e.slice(1), t);
|
|
1276
|
+
return S(n) ? n : rt(t, n, t.rows, t.cols);
|
|
1277
|
+
}
|
|
1278
|
+
function st(e, t, n) {
|
|
1279
|
+
let r = M(e[0]), i = F(e, 1, 1), a = B(r, i);
|
|
1280
|
+
if (a) return a;
|
|
1281
|
+
let o = r, s = i;
|
|
1282
|
+
return s === 0 ? n === "FLOOR" ? x("#DIV/0!", "Division by zero") : 0 : o > 0 && s < 0 ? x("#NUM!", "A positive number needs a positive significance") : t(et(o / s)) * s;
|
|
1283
|
+
}
|
|
1284
|
+
var ct = [
|
|
1285
|
+
{
|
|
1286
|
+
name: "SUM",
|
|
1287
|
+
category: "math",
|
|
1288
|
+
syntax: "SUM(value1, [value2, ...])",
|
|
1289
|
+
description: "Adds numbers and the numbers in ranges.",
|
|
1290
|
+
minArgs: 1,
|
|
1291
|
+
maxArgs: Infinity,
|
|
1292
|
+
call: (e) => {
|
|
1293
|
+
let t = L(e);
|
|
1294
|
+
return S(t) ? t : it(t);
|
|
1295
|
+
}
|
|
1296
|
+
},
|
|
1297
|
+
{
|
|
1298
|
+
name: "SUMIF",
|
|
1299
|
+
category: "math",
|
|
1300
|
+
syntax: "SUMIF(range, criterion, [sum_range])",
|
|
1301
|
+
description: "Adds the cells that meet a criterion.",
|
|
1302
|
+
minArgs: 2,
|
|
1303
|
+
maxArgs: 3,
|
|
1304
|
+
call: (e) => {
|
|
1305
|
+
let t = at(e);
|
|
1306
|
+
return S(t) ? t : it(t);
|
|
1307
|
+
}
|
|
1308
|
+
},
|
|
1309
|
+
{
|
|
1310
|
+
name: "SUMIFS",
|
|
1311
|
+
category: "math",
|
|
1312
|
+
syntax: "SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
1313
|
+
description: "Adds the cells that meet every criterion.",
|
|
1314
|
+
minArgs: 3,
|
|
1315
|
+
maxArgs: Infinity,
|
|
1316
|
+
call: (e) => {
|
|
1317
|
+
let t = ot(e);
|
|
1318
|
+
return S(t) ? t : it(t);
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
name: "SUMPRODUCT",
|
|
1323
|
+
category: "math",
|
|
1324
|
+
syntax: "SUMPRODUCT(array1, [array2, ...])",
|
|
1325
|
+
description: "Multiplies matching cells of ranges of the same size and adds the products.",
|
|
1326
|
+
minArgs: 1,
|
|
1327
|
+
maxArgs: Infinity,
|
|
1328
|
+
call: (e) => {
|
|
1329
|
+
let t = e.map(T), { rows: n, cols: r } = t[0];
|
|
1330
|
+
if (t.some((e) => e.rows !== n || e.cols !== r)) return x("#VALUE!", "The ranges differ in size");
|
|
1331
|
+
let i = 0;
|
|
1332
|
+
for (let e = 0; e < n; e++) for (let n = 0; n < r; n++) {
|
|
1333
|
+
let r = 1;
|
|
1334
|
+
for (let i of t) {
|
|
1335
|
+
let t = i.get(e, n);
|
|
1336
|
+
if (S(t)) return t;
|
|
1337
|
+
r *= typeof t == "number" ? t : 0;
|
|
1338
|
+
}
|
|
1339
|
+
i += r;
|
|
1340
|
+
}
|
|
1341
|
+
return i;
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
name: "PRODUCT",
|
|
1346
|
+
category: "math",
|
|
1347
|
+
syntax: "PRODUCT(value1, [value2, ...])",
|
|
1348
|
+
description: "Multiplies numbers and the numbers in ranges.",
|
|
1349
|
+
minArgs: 1,
|
|
1350
|
+
maxArgs: Infinity,
|
|
1351
|
+
call: (e) => {
|
|
1352
|
+
let t = L(e);
|
|
1353
|
+
return S(t) ? t : t.length === 0 ? 0 : t.reduce((e, t) => e * t, 1);
|
|
1354
|
+
}
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
name: "ROUND",
|
|
1358
|
+
category: "math",
|
|
1359
|
+
syntax: "ROUND(value, [digits])",
|
|
1360
|
+
description: "Rounds a number to a number of digits, halves away from zero.",
|
|
1361
|
+
minArgs: 1,
|
|
1362
|
+
maxArgs: 2,
|
|
1363
|
+
call: (e) => {
|
|
1364
|
+
let t = F(e, 1, 0), n = M(e[0]);
|
|
1365
|
+
return B(n, t) ?? K(tt, n, t);
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
name: "ROUNDUP",
|
|
1370
|
+
category: "math",
|
|
1371
|
+
syntax: "ROUNDUP(value, [digits])",
|
|
1372
|
+
description: "Rounds a number away from zero to a number of digits.",
|
|
1373
|
+
minArgs: 1,
|
|
1374
|
+
maxArgs: 2,
|
|
1375
|
+
call: (e) => {
|
|
1376
|
+
let t = F(e, 1, 0), n = M(e[0]);
|
|
1377
|
+
return B(n, t) ?? K(Math.ceil, n, t);
|
|
1378
|
+
}
|
|
1379
|
+
},
|
|
1380
|
+
{
|
|
1381
|
+
name: "ROUNDDOWN",
|
|
1382
|
+
category: "math",
|
|
1383
|
+
syntax: "ROUNDDOWN(value, [digits])",
|
|
1384
|
+
description: "Rounds a number toward zero to a number of digits.",
|
|
1385
|
+
minArgs: 1,
|
|
1386
|
+
maxArgs: 2,
|
|
1387
|
+
call: (e) => {
|
|
1388
|
+
let t = F(e, 1, 0), n = M(e[0]);
|
|
1389
|
+
return B(n, t) ?? K(Math.floor, n, t);
|
|
1390
|
+
}
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
name: "INT",
|
|
1394
|
+
category: "math",
|
|
1395
|
+
syntax: "INT(value)",
|
|
1396
|
+
description: "Rounds a number down to the nearest integer.",
|
|
1397
|
+
minArgs: 1,
|
|
1398
|
+
maxArgs: 1,
|
|
1399
|
+
call: z((e) => Math.floor(e))
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
name: "TRUNC",
|
|
1403
|
+
category: "math",
|
|
1404
|
+
syntax: "TRUNC(value, [digits])",
|
|
1405
|
+
description: "Cuts a number to a number of digits without rounding.",
|
|
1406
|
+
minArgs: 1,
|
|
1407
|
+
maxArgs: 2,
|
|
1408
|
+
call: (e) => {
|
|
1409
|
+
let t = F(e, 1, 0), n = M(e[0]);
|
|
1410
|
+
return B(n, t) ?? K(Math.floor, n, t);
|
|
1411
|
+
}
|
|
1412
|
+
},
|
|
1413
|
+
{
|
|
1414
|
+
name: "ABS",
|
|
1415
|
+
category: "math",
|
|
1416
|
+
syntax: "ABS(value)",
|
|
1417
|
+
description: "Returns a number without its sign.",
|
|
1418
|
+
minArgs: 1,
|
|
1419
|
+
maxArgs: 1,
|
|
1420
|
+
call: z((e) => Math.abs(e))
|
|
1421
|
+
},
|
|
1422
|
+
{
|
|
1423
|
+
name: "MOD",
|
|
1424
|
+
category: "math",
|
|
1425
|
+
syntax: "MOD(dividend, divisor)",
|
|
1426
|
+
description: "Returns the remainder of a division, with the sign of the divisor.",
|
|
1427
|
+
minArgs: 2,
|
|
1428
|
+
maxArgs: 2,
|
|
1429
|
+
call: z((e, t) => t === 0 ? x("#DIV/0!", "Division by zero") : e - t * Math.floor(e / t))
|
|
1430
|
+
},
|
|
1431
|
+
{
|
|
1432
|
+
name: "POWER",
|
|
1433
|
+
category: "math",
|
|
1434
|
+
syntax: "POWER(base, exponent)",
|
|
1435
|
+
description: "Raises a number to a power.",
|
|
1436
|
+
minArgs: 2,
|
|
1437
|
+
maxArgs: 2,
|
|
1438
|
+
call: z((e, t) => e === 0 && t === 0 ? x("#NUM!", "Zero to the power of zero") : e === 0 && t < 0 ? x("#DIV/0!", "Division by zero") : e ** +t)
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
name: "SQRT",
|
|
1442
|
+
category: "math",
|
|
1443
|
+
syntax: "SQRT(value)",
|
|
1444
|
+
description: "Returns the square root of a number.",
|
|
1445
|
+
minArgs: 1,
|
|
1446
|
+
maxArgs: 1,
|
|
1447
|
+
call: z((e) => e < 0 ? x("#NUM!", "Square root of a negative number") : Math.sqrt(e))
|
|
1448
|
+
},
|
|
1449
|
+
{
|
|
1450
|
+
name: "EXP",
|
|
1451
|
+
category: "math",
|
|
1452
|
+
syntax: "EXP(value)",
|
|
1453
|
+
description: "Returns e raised to a power.",
|
|
1454
|
+
minArgs: 1,
|
|
1455
|
+
maxArgs: 1,
|
|
1456
|
+
call: z((e) => Math.exp(e))
|
|
1457
|
+
},
|
|
1458
|
+
{
|
|
1459
|
+
name: "LN",
|
|
1460
|
+
category: "math",
|
|
1461
|
+
syntax: "LN(value)",
|
|
1462
|
+
description: "Returns the natural logarithm of a number.",
|
|
1463
|
+
minArgs: 1,
|
|
1464
|
+
maxArgs: 1,
|
|
1465
|
+
call: z((e) => e <= 0 ? x("#NUM!", "Logarithm of a number that is not positive") : Math.log(e))
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
name: "LOG",
|
|
1469
|
+
category: "math",
|
|
1470
|
+
syntax: "LOG(value, [base])",
|
|
1471
|
+
description: "Returns the logarithm of a number in a base, 10 when left out.",
|
|
1472
|
+
minArgs: 1,
|
|
1473
|
+
maxArgs: 2,
|
|
1474
|
+
call: (e) => {
|
|
1475
|
+
let t = F(e, 1, 10), n = M(e[0]), r = B(n, t);
|
|
1476
|
+
if (r) return r;
|
|
1477
|
+
let i = n, a = t;
|
|
1478
|
+
return i <= 0 || a <= 0 ? x("#NUM!", "Logarithm of a number that is not positive") : a === 1 ? x("#DIV/0!", "Division by zero") : Math.log(i) / Math.log(a);
|
|
1479
|
+
}
|
|
1480
|
+
},
|
|
1481
|
+
{
|
|
1482
|
+
name: "LOG10",
|
|
1483
|
+
category: "math",
|
|
1484
|
+
syntax: "LOG10(value)",
|
|
1485
|
+
description: "Returns the base 10 logarithm of a number.",
|
|
1486
|
+
minArgs: 1,
|
|
1487
|
+
maxArgs: 1,
|
|
1488
|
+
call: z((e) => e <= 0 ? x("#NUM!", "Logarithm of a number that is not positive") : Math.log10(e))
|
|
1489
|
+
},
|
|
1490
|
+
{
|
|
1491
|
+
name: "PI",
|
|
1492
|
+
category: "math",
|
|
1493
|
+
syntax: "PI()",
|
|
1494
|
+
description: "Returns the number pi.",
|
|
1495
|
+
minArgs: 0,
|
|
1496
|
+
maxArgs: 0,
|
|
1497
|
+
call: () => Math.PI
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
name: "SIGN",
|
|
1501
|
+
category: "math",
|
|
1502
|
+
syntax: "SIGN(value)",
|
|
1503
|
+
description: "Returns 1 for a positive number, -1 for a negative one and 0 for zero.",
|
|
1504
|
+
minArgs: 1,
|
|
1505
|
+
maxArgs: 1,
|
|
1506
|
+
call: z((e) => Math.sign(e))
|
|
1507
|
+
},
|
|
1508
|
+
{
|
|
1509
|
+
name: "CEILING",
|
|
1510
|
+
category: "math",
|
|
1511
|
+
syntax: "CEILING(value, [significance])",
|
|
1512
|
+
description: "Rounds a number up to the nearest multiple of a significance, 1 when left out.",
|
|
1513
|
+
minArgs: 1,
|
|
1514
|
+
maxArgs: 2,
|
|
1515
|
+
call: (e) => st(e, Math.ceil, "CEILING")
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
name: "FLOOR",
|
|
1519
|
+
category: "math",
|
|
1520
|
+
syntax: "FLOOR(value, [significance])",
|
|
1521
|
+
description: "Rounds a number down to the nearest multiple of a significance, 1 when left out.",
|
|
1522
|
+
minArgs: 1,
|
|
1523
|
+
maxArgs: 2,
|
|
1524
|
+
call: (e) => st(e, Math.floor, "FLOOR")
|
|
1525
|
+
}
|
|
1526
|
+
], lt = (e) => e.length === 0 ? x("#DIV/0!", "There are no numbers to average") : e.reduce((e, t) => e + t, 0) / e.length;
|
|
1527
|
+
function ut(e) {
|
|
1528
|
+
if (e.length < 2) return x("#DIV/0!", "At least two numbers are needed");
|
|
1529
|
+
let t = e.reduce((e, t) => e + t, 0) / e.length;
|
|
1530
|
+
return e.reduce((e, n) => e + (n - t) ** 2, 0) / (e.length - 1);
|
|
1531
|
+
}
|
|
1532
|
+
var q = (e) => (t) => {
|
|
1533
|
+
let n = L(t);
|
|
1534
|
+
return S(n) ? n : e(n);
|
|
1535
|
+
};
|
|
1536
|
+
function dt(e, t) {
|
|
1537
|
+
let n = L([T(e[0])]), r = M(e[1]), i = B(n, r);
|
|
1538
|
+
if (i) return i;
|
|
1539
|
+
let a = n.slice().sort((e, n) => t ? n - e : e - n), o = Math.ceil(r) - 1;
|
|
1540
|
+
return o < 0 || o >= a.length ? x("#NUM!", "The position is outside the list") : a[o];
|
|
1541
|
+
}
|
|
1542
|
+
var ft = [
|
|
1543
|
+
{
|
|
1544
|
+
name: "AVERAGE",
|
|
1545
|
+
category: "statistical",
|
|
1546
|
+
syntax: "AVERAGE(value1, [value2, ...])",
|
|
1547
|
+
description: "Returns the arithmetic mean of numbers and the numbers in ranges.",
|
|
1548
|
+
minArgs: 1,
|
|
1549
|
+
maxArgs: Infinity,
|
|
1550
|
+
call: q(lt)
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
name: "AVERAGEIF",
|
|
1554
|
+
category: "statistical",
|
|
1555
|
+
syntax: "AVERAGEIF(range, criterion, [average_range])",
|
|
1556
|
+
description: "Returns the mean of the cells that meet a criterion.",
|
|
1557
|
+
minArgs: 2,
|
|
1558
|
+
maxArgs: 3,
|
|
1559
|
+
call: (e) => {
|
|
1560
|
+
let t = at(e);
|
|
1561
|
+
return S(t) ? t : lt(t);
|
|
1562
|
+
}
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
name: "AVERAGEIFS",
|
|
1566
|
+
category: "statistical",
|
|
1567
|
+
syntax: "AVERAGEIFS(average_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
1568
|
+
description: "Returns the mean of the cells that meet every criterion.",
|
|
1569
|
+
minArgs: 3,
|
|
1570
|
+
maxArgs: Infinity,
|
|
1571
|
+
call: (e) => {
|
|
1572
|
+
let t = ot(e);
|
|
1573
|
+
return S(t) ? t : lt(t);
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
name: "COUNT",
|
|
1578
|
+
category: "statistical",
|
|
1579
|
+
syntax: "COUNT(value1, [value2, ...])",
|
|
1580
|
+
description: "Counts the numbers among the values and in ranges.",
|
|
1581
|
+
minArgs: 1,
|
|
1582
|
+
maxArgs: Infinity,
|
|
1583
|
+
call: (e) => {
|
|
1584
|
+
let t = 0;
|
|
1585
|
+
for (let n of e) C(n) ? E(n, (e) => {
|
|
1586
|
+
typeof e == "number" && t++;
|
|
1587
|
+
}) : (typeof n == "number" || typeof n == "boolean" || typeof n == "string" && O(n) !== null) && t++;
|
|
1588
|
+
return t;
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
name: "COUNTA",
|
|
1593
|
+
category: "statistical",
|
|
1594
|
+
syntax: "COUNTA(value1, [value2, ...])",
|
|
1595
|
+
description: "Counts the values and the cells in ranges that are not empty.",
|
|
1596
|
+
minArgs: 1,
|
|
1597
|
+
maxArgs: Infinity,
|
|
1598
|
+
call: (e) => {
|
|
1599
|
+
let t = 0;
|
|
1600
|
+
for (let n of e) C(n) ? E(n, (e) => {
|
|
1601
|
+
e !== null && t++;
|
|
1602
|
+
}) : n !== null && t++;
|
|
1603
|
+
return t;
|
|
1604
|
+
}
|
|
1605
|
+
},
|
|
1606
|
+
{
|
|
1607
|
+
name: "COUNTBLANK",
|
|
1608
|
+
category: "statistical",
|
|
1609
|
+
syntax: "COUNTBLANK(range)",
|
|
1610
|
+
description: "Counts the empty cells in a range, including cells with empty text.",
|
|
1611
|
+
minArgs: 1,
|
|
1612
|
+
maxArgs: 1,
|
|
1613
|
+
call: (e) => {
|
|
1614
|
+
let t = 0;
|
|
1615
|
+
return E(T(e[0]), (e) => {
|
|
1616
|
+
(e === null || e === "") && t++;
|
|
1617
|
+
}), t;
|
|
1618
|
+
}
|
|
1619
|
+
},
|
|
1620
|
+
{
|
|
1621
|
+
name: "COUNTIF",
|
|
1622
|
+
category: "statistical",
|
|
1623
|
+
syntax: "COUNTIF(range, criterion)",
|
|
1624
|
+
description: "Counts the cells in a range that meet a criterion.",
|
|
1625
|
+
minArgs: 2,
|
|
1626
|
+
maxArgs: 2,
|
|
1627
|
+
call: (e) => {
|
|
1628
|
+
let t = Ke(T(e[1]).get(0, 0)), n = 0;
|
|
1629
|
+
return E(T(e[0]), (e) => {
|
|
1630
|
+
t(e) && n++;
|
|
1631
|
+
}), n;
|
|
1632
|
+
}
|
|
1633
|
+
},
|
|
1634
|
+
{
|
|
1635
|
+
name: "COUNTIFS",
|
|
1636
|
+
category: "statistical",
|
|
1637
|
+
syntax: "COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
1638
|
+
description: "Counts the positions where every criterion is met.",
|
|
1639
|
+
minArgs: 2,
|
|
1640
|
+
maxArgs: Infinity,
|
|
1641
|
+
call: (e) => {
|
|
1642
|
+
let t = T(e[0]), n = nt(e);
|
|
1643
|
+
if (S(n)) return n;
|
|
1644
|
+
let r = 0;
|
|
1645
|
+
for (let e = 0; e < t.rows; e++) for (let i = 0; i < t.cols; i++) n(e, i) && r++;
|
|
1646
|
+
return r;
|
|
1647
|
+
}
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
name: "MIN",
|
|
1651
|
+
category: "statistical",
|
|
1652
|
+
syntax: "MIN(value1, [value2, ...])",
|
|
1653
|
+
description: "Returns the smallest number, or 0 when there are none.",
|
|
1654
|
+
minArgs: 1,
|
|
1655
|
+
maxArgs: Infinity,
|
|
1656
|
+
call: q((e) => e.length === 0 ? 0 : e.reduce((e, t) => Math.min(e, t)))
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
name: "MAX",
|
|
1660
|
+
category: "statistical",
|
|
1661
|
+
syntax: "MAX(value1, [value2, ...])",
|
|
1662
|
+
description: "Returns the largest number, or 0 when there are none.",
|
|
1663
|
+
minArgs: 1,
|
|
1664
|
+
maxArgs: Infinity,
|
|
1665
|
+
call: q((e) => e.length === 0 ? 0 : e.reduce((e, t) => Math.max(e, t)))
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
name: "MEDIAN",
|
|
1669
|
+
category: "statistical",
|
|
1670
|
+
syntax: "MEDIAN(value1, [value2, ...])",
|
|
1671
|
+
description: "Returns the middle number, or the mean of the two middle numbers.",
|
|
1672
|
+
minArgs: 1,
|
|
1673
|
+
maxArgs: Infinity,
|
|
1674
|
+
call: q((e) => {
|
|
1675
|
+
if (e.length === 0) return x("#NUM!", "There are no numbers");
|
|
1676
|
+
let t = e.slice().sort((e, t) => e - t), n = Math.floor(t.length / 2);
|
|
1677
|
+
return t.length % 2 == 1 ? t[n] : (t[n - 1] + t[n]) / 2;
|
|
1678
|
+
})
|
|
1679
|
+
},
|
|
1680
|
+
{
|
|
1681
|
+
name: "LARGE",
|
|
1682
|
+
category: "statistical",
|
|
1683
|
+
syntax: "LARGE(range, k)",
|
|
1684
|
+
description: "Returns the k-th largest number in a range.",
|
|
1685
|
+
minArgs: 2,
|
|
1686
|
+
maxArgs: 2,
|
|
1687
|
+
call: (e) => dt(e, !0)
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
name: "SMALL",
|
|
1691
|
+
category: "statistical",
|
|
1692
|
+
syntax: "SMALL(range, k)",
|
|
1693
|
+
description: "Returns the k-th smallest number in a range.",
|
|
1694
|
+
minArgs: 2,
|
|
1695
|
+
maxArgs: 2,
|
|
1696
|
+
call: (e) => dt(e, !1)
|
|
1697
|
+
},
|
|
1698
|
+
{
|
|
1699
|
+
name: "STDEV",
|
|
1700
|
+
category: "statistical",
|
|
1701
|
+
syntax: "STDEV(value1, [value2, ...])",
|
|
1702
|
+
description: "Returns the standard deviation of a sample.",
|
|
1703
|
+
minArgs: 1,
|
|
1704
|
+
maxArgs: Infinity,
|
|
1705
|
+
call: q((e) => {
|
|
1706
|
+
let t = ut(e);
|
|
1707
|
+
return S(t) ? t : Math.sqrt(t);
|
|
1708
|
+
})
|
|
1709
|
+
},
|
|
1710
|
+
{
|
|
1711
|
+
name: "VAR",
|
|
1712
|
+
category: "statistical",
|
|
1713
|
+
syntax: "VAR(value1, [value2, ...])",
|
|
1714
|
+
description: "Returns the variance of a sample.",
|
|
1715
|
+
minArgs: 1,
|
|
1716
|
+
maxArgs: Infinity,
|
|
1717
|
+
call: q(ut)
|
|
1718
|
+
}
|
|
1719
|
+
], pt = [
|
|
1720
|
+
"January",
|
|
1721
|
+
"February",
|
|
1722
|
+
"March",
|
|
1723
|
+
"April",
|
|
1724
|
+
"May",
|
|
1725
|
+
"June",
|
|
1726
|
+
"July",
|
|
1727
|
+
"August",
|
|
1728
|
+
"September",
|
|
1729
|
+
"October",
|
|
1730
|
+
"November",
|
|
1731
|
+
"December"
|
|
1732
|
+
], mt = [
|
|
1733
|
+
"Sunday",
|
|
1734
|
+
"Monday",
|
|
1735
|
+
"Tuesday",
|
|
1736
|
+
"Wednesday",
|
|
1737
|
+
"Thursday",
|
|
1738
|
+
"Friday",
|
|
1739
|
+
"Saturday"
|
|
1740
|
+
], ht = (e) => e.kind === "literal" || e.kind === "number" ? e.text : "";
|
|
1741
|
+
function gt(e) {
|
|
1742
|
+
let t = [], n = "";
|
|
1743
|
+
for (let r = 0; r < e.length; r++) {
|
|
1744
|
+
let i = e[r];
|
|
1745
|
+
if (i === "\"") {
|
|
1746
|
+
let t = e.indexOf("\"", r + 1), i = t < 0 ? e.length : t + 1;
|
|
1747
|
+
n += e.slice(r, i), r = i - 1;
|
|
1748
|
+
} else i === "\\" ? (n += e.slice(r, r + 2), r++) : i === ";" ? (t.push(n), n = "") : n += i;
|
|
1749
|
+
}
|
|
1750
|
+
return t.push(n), t;
|
|
1751
|
+
}
|
|
1752
|
+
function _t(e) {
|
|
1753
|
+
let t = [], n = (e) => {
|
|
1754
|
+
let n = t[t.length - 1];
|
|
1755
|
+
n && n.kind === "literal" ? n.text += e : t.push({
|
|
1756
|
+
kind: "literal",
|
|
1757
|
+
text: e
|
|
1758
|
+
});
|
|
1759
|
+
}, r = 0;
|
|
1760
|
+
for (; r < e.length;) {
|
|
1761
|
+
let i = e[r], a = i.toLowerCase();
|
|
1762
|
+
if (i === "\"") {
|
|
1763
|
+
let t = e.indexOf("\"", r + 1), i = t < 0 ? e.length : t;
|
|
1764
|
+
n(e.slice(r + 1, i)), r = i + 1;
|
|
1765
|
+
} else if (i === "\\") n(e[r + 1] ?? ""), r += 2;
|
|
1766
|
+
else if (i === "[") {
|
|
1767
|
+
let t = e.indexOf("]", r);
|
|
1768
|
+
r = t < 0 ? e.length : t + 1;
|
|
1769
|
+
} else if (e.slice(r, r + 5).toUpperCase() === "AM/PM") t.push({
|
|
1770
|
+
kind: "ampm",
|
|
1771
|
+
short: !1
|
|
1772
|
+
}), r += 5;
|
|
1773
|
+
else if (e.slice(r, r + 3).toUpperCase() === "A/P") t.push({
|
|
1774
|
+
kind: "ampm",
|
|
1775
|
+
short: !0
|
|
1776
|
+
}), r += 3;
|
|
1777
|
+
else if ("ymdhs".includes(a)) {
|
|
1778
|
+
let n = r;
|
|
1779
|
+
for (; n < e.length && e[n].toLowerCase() === a;) n++;
|
|
1780
|
+
t.push({
|
|
1781
|
+
kind: "date",
|
|
1782
|
+
code: a.repeat(n - r)
|
|
1783
|
+
}), r = n;
|
|
1784
|
+
} else if ("0#?.,%".includes(i) || a === "e" && /[+-]/.test(e[r + 1] ?? "")) {
|
|
1785
|
+
let n = a === "e" ? 2 : 1, i = t[t.length - 1];
|
|
1786
|
+
i && i.kind === "number" ? i.text += e.slice(r, r + n) : t.push({
|
|
1787
|
+
kind: "number",
|
|
1788
|
+
text: e.slice(r, r + n)
|
|
1789
|
+
}), r += n;
|
|
1790
|
+
} else n(i), r++;
|
|
1791
|
+
}
|
|
1792
|
+
return t;
|
|
1793
|
+
}
|
|
1794
|
+
var J = (e, t) => String(e).padStart(t, "0");
|
|
1795
|
+
function vt(e, t) {
|
|
1796
|
+
let n = d(e), r = t.some((e) => e.kind === "ampm"), i = t.filter((e) => e.kind === "date"), a = "";
|
|
1797
|
+
for (let e of t) if (e.kind === "literal") a += e.text;
|
|
1798
|
+
else if (e.kind === "number") a += e.text;
|
|
1799
|
+
else if (e.kind === "ampm") {
|
|
1800
|
+
let t = n.hours >= 12;
|
|
1801
|
+
a += e.short ? t ? "P" : "A" : t ? "PM" : "AM";
|
|
1802
|
+
} else {
|
|
1803
|
+
let t = i.indexOf(e), o = e.code;
|
|
1804
|
+
switch (o[0]) {
|
|
1805
|
+
case "y":
|
|
1806
|
+
a += o.length <= 2 ? J(n.year % 100, 2) : String(n.year);
|
|
1807
|
+
break;
|
|
1808
|
+
case "d":
|
|
1809
|
+
o.length === 1 ? a += n.day : o.length === 2 ? a += J(n.day, 2) : o.length === 3 ? a += mt[n.weekday].slice(0, 3) : a += mt[n.weekday];
|
|
1810
|
+
break;
|
|
1811
|
+
case "h": {
|
|
1812
|
+
let e = r ? n.hours % 12 || 12 : n.hours;
|
|
1813
|
+
a += o.length === 1 ? e : J(e, 2);
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
case "s":
|
|
1817
|
+
a += o.length === 1 ? n.seconds : J(n.seconds, 2);
|
|
1818
|
+
break;
|
|
1819
|
+
default: {
|
|
1820
|
+
let e = i[t - 1]?.code[0], r = i[t + 1]?.code[0];
|
|
1821
|
+
o.length <= 2 && (e === "h" || r === "s") ? a += o.length === 1 ? n.minutes : J(n.minutes, 2) : o.length === 1 ? a += n.month : o.length === 2 ? a += J(n.month, 2) : o.length === 3 ? a += pt[n.month - 1].slice(0, 3) : o.length === 4 ? a += pt[n.month - 1] : a += pt[n.month - 1][0];
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return a;
|
|
1826
|
+
}
|
|
1827
|
+
function yt(e, t) {
|
|
1828
|
+
let n = 10 ** t;
|
|
1829
|
+
return Math.round(Number((e * n).toPrecision(15))) / n;
|
|
1830
|
+
}
|
|
1831
|
+
function bt(e) {
|
|
1832
|
+
return e.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
1833
|
+
}
|
|
1834
|
+
function xt(e, t, n) {
|
|
1835
|
+
let r = Math.abs(e) * 100 ** n, i = t.search(/[eE][+-]/), a = i < 0 ? t : t.slice(0, i), o = a.indexOf("."), s = o < 0 ? a : a.slice(0, o), c = o < 0 ? "" : a.slice(o + 1).replace(/,/g, ""), l = /,+$/.exec(s);
|
|
1836
|
+
l && (r /= 1e3 ** l[0].length, s = s.slice(0, -l[0].length));
|
|
1837
|
+
let u = s.includes(","), d = (s.match(/0/g) ?? []).length, f = (c.match(/[0#?]/g) ?? []).length, p = (/^0*/.exec(c) ?? [""])[0].length, m = "";
|
|
1838
|
+
if (i >= 0) {
|
|
1839
|
+
let e = t.slice(i + 2), n = r === 0 ? 0 : Math.floor(Math.log10(r)), a = r / 10 ** n;
|
|
1840
|
+
yt(a, f) >= 10 && (n++, a = r / 10 ** n), r = a;
|
|
1841
|
+
let o = n < 0 ? "-" : t[i + 1] === "+" ? "+" : "", s = (e.match(/0/g) ?? []).length;
|
|
1842
|
+
m = t[i] + o + J(Math.abs(n), s);
|
|
1843
|
+
}
|
|
1844
|
+
let [h, g = ""] = yt(r, f).toFixed(f).split("."), _ = g;
|
|
1845
|
+
for (; _.length > p && _.endsWith("0");) _ = _.slice(0, -1);
|
|
1846
|
+
let v = h === "0" && d === 0 ? "" : h;
|
|
1847
|
+
return v = v.padStart(d, "0"), u && (v = bt(v)), v + (o >= 0 ? "." + _ : "") + m;
|
|
1848
|
+
}
|
|
1849
|
+
function St(e, t) {
|
|
1850
|
+
let n = gt(t);
|
|
1851
|
+
if (typeof e == "string") return n.length >= 4 ? n[3].replace(/@/g, e).replace(/"/g, "") : e;
|
|
1852
|
+
let r = n[0], i = !0;
|
|
1853
|
+
if (e < 0 && n.length >= 2 && n[1] !== "" ? (r = n[1], i = !1) : e === 0 && n.length >= 3 && n[2] !== "" && (r = n[2]), r.trim().toUpperCase() === "GENERAL" || r === "") return me(e);
|
|
1854
|
+
let a = _t(r);
|
|
1855
|
+
if (a.some((e) => e.kind === "date" || e.kind === "ampm")) return vt(e, a);
|
|
1856
|
+
let o = a.filter((e) => e.kind === "number").map((e) => e.text).join("");
|
|
1857
|
+
if (!/[0#?]/.test(o)) return a.map(ht).join("");
|
|
1858
|
+
let s = (o.match(/%/g) ?? []).length, c = xt(e, o.replace(/%/g, "").replace(/\?/g, "#"), s), l = i && e < 0 && /[1-9]/.test(c), u = !1, d = "";
|
|
1859
|
+
for (let e of a) e.kind === "number" ? !u && /[0#?]/.test(e.text) ? (d += (l ? "-" : "") + c + "%".repeat((e.text.match(/%/g) ?? []).length), u = !0) : d += "%".repeat((e.text.match(/%/g) ?? []).length) : d += ht(e);
|
|
1860
|
+
return d;
|
|
1861
|
+
}
|
|
1862
|
+
//#endregion
|
|
1863
|
+
//#region src/formula/functions/text.ts
|
|
1864
|
+
var Ct = 32767;
|
|
1865
|
+
function wt(e) {
|
|
1866
|
+
let t = [];
|
|
1867
|
+
for (let n of e) if (C(n)) {
|
|
1868
|
+
let e = null;
|
|
1869
|
+
if (E(n, (n) => {
|
|
1870
|
+
let r = A(n);
|
|
1871
|
+
if (S(r)) return e = r, !0;
|
|
1872
|
+
t.push(r);
|
|
1873
|
+
}), e) return e;
|
|
1874
|
+
} else {
|
|
1875
|
+
let e = A(n);
|
|
1876
|
+
if (S(e)) return e;
|
|
1877
|
+
t.push(e);
|
|
1878
|
+
}
|
|
1879
|
+
return t;
|
|
1880
|
+
}
|
|
1881
|
+
var Y = (e) => (t) => {
|
|
1882
|
+
let n = N(t[0]);
|
|
1883
|
+
return S(n) ? n : e(n);
|
|
1884
|
+
};
|
|
1885
|
+
function Tt(e, t) {
|
|
1886
|
+
let n = N(e[0]), r = F(e, 1, 1), i = B(n, r);
|
|
1887
|
+
if (i) return i;
|
|
1888
|
+
let a = Math.trunc(r);
|
|
1889
|
+
if (a < 0) return x("#VALUE!", "The count cannot be negative");
|
|
1890
|
+
let o = n;
|
|
1891
|
+
return t ? o.slice(Math.max(0, o.length - a)) : o.slice(0, a);
|
|
1892
|
+
}
|
|
1893
|
+
function Et(e, t) {
|
|
1894
|
+
let n = N(e[0]), r = N(e[1]), i = F(e, 2, 1), a = B(n, r, i);
|
|
1895
|
+
if (a) return a;
|
|
1896
|
+
let o = Math.trunc(i), s = r;
|
|
1897
|
+
if (o < 1 || o > s.length + 1) return x("#VALUE!", "The start position is outside the text");
|
|
1898
|
+
if (t) {
|
|
1899
|
+
let e = s.indexOf(n, o - 1);
|
|
1900
|
+
return e < 0 ? x("#VALUE!", "The text was not found") : e + 1;
|
|
1901
|
+
}
|
|
1902
|
+
let c = Ue(n, !1).exec(s.slice(o - 1));
|
|
1903
|
+
return c ? c.index + o : x("#VALUE!", "The text was not found");
|
|
1904
|
+
}
|
|
1905
|
+
var Dt = [
|
|
1906
|
+
{
|
|
1907
|
+
name: "CONCAT",
|
|
1908
|
+
category: "text",
|
|
1909
|
+
syntax: "CONCAT(value1, [value2, ...])",
|
|
1910
|
+
description: "Joins values and the cells of ranges into one text.",
|
|
1911
|
+
minArgs: 1,
|
|
1912
|
+
maxArgs: Infinity,
|
|
1913
|
+
call: (e) => {
|
|
1914
|
+
let t = wt(e);
|
|
1915
|
+
return S(t) ? t : t.join("");
|
|
1916
|
+
}
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
name: "CONCATENATE",
|
|
1920
|
+
category: "text",
|
|
1921
|
+
syntax: "CONCATENATE(value1, [value2, ...])",
|
|
1922
|
+
description: "Joins values into one text.",
|
|
1923
|
+
minArgs: 1,
|
|
1924
|
+
maxArgs: Infinity,
|
|
1925
|
+
call: (e) => {
|
|
1926
|
+
let t = wt(e);
|
|
1927
|
+
return S(t) ? t : t.join("");
|
|
1928
|
+
}
|
|
1929
|
+
},
|
|
1930
|
+
{
|
|
1931
|
+
name: "TEXTJOIN",
|
|
1932
|
+
category: "text",
|
|
1933
|
+
syntax: "TEXTJOIN(delimiter, ignore_empty, value1, [value2, ...])",
|
|
1934
|
+
description: "Joins values with a delimiter, optionally leaving out empty ones.",
|
|
1935
|
+
minArgs: 3,
|
|
1936
|
+
maxArgs: Infinity,
|
|
1937
|
+
call: (e) => {
|
|
1938
|
+
let t = N(e[0]), n = P(e[1]), r = wt(e.slice(2));
|
|
1939
|
+
return B(t, n, r) || (n ? r.filter((e) => e !== "") : r).join(t);
|
|
1940
|
+
}
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
name: "LEN",
|
|
1944
|
+
category: "text",
|
|
1945
|
+
syntax: "LEN(text)",
|
|
1946
|
+
description: "Returns the number of characters in a text.",
|
|
1947
|
+
minArgs: 1,
|
|
1948
|
+
maxArgs: 1,
|
|
1949
|
+
call: Y((e) => e.length)
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
name: "LEFT",
|
|
1953
|
+
category: "text",
|
|
1954
|
+
syntax: "LEFT(text, [count])",
|
|
1955
|
+
description: "Returns the first characters of a text, one when the count is left out.",
|
|
1956
|
+
minArgs: 1,
|
|
1957
|
+
maxArgs: 2,
|
|
1958
|
+
call: (e) => Tt(e, !1)
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
name: "RIGHT",
|
|
1962
|
+
category: "text",
|
|
1963
|
+
syntax: "RIGHT(text, [count])",
|
|
1964
|
+
description: "Returns the last characters of a text, one when the count is left out.",
|
|
1965
|
+
minArgs: 1,
|
|
1966
|
+
maxArgs: 2,
|
|
1967
|
+
call: (e) => Tt(e, !0)
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
name: "MID",
|
|
1971
|
+
category: "text",
|
|
1972
|
+
syntax: "MID(text, start, count)",
|
|
1973
|
+
description: "Returns characters from the middle of a text, counting from 1.",
|
|
1974
|
+
minArgs: 3,
|
|
1975
|
+
maxArgs: 3,
|
|
1976
|
+
call: (e) => {
|
|
1977
|
+
let t = N(e[0]), n = M(e[1]), r = M(e[2]), i = B(t, n, r);
|
|
1978
|
+
if (i) return i;
|
|
1979
|
+
let a = Math.trunc(n), o = Math.trunc(r);
|
|
1980
|
+
return a < 1 ? x("#VALUE!", "The start position must be at least 1") : o < 0 ? x("#VALUE!", "The count cannot be negative") : t.slice(a - 1, a - 1 + o);
|
|
1981
|
+
}
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
name: "UPPER",
|
|
1985
|
+
category: "text",
|
|
1986
|
+
syntax: "UPPER(text)",
|
|
1987
|
+
description: "Converts a text to upper case.",
|
|
1988
|
+
minArgs: 1,
|
|
1989
|
+
maxArgs: 1,
|
|
1990
|
+
call: Y((e) => e.toUpperCase())
|
|
1991
|
+
},
|
|
1992
|
+
{
|
|
1993
|
+
name: "LOWER",
|
|
1994
|
+
category: "text",
|
|
1995
|
+
syntax: "LOWER(text)",
|
|
1996
|
+
description: "Converts a text to lower case.",
|
|
1997
|
+
minArgs: 1,
|
|
1998
|
+
maxArgs: 1,
|
|
1999
|
+
call: Y((e) => e.toLowerCase())
|
|
2000
|
+
},
|
|
2001
|
+
{
|
|
2002
|
+
name: "PROPER",
|
|
2003
|
+
category: "text",
|
|
2004
|
+
syntax: "PROPER(text)",
|
|
2005
|
+
description: "Capitalises the first letter of each word and lowers the rest.",
|
|
2006
|
+
minArgs: 1,
|
|
2007
|
+
maxArgs: 1,
|
|
2008
|
+
call: Y((e) => e.toLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (e, t, n) => t + n.toUpperCase()))
|
|
2009
|
+
},
|
|
2010
|
+
{
|
|
2011
|
+
name: "TRIM",
|
|
2012
|
+
category: "text",
|
|
2013
|
+
syntax: "TRIM(text)",
|
|
2014
|
+
description: "Removes spaces from both ends and collapses runs of spaces inside.",
|
|
2015
|
+
minArgs: 1,
|
|
2016
|
+
maxArgs: 1,
|
|
2017
|
+
call: Y((e) => e.replace(/ +/g, " ").trim())
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
name: "SUBSTITUTE",
|
|
2021
|
+
category: "text",
|
|
2022
|
+
syntax: "SUBSTITUTE(text, old_text, new_text, [instance])",
|
|
2023
|
+
description: "Replaces occurrences of a text, or only the given occurrence.",
|
|
2024
|
+
minArgs: 3,
|
|
2025
|
+
maxArgs: 4,
|
|
2026
|
+
call: (e) => {
|
|
2027
|
+
let t = N(e[0]), n = N(e[1]), r = N(e[2]), i = e[3] === void 0 || e[3] === null ? null : M(e[3]), a = B(t, n, r, i);
|
|
2028
|
+
if (a) return a;
|
|
2029
|
+
let o = t, s = n;
|
|
2030
|
+
if (s === "") return o;
|
|
2031
|
+
if (i === null) return o.split(s).join(r);
|
|
2032
|
+
let c = Math.trunc(i);
|
|
2033
|
+
if (c < 1) return x("#VALUE!", "The instance must be at least 1");
|
|
2034
|
+
let l = -1;
|
|
2035
|
+
for (let e = 0; e < c; e++) if (l = o.indexOf(s, l + 1), l < 0) return o;
|
|
2036
|
+
return o.slice(0, l) + r + o.slice(l + s.length);
|
|
2037
|
+
}
|
|
2038
|
+
},
|
|
2039
|
+
{
|
|
2040
|
+
name: "REPLACE",
|
|
2041
|
+
category: "text",
|
|
2042
|
+
syntax: "REPLACE(text, start, count, new_text)",
|
|
2043
|
+
description: "Replaces a number of characters at a position, counting from 1.",
|
|
2044
|
+
minArgs: 4,
|
|
2045
|
+
maxArgs: 4,
|
|
2046
|
+
call: (e) => {
|
|
2047
|
+
let t = N(e[0]), n = M(e[1]), r = M(e[2]), i = N(e[3]), a = B(t, n, r, i);
|
|
2048
|
+
if (a) return a;
|
|
2049
|
+
let o = Math.trunc(n), s = Math.trunc(r);
|
|
2050
|
+
if (o < 1) return x("#VALUE!", "The start position must be at least 1");
|
|
2051
|
+
if (s < 0) return x("#VALUE!", "The count cannot be negative");
|
|
2052
|
+
let c = t;
|
|
2053
|
+
return c.slice(0, o - 1) + i + c.slice(o - 1 + s);
|
|
2054
|
+
}
|
|
2055
|
+
},
|
|
2056
|
+
{
|
|
2057
|
+
name: "FIND",
|
|
2058
|
+
category: "text",
|
|
2059
|
+
syntax: "FIND(search_for, text, [start])",
|
|
2060
|
+
description: "Returns the position of a text inside another, matching case.",
|
|
2061
|
+
minArgs: 2,
|
|
2062
|
+
maxArgs: 3,
|
|
2063
|
+
call: (e) => Et(e, !0)
|
|
2064
|
+
},
|
|
2065
|
+
{
|
|
2066
|
+
name: "SEARCH",
|
|
2067
|
+
category: "text",
|
|
2068
|
+
syntax: "SEARCH(search_for, text, [start])",
|
|
2069
|
+
description: "Returns the position of a text inside another, ignoring case and allowing wildcards.",
|
|
2070
|
+
minArgs: 2,
|
|
2071
|
+
maxArgs: 3,
|
|
2072
|
+
call: (e) => Et(e, !1)
|
|
2073
|
+
},
|
|
2074
|
+
{
|
|
2075
|
+
name: "REPT",
|
|
2076
|
+
category: "text",
|
|
2077
|
+
syntax: "REPT(text, times)",
|
|
2078
|
+
description: "Repeats a text a number of times.",
|
|
2079
|
+
minArgs: 2,
|
|
2080
|
+
maxArgs: 2,
|
|
2081
|
+
call: (e) => {
|
|
2082
|
+
let t = N(e[0]), n = M(e[1]), r = B(t, n);
|
|
2083
|
+
if (r) return r;
|
|
2084
|
+
let i = Math.trunc(n);
|
|
2085
|
+
return i < 0 ? x("#VALUE!", "The count cannot be negative") : t.length * i > Ct ? x("#VALUE!", "The text would be too long") : t.repeat(i);
|
|
2086
|
+
}
|
|
2087
|
+
},
|
|
2088
|
+
{
|
|
2089
|
+
name: "EXACT",
|
|
2090
|
+
category: "text",
|
|
2091
|
+
syntax: "EXACT(text1, text2)",
|
|
2092
|
+
description: "Returns TRUE when two texts are the same, including case.",
|
|
2093
|
+
minArgs: 2,
|
|
2094
|
+
maxArgs: 2,
|
|
2095
|
+
call: (e) => {
|
|
2096
|
+
let t = N(e[0]), n = N(e[1]);
|
|
2097
|
+
return B(t, n) ?? t === n;
|
|
2098
|
+
}
|
|
2099
|
+
},
|
|
2100
|
+
{
|
|
2101
|
+
name: "VALUE",
|
|
2102
|
+
category: "text",
|
|
2103
|
+
syntax: "VALUE(text)",
|
|
2104
|
+
description: "Converts a text that looks like a number into the number.",
|
|
2105
|
+
minArgs: 1,
|
|
2106
|
+
maxArgs: 1,
|
|
2107
|
+
call: (e) => {
|
|
2108
|
+
let t = D(e[0]);
|
|
2109
|
+
if (typeof t == "number" || S(t)) return t;
|
|
2110
|
+
let n = typeof t == "string" ? O(t) : null;
|
|
2111
|
+
return n === null ? x("#VALUE!", "The text is not a number") : n;
|
|
2112
|
+
}
|
|
2113
|
+
},
|
|
2114
|
+
{
|
|
2115
|
+
name: "TEXT",
|
|
2116
|
+
category: "text",
|
|
2117
|
+
syntax: "TEXT(value, format)",
|
|
2118
|
+
description: "Formats a number or date as text with a format code such as \"#,##0.00\", \"0%\" or \"yyyy-mm-dd\".",
|
|
2119
|
+
minArgs: 2,
|
|
2120
|
+
maxArgs: 2,
|
|
2121
|
+
call: (e) => {
|
|
2122
|
+
let t = D(e[0]), n = N(e[1]);
|
|
2123
|
+
if (S(t)) return t;
|
|
2124
|
+
if (S(n)) return n;
|
|
2125
|
+
if (typeof t == "boolean") return t ? "TRUE" : "FALSE";
|
|
2126
|
+
if (typeof t == "string") {
|
|
2127
|
+
let e = k(t);
|
|
2128
|
+
return St(S(e) ? t : e, n);
|
|
2129
|
+
}
|
|
2130
|
+
return St(t ?? 0, n);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
], Ot = [
|
|
2134
|
+
...ct,
|
|
2135
|
+
...ft,
|
|
2136
|
+
...He,
|
|
2137
|
+
...Dt,
|
|
2138
|
+
...$e,
|
|
2139
|
+
...ze,
|
|
2140
|
+
...Re
|
|
2141
|
+
].sort((e, t) => e.name < t.name ? -1 : e.name > t.name ? 1 : 0), kt = new Map(Ot.map((e) => [e.name, e])), At = Object.freeze(Ot.map(({ name: e, category: t, syntax: n, description: r, minArgs: i, maxArgs: a }) => Object.freeze({
|
|
2142
|
+
name: e,
|
|
2143
|
+
category: t,
|
|
2144
|
+
syntax: n,
|
|
2145
|
+
description: r,
|
|
2146
|
+
minArgs: i,
|
|
2147
|
+
maxArgs: a
|
|
2148
|
+
})));
|
|
2149
|
+
function jt(e) {
|
|
2150
|
+
let t = e.trim().toUpperCase();
|
|
2151
|
+
return At.filter((e) => e.name.startsWith(t));
|
|
2152
|
+
}
|
|
2153
|
+
//#endregion
|
|
2154
|
+
//#region src/formula/evaluator.ts
|
|
2155
|
+
function X(e, t, n) {
|
|
2156
|
+
if (S(t)) return t;
|
|
2157
|
+
if (S(n)) return n;
|
|
2158
|
+
if (e === "&") {
|
|
2159
|
+
let e = A(t);
|
|
2160
|
+
if (S(e)) return e;
|
|
2161
|
+
let r = A(n);
|
|
2162
|
+
return S(r) ? r : e + r;
|
|
2163
|
+
}
|
|
2164
|
+
if (e === "=" || e === "<>" || e === "<" || e === ">" || e === "<=" || e === ">=") {
|
|
2165
|
+
let r = I(t, n);
|
|
2166
|
+
switch (e) {
|
|
2167
|
+
case "=": return r === 0;
|
|
2168
|
+
case "<>": return r !== 0;
|
|
2169
|
+
case "<": return r < 0;
|
|
2170
|
+
case ">": return r > 0;
|
|
2171
|
+
case "<=": return r <= 0;
|
|
2172
|
+
default: return r >= 0;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
let r = k(t);
|
|
2176
|
+
if (S(r)) return r;
|
|
2177
|
+
let i = k(n);
|
|
2178
|
+
if (S(i)) return i;
|
|
2179
|
+
let a;
|
|
2180
|
+
switch (e) {
|
|
2181
|
+
case "+":
|
|
2182
|
+
a = r + i;
|
|
2183
|
+
break;
|
|
2184
|
+
case "-":
|
|
2185
|
+
a = r - i;
|
|
2186
|
+
break;
|
|
2187
|
+
case "*":
|
|
2188
|
+
a = r * i;
|
|
2189
|
+
break;
|
|
2190
|
+
case "/":
|
|
2191
|
+
if (i === 0) return x("#DIV/0!", "Division by zero");
|
|
2192
|
+
a = r / i;
|
|
2193
|
+
break;
|
|
2194
|
+
default:
|
|
2195
|
+
if (r === 0 && i === 0) return x("#NUM!", "Zero to the power of zero");
|
|
2196
|
+
if (r === 0 && i < 0) return x("#DIV/0!", "Division by zero");
|
|
2197
|
+
a = r ** +i;
|
|
2198
|
+
}
|
|
2199
|
+
return R(a);
|
|
2200
|
+
}
|
|
2201
|
+
var Mt = (e) => !C(e) || e.rows === 1 && e.cols === 1;
|
|
2202
|
+
function Nt(e, t, n) {
|
|
2203
|
+
if (Mt(e) && Mt(t)) return n(D(e), D(t));
|
|
2204
|
+
let r = C(e) ? e : w(1, 1, [e]), i = C(t) ? t : w(1, 1, [t]), a = Math.max(r.rows, i.rows), o = Math.max(r.cols, i.cols), s = (e, t, n) => {
|
|
2205
|
+
let r = e.rows === 1 ? 0 : t, i = e.cols === 1 ? 0 : n;
|
|
2206
|
+
return r >= e.rows || i >= e.cols ? x("#N/A", "The ranges differ in size") : e.get(r, i);
|
|
2207
|
+
}, c = [];
|
|
2208
|
+
for (let e = 0; e < a; e++) for (let t = 0; t < o; t++) c.push(n(s(r, e, t), s(i, e, t)));
|
|
2209
|
+
return w(a, o, c);
|
|
2210
|
+
}
|
|
2211
|
+
function Pt(e, t) {
|
|
2212
|
+
let n = (e) => e === 1 ? "argument" : "arguments";
|
|
2213
|
+
return e === t ? `${e} ${n(e)}` : t === Infinity ? `at least ${e} ${n(e)}` : `between ${e} and ${t} arguments`;
|
|
2214
|
+
}
|
|
2215
|
+
function Z(e, t) {
|
|
2216
|
+
switch (e.type) {
|
|
2217
|
+
case "number":
|
|
2218
|
+
case "string":
|
|
2219
|
+
case "boolean": return e.value;
|
|
2220
|
+
case "error": return e.error;
|
|
2221
|
+
case "missing": return null;
|
|
2222
|
+
case "name": return x("#NAME?", `Unknown name ${e.name}`);
|
|
2223
|
+
case "ref": return fe(t, {
|
|
2224
|
+
r1: e.row,
|
|
2225
|
+
c1: e.col,
|
|
2226
|
+
r2: e.row,
|
|
2227
|
+
c2: e.col
|
|
2228
|
+
});
|
|
2229
|
+
case "range": return fe(t, e.range);
|
|
2230
|
+
case "array": return w(e.rows, e.cols, e.values);
|
|
2231
|
+
case "unary": return Nt(Z(e.operand, t), 0, (t) => e.op === "-" ? X("-", 0, t) : X("+", 0, t));
|
|
2232
|
+
case "percent": return Nt(Z(e.operand, t), 100, (e, t) => X("/", e, t));
|
|
2233
|
+
case "binary": return Nt(Z(e.left, t), Z(e.right, t), (t, n) => X(e.op, t, n));
|
|
2234
|
+
case "call": {
|
|
2235
|
+
let n = kt.get(e.name);
|
|
2236
|
+
if (!n) return x("#NAME?", `Unknown function ${e.name}`);
|
|
2237
|
+
let r = e.args.length;
|
|
2238
|
+
if (r < n.minArgs || r > n.maxArgs) return x("#N/A", `${e.name} expects ${Pt(n.minArgs, n.maxArgs)}`);
|
|
2239
|
+
let i = (e) => Z(e, t);
|
|
2240
|
+
return R(n.lazy ? n.lazy(e.args, t, i) : n.call ? n.call(e.args.map(i), t) : x("#NAME?", `Unknown function ${e.name}`));
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function Ft(e) {
|
|
2245
|
+
let t = D(e);
|
|
2246
|
+
return t === null ? 0 : R(t);
|
|
2247
|
+
}
|
|
2248
|
+
function It(e, t) {
|
|
2249
|
+
try {
|
|
2250
|
+
return Ft(Z(e, t));
|
|
2251
|
+
} catch (e) {
|
|
2252
|
+
if (e instanceof RangeError) return x("#ERROR!", "The formula is nested too deeply");
|
|
2253
|
+
throw e;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
//#endregion
|
|
2257
|
+
//#region src/formula/parser.ts
|
|
2258
|
+
var Lt = class extends Error {}, Rt = {
|
|
2259
|
+
"=": 10,
|
|
2260
|
+
"<>": 10,
|
|
2261
|
+
"<": 10,
|
|
2262
|
+
">": 10,
|
|
2263
|
+
"<=": 10,
|
|
2264
|
+
">=": 10,
|
|
2265
|
+
"&": 20,
|
|
2266
|
+
"+": 30,
|
|
2267
|
+
"-": 30,
|
|
2268
|
+
"*": 40,
|
|
2269
|
+
"/": 40,
|
|
2270
|
+
"^": 50,
|
|
2271
|
+
":": 80
|
|
2272
|
+
}, zt = 60, Bt = 70;
|
|
2273
|
+
function Vt(e, t = _) {
|
|
2274
|
+
let n = b(e, t).filter((e) => e.type !== "whitespace");
|
|
2275
|
+
n.length > 0 && n[0].type === "operator" && n[0].text === "=" && n.shift();
|
|
2276
|
+
let i = 0, s = () => n[i], c = () => n[i++], l = (e) => {
|
|
2277
|
+
throw new Lt(e);
|
|
2278
|
+
}, u = (e) => e ? `Unexpected "${e.text}"` : "The formula ends too early", d = (e) => {
|
|
2279
|
+
let t = m();
|
|
2280
|
+
for (;;) {
|
|
2281
|
+
let n = s();
|
|
2282
|
+
if (!n || n.type !== "operator") break;
|
|
2283
|
+
if (n.text === "%") {
|
|
2284
|
+
if (zt <= e) break;
|
|
2285
|
+
i++, t = {
|
|
2286
|
+
type: "percent",
|
|
2287
|
+
operand: t
|
|
2288
|
+
};
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2291
|
+
let r = Rt[n.text];
|
|
2292
|
+
if (r === void 0 || r <= e) break;
|
|
2293
|
+
i++;
|
|
2294
|
+
let a = d(r);
|
|
2295
|
+
t = n.text === ":" ? p(t, a) : f(n.text, t, a);
|
|
2296
|
+
}
|
|
2297
|
+
return t;
|
|
2298
|
+
}, f = (e, t, n) => ({
|
|
2299
|
+
type: "binary",
|
|
2300
|
+
op: e,
|
|
2301
|
+
left: t,
|
|
2302
|
+
right: n
|
|
2303
|
+
}), p = (e, t) => {
|
|
2304
|
+
let n = (e) => e.type === "ref" ? {
|
|
2305
|
+
r1: e.row,
|
|
2306
|
+
c1: e.col,
|
|
2307
|
+
r2: e.row,
|
|
2308
|
+
c2: e.col
|
|
2309
|
+
} : e.type === "range" ? e.range : null, r = n(e), i = n(t);
|
|
2310
|
+
return !r || !i ? l("A range needs a reference on each side of \":\"") : {
|
|
2311
|
+
type: "range",
|
|
2312
|
+
range: o(Math.min(r.r1, i.r1), Math.min(r.c1, i.c1), Math.max(r.r2, i.r2), Math.max(r.c2, i.c2))
|
|
2313
|
+
};
|
|
2314
|
+
}, m = () => {
|
|
2315
|
+
let e = c();
|
|
2316
|
+
if (!e) return l(u(e));
|
|
2317
|
+
switch (e.type) {
|
|
2318
|
+
case "number": return {
|
|
2319
|
+
type: "number",
|
|
2320
|
+
value: Number(e.text.replace(t.decimal, "."))
|
|
2321
|
+
};
|
|
2322
|
+
case "string": return {
|
|
2323
|
+
type: "string",
|
|
2324
|
+
value: e.text.slice(1, -1).replace(/""/g, "\"")
|
|
2325
|
+
};
|
|
2326
|
+
case "boolean": return {
|
|
2327
|
+
type: "boolean",
|
|
2328
|
+
value: e.text.toUpperCase() === "TRUE"
|
|
2329
|
+
};
|
|
2330
|
+
case "error": return {
|
|
2331
|
+
type: "error",
|
|
2332
|
+
error: x(e.text.toUpperCase())
|
|
2333
|
+
};
|
|
2334
|
+
case "reference": {
|
|
2335
|
+
let t = r(e.text);
|
|
2336
|
+
return t ? {
|
|
2337
|
+
type: "ref",
|
|
2338
|
+
...t
|
|
2339
|
+
} : l(`"${e.text}" is not a reference`);
|
|
2340
|
+
}
|
|
2341
|
+
case "range": {
|
|
2342
|
+
let t = a(e.text);
|
|
2343
|
+
return t ? {
|
|
2344
|
+
type: "range",
|
|
2345
|
+
range: t
|
|
2346
|
+
} : l(`"${e.text}" is not a range`);
|
|
2347
|
+
}
|
|
2348
|
+
case "name": return {
|
|
2349
|
+
type: "name",
|
|
2350
|
+
name: e.text
|
|
2351
|
+
};
|
|
2352
|
+
case "function": return v(e.text);
|
|
2353
|
+
case "brace": return e.text === "{" ? h() : l(u(e));
|
|
2354
|
+
case "paren":
|
|
2355
|
+
if (e.text === "(") {
|
|
2356
|
+
let e = d(0), t = c();
|
|
2357
|
+
return (!t || t.text !== ")") && l("A parenthesis is not closed"), e;
|
|
2358
|
+
}
|
|
2359
|
+
return l(u(e));
|
|
2360
|
+
case "operator": return e.text === "-" || e.text === "+" ? {
|
|
2361
|
+
type: "unary",
|
|
2362
|
+
op: e.text,
|
|
2363
|
+
operand: d(Bt)
|
|
2364
|
+
} : l(u(e));
|
|
2365
|
+
default: return e.text.startsWith("\"") ? l("A text value is missing its closing quote") : l(u(e));
|
|
2366
|
+
}
|
|
2367
|
+
}, h = () => {
|
|
2368
|
+
let e = [[]];
|
|
2369
|
+
for (;;) {
|
|
2370
|
+
let n = c(), r = 1;
|
|
2371
|
+
for (; n?.type === "operator" && (n.text === "-" || n.text === "+");) n.text === "-" && (r = -r), n = c();
|
|
2372
|
+
if (!n) return l("An array is missing its closing \"}\"");
|
|
2373
|
+
if (n.type === "brace" && n.text === "}" && r === 1) return l("An array needs at least one value");
|
|
2374
|
+
let i = e[e.length - 1];
|
|
2375
|
+
if (n.type === "number") i.push(r * Number(n.text.replace(t.decimal, ".")));
|
|
2376
|
+
else if (r === 1 && n.type === "string") i.push(n.text.slice(1, -1).replace(/""/g, "\""));
|
|
2377
|
+
else if (r === 1 && n.type === "boolean") i.push(n.text.toUpperCase() === "TRUE");
|
|
2378
|
+
else if (r === 1 && n.type === "error") i.push(x(n.text.toUpperCase()));
|
|
2379
|
+
else return l("An array can only hold numbers, text, TRUE, FALSE and errors");
|
|
2380
|
+
let a = c();
|
|
2381
|
+
if (a?.type !== "separator") {
|
|
2382
|
+
if (a?.type === "rowSeparator") {
|
|
2383
|
+
e.push([]);
|
|
2384
|
+
continue;
|
|
2385
|
+
}
|
|
2386
|
+
if (a?.type === "brace" && a.text === "}") break;
|
|
2387
|
+
return l(a ? u(a) : "An array is missing its closing \"}\"");
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
let n = e[0].length;
|
|
2391
|
+
if (e.some((e) => e.length !== n)) return l("Every row of an array needs the same number of values");
|
|
2392
|
+
let r = [];
|
|
2393
|
+
for (let t of e) r.push(...t);
|
|
2394
|
+
return {
|
|
2395
|
+
type: "array",
|
|
2396
|
+
rows: e.length,
|
|
2397
|
+
cols: n,
|
|
2398
|
+
values: r
|
|
2399
|
+
};
|
|
2400
|
+
}, g = (e) => !!e && (e.type === "separator" || e.type === "paren" && e.text === ")"), v = (e) => {
|
|
2401
|
+
c();
|
|
2402
|
+
let t = [];
|
|
2403
|
+
if (s()?.type === "paren" && s()?.text === ")") return i++, {
|
|
2404
|
+
type: "call",
|
|
2405
|
+
name: e.toUpperCase(),
|
|
2406
|
+
args: t
|
|
2407
|
+
};
|
|
2408
|
+
for (;;) {
|
|
2409
|
+
t.push(g(s()) ? { type: "missing" } : d(0));
|
|
2410
|
+
let n = c();
|
|
2411
|
+
if (n?.type !== "separator") {
|
|
2412
|
+
if (n?.type === "paren" && n.text === ")") break;
|
|
2413
|
+
l(n ? u(n) : `${e.toUpperCase()} is missing a ")"`);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
return {
|
|
2417
|
+
type: "call",
|
|
2418
|
+
name: e.toUpperCase(),
|
|
2419
|
+
args: t
|
|
2420
|
+
};
|
|
2421
|
+
};
|
|
2422
|
+
try {
|
|
2423
|
+
n.length === 0 && l("The formula is empty");
|
|
2424
|
+
let e = d(0);
|
|
2425
|
+
return i < n.length && l(u(n[i])), e;
|
|
2426
|
+
} catch (e) {
|
|
2427
|
+
return {
|
|
2428
|
+
type: "error",
|
|
2429
|
+
error: x("#ERROR!", e instanceof Lt ? e.message : e instanceof RangeError ? "The formula is nested too deeply" : "The formula could not be read")
|
|
2430
|
+
};
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
function Ht(e, t = []) {
|
|
2434
|
+
let n = [e];
|
|
2435
|
+
for (; n.length > 0;) {
|
|
2436
|
+
let e = n.pop();
|
|
2437
|
+
switch (e.type) {
|
|
2438
|
+
case "ref":
|
|
2439
|
+
case "range":
|
|
2440
|
+
t.push(e);
|
|
2441
|
+
break;
|
|
2442
|
+
case "call":
|
|
2443
|
+
for (let t of e.args) n.push(t);
|
|
2444
|
+
break;
|
|
2445
|
+
case "unary":
|
|
2446
|
+
case "percent":
|
|
2447
|
+
n.push(e.operand);
|
|
2448
|
+
break;
|
|
2449
|
+
case "binary":
|
|
2450
|
+
n.push(e.left, e.right);
|
|
2451
|
+
break;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return t;
|
|
2455
|
+
}
|
|
2456
|
+
//#endregion
|
|
2457
|
+
//#region src/formula/sheet.ts
|
|
2458
|
+
var Ut = 2e4, Q = (e, t) => e * Ut + t, $ = () => x("#REF!", "Circular reference");
|
|
2459
|
+
function Wt(e) {
|
|
2460
|
+
return e === void 0 || e === "" ? null : typeof e == "number" && !Number.isFinite(e) ? x("#NUM!", "The value is not a finite number") : e;
|
|
2461
|
+
}
|
|
2462
|
+
function Gt(e) {
|
|
2463
|
+
let t = Vt(e);
|
|
2464
|
+
return {
|
|
2465
|
+
tree: t,
|
|
2466
|
+
reads: Ht(t)
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
function Kt() {
|
|
2470
|
+
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = {
|
|
2471
|
+
rows: 0,
|
|
2472
|
+
cols: 0
|
|
2473
|
+
}, s = (e) => ({
|
|
2474
|
+
cell(e, t) {
|
|
2475
|
+
let r = Q(e, t), i = n.get(r);
|
|
2476
|
+
return de(i) ? a.get(r) ?? $() : Wt(i);
|
|
2477
|
+
},
|
|
2478
|
+
extent: o,
|
|
2479
|
+
at: e
|
|
2480
|
+
});
|
|
2481
|
+
function c(t) {
|
|
2482
|
+
let c = /* @__PURE__ */ new Map();
|
|
2483
|
+
n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = {
|
|
2484
|
+
rows: 0,
|
|
2485
|
+
cols: 0
|
|
2486
|
+
};
|
|
2487
|
+
let l = [], u = /* @__PURE__ */ new Map();
|
|
2488
|
+
for (let a of Object.keys(t)) {
|
|
2489
|
+
let s = r(a);
|
|
2490
|
+
if (!s) continue;
|
|
2491
|
+
let d = t[a];
|
|
2492
|
+
if (d == null || d === "") continue;
|
|
2493
|
+
let f = Q(s.row, s.col);
|
|
2494
|
+
if (n.set(f, d), o.rows = Math.max(o.rows, s.row + 1), o.cols = Math.max(o.cols, s.col + 1), de(d)) {
|
|
2495
|
+
let t = c.get(d) ?? e.get(d) ?? Gt(d);
|
|
2496
|
+
c.set(d, t), u.set(f, l.length), l.push({
|
|
2497
|
+
key: f,
|
|
2498
|
+
ref: i(s.row, s.col),
|
|
2499
|
+
...s,
|
|
2500
|
+
parsed: t
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
e = c;
|
|
2505
|
+
let d = l.map((e) => {
|
|
2506
|
+
let t = [];
|
|
2507
|
+
for (let n of e.parsed.reads) if (n.type === "ref") {
|
|
2508
|
+
let e = u.get(Q(n.row, n.col));
|
|
2509
|
+
e !== void 0 && t.push(e);
|
|
2510
|
+
} else if (n.type === "range") {
|
|
2511
|
+
let e = Math.min(n.range.r2, o.rows - 1), r = Math.min(n.range.c2, o.cols - 1), { r1: i, c1: a } = n.range;
|
|
2512
|
+
if (Math.max(0, e - i + 1) * Math.max(0, r - a + 1) <= l.length) for (let n = i; n <= e; n++) for (let e = a; e <= r; e++) {
|
|
2513
|
+
let r = u.get(Q(n, e));
|
|
2514
|
+
r !== void 0 && t.push(r);
|
|
2515
|
+
}
|
|
2516
|
+
else l.forEach((n, o) => {
|
|
2517
|
+
n.row >= i && n.row <= e && n.col >= a && n.col <= r && t.push(o);
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
return t;
|
|
2521
|
+
});
|
|
2522
|
+
for (let e of qt(d)) {
|
|
2523
|
+
let t = e[0];
|
|
2524
|
+
if (e.length > 1 || d[t].includes(t)) {
|
|
2525
|
+
for (let t of e) a.set(l[t].key, $());
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
let n = l[t];
|
|
2529
|
+
a.set(n.key, It(n.parsed.tree, s({
|
|
2530
|
+
row: n.row,
|
|
2531
|
+
col: n.col
|
|
2532
|
+
})));
|
|
2533
|
+
}
|
|
2534
|
+
let f = /* @__PURE__ */ new Map();
|
|
2535
|
+
for (let e of l) f.set(e.ref, a.get(e.key) ?? $());
|
|
2536
|
+
return f;
|
|
2537
|
+
}
|
|
2538
|
+
function l(e) {
|
|
2539
|
+
let n = t.get(e);
|
|
2540
|
+
return n || (t.size > 500 && t.clear(), n = Gt(e), t.set(e, n)), It(n.tree, s());
|
|
2541
|
+
}
|
|
2542
|
+
return {
|
|
2543
|
+
compute: c,
|
|
2544
|
+
evaluate: l,
|
|
2545
|
+
get cacheSize() {
|
|
2546
|
+
return e.size;
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
function qt(e) {
|
|
2551
|
+
let t = e.length, n = new Int32Array(t).fill(-1), r = new Int32Array(t), i = new Uint8Array(t), a = [], o = [], s = 0;
|
|
2552
|
+
for (let c = 0; c < t; c++) {
|
|
2553
|
+
if (n[c] !== -1) continue;
|
|
2554
|
+
let t = [c], l = [0];
|
|
2555
|
+
for (n[c] = r[c] = s++, a.push(c), i[c] = 1; t.length > 0;) {
|
|
2556
|
+
let c = t.length - 1, u = t[c], d = e[u][l[c]];
|
|
2557
|
+
if (d !== void 0) {
|
|
2558
|
+
l[c]++, n[d] === -1 ? (n[d] = r[d] = s++, a.push(d), i[d] = 1, t.push(d), l.push(0)) : i[d] && (r[u] = Math.min(r[u], n[d]));
|
|
2559
|
+
continue;
|
|
2560
|
+
}
|
|
2561
|
+
if (t.pop(), l.pop(), t.length > 0) {
|
|
2562
|
+
let e = t[t.length - 1];
|
|
2563
|
+
r[e] = Math.min(r[e], r[u]);
|
|
2564
|
+
}
|
|
2565
|
+
if (r[u] === n[u]) {
|
|
2566
|
+
let e = [], t;
|
|
2567
|
+
do
|
|
2568
|
+
t = a.pop(), i[t] = 0, e.push(t);
|
|
2569
|
+
while (t !== u);
|
|
2570
|
+
o.push(e);
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
return o;
|
|
2575
|
+
}
|
|
2576
|
+
//#endregion
|
|
2577
|
+
export { i as _, Ee as a, r as b, ye as c, _ as d, b as f, e as g, u as h, be as i, de as l, g as m, At as n, ge as o, d as p, jt as r, ve as s, Kt as t, S as u, t as v, a as y };
|