blixify-ui-web 1.2.181 → 1.2.183

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/components/data/dataTemplate/activityChanges.d.ts.map +1 -1
  2. package/lib/components/data/dataTemplate/activityChanges.js +1 -0
  3. package/lib/components/data/dataTemplate/activityChanges.js.map +1 -1
  4. package/lib/components/data/dataTemplate/index.d.ts +1 -0
  5. package/lib/components/data/dataTemplate/index.d.ts.map +1 -1
  6. package/lib/components/data/dataTemplate/index.js +664 -419
  7. package/lib/components/data/dataTemplate/index.js.map +1 -1
  8. package/lib/components/data/dataTemplate/model.d.ts +11 -2
  9. package/lib/components/data/dataTemplate/model.d.ts.map +1 -1
  10. package/lib/components/data/flexFilter/index.d.ts.map +1 -1
  11. package/lib/components/data/flexFilter/index.js +41 -14
  12. package/lib/components/data/flexFilter/index.js.map +1 -1
  13. package/lib/components/data/formula/builder.d.ts +19 -0
  14. package/lib/components/data/formula/builder.d.ts.map +1 -0
  15. package/lib/components/data/formula/builder.js +189 -0
  16. package/lib/components/data/formula/builder.js.map +1 -0
  17. package/lib/components/data/formula/functions.d.ts +22 -0
  18. package/lib/components/data/formula/functions.d.ts.map +1 -0
  19. package/lib/components/data/formula/functions.js +773 -0
  20. package/lib/components/data/formula/functions.js.map +1 -0
  21. package/lib/components/data/formula/index.d.ts +75 -0
  22. package/lib/components/data/formula/index.d.ts.map +1 -0
  23. package/lib/components/data/formula/index.js +801 -0
  24. package/lib/components/data/formula/index.js.map +1 -0
  25. package/lib/components/data/listModule.d.ts.map +1 -1
  26. package/lib/components/data/listModule.js +7 -1
  27. package/lib/components/data/listModule.js.map +1 -1
  28. package/lib/components/data/readModule.d.ts.map +1 -1
  29. package/lib/components/data/readModule.js +25 -2
  30. package/lib/components/data/readModule.js.map +1 -1
  31. package/lib/components/data/utils.d.ts.map +1 -1
  32. package/lib/components/data/utils.js +4 -0
  33. package/lib/components/data/utils.js.map +1 -1
  34. package/lib/components/display/newTable/index.d.ts +1 -0
  35. package/lib/components/display/newTable/index.d.ts.map +1 -1
  36. package/lib/components/display/newTable/index.js +85 -30
  37. package/lib/components/display/newTable/index.js.map +1 -1
  38. package/lib/tail.css +2 -2
  39. package/package.json +1 -1
@@ -0,0 +1,773 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleToFormulaDate = exports.handleFormatFormulaDate = exports.FORMULA_FUNCTION_CATEGORIES = exports.FORMULA_CONSTANTS = exports.FORMULA_FUNCTIONS = exports.handleToFormulaText = exports.handleToFormulaNumber = exports.FORMULA_MAX_TEXT = void 0;
7
+ var dayjs_1 = __importDefault(require("../../dayjs"));
8
+ var advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
9
+ var weekOfYear_1 = __importDefault(require("dayjs/plugin/weekOfYear"));
10
+ dayjs_1.default.extend(advancedFormat_1.default);
11
+ dayjs_1.default.extend(weekOfYear_1.default);
12
+ var dayjs = dayjs_1.default;
13
+ exports.FORMULA_MAX_TEXT = 10000;
14
+ //=====================================================================================
15
+ //SECTION: Value coercion — Monday semantics: an empty cell is "" everywhere,
16
+ // which reads as 0 in arithmetic and as blank text in text functions
17
+ //=====================================================================================
18
+ var handleToFormulaNumber = function (value) {
19
+ if (value === "" || value === null || value === undefined)
20
+ return 0;
21
+ if (typeof value === "boolean")
22
+ return value ? 1 : 0;
23
+ return Number(value);
24
+ };
25
+ exports.handleToFormulaNumber = handleToFormulaNumber;
26
+ var handleToFormulaText = function (value) {
27
+ if (value === null || value === undefined)
28
+ return "";
29
+ if (typeof value === "number")
30
+ return Number.isFinite(value) ? String(handleRoundTo(value, 10)) : "NaN";
31
+ return String(value);
32
+ };
33
+ exports.handleToFormulaText = handleToFormulaText;
34
+ var handleRoundTo = function (value, digits) {
35
+ var factor = Math.pow(10, digits);
36
+ return Math.round(value * factor) / factor;
37
+ };
38
+ var handleToFormulaDate = function (value) {
39
+ if (value === "" || value === null || value === undefined)
40
+ return null;
41
+ var parsed = dayjs(value instanceof Date ? value : String(value));
42
+ return parsed.isValid() ? parsed : null;
43
+ };
44
+ exports.handleToFormulaDate = handleToFormulaDate;
45
+ // INFO: a date that carries no time of day is written without one, so a date
46
+ // column and TODAY() compare as equal text and display the way they were typed
47
+ var handleFormatFormulaDate = function (date) {
48
+ if (!date)
49
+ return "";
50
+ var hasTime = date.hour() !== 0 || date.minute() !== 0 || date.second() !== 0;
51
+ return date.format(hasTime ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD");
52
+ };
53
+ exports.handleFormatFormulaDate = handleFormatFormulaDate;
54
+ // INFO: joins text up to the formula text cap and stops there, rather than
55
+ // building the whole string and cutting it afterwards
56
+ var handleJoinCapped = function (parts) {
57
+ var output = "";
58
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
59
+ var each = parts_1[_i];
60
+ var room = exports.FORMULA_MAX_TEXT - output.length;
61
+ if (room <= 0)
62
+ break;
63
+ output += each.length > room ? each.slice(0, room) : each;
64
+ }
65
+ return output;
66
+ };
67
+ var handleFlattenArgs = function (args) {
68
+ return args.reduce(function (acc, each) { return acc.concat(Array.isArray(each) ? each : [each]); }, []);
69
+ };
70
+ // INFO: TEXT(8500.6, "$#,##0.00") — the subset of spreadsheet number formats
71
+ // Monday documents: literal prefix/suffix, thousands separator, fixed decimals
72
+ // and a trailing percent
73
+ var handleFormatNumberPattern = function (value, pattern) {
74
+ var numberValue = (0, exports.handleToFormulaNumber)(value);
75
+ if (!Number.isFinite(numberValue))
76
+ return "NaN";
77
+ var match = /[#0][#0,]*(\.[#0]+)?%?/.exec(pattern !== null && pattern !== void 0 ? pattern : "");
78
+ if (!match)
79
+ return (0, exports.handleToFormulaText)(value);
80
+ var token = match[0];
81
+ var isPercent = token.endsWith("%");
82
+ var decimals = match[1] ? match[1].length - 1 : 0;
83
+ var scaled = isPercent ? numberValue * 100 : numberValue;
84
+ var formatted = scaled.toLocaleString("en-US", {
85
+ minimumFractionDigits: decimals,
86
+ maximumFractionDigits: decimals,
87
+ useGrouping: token.includes(","),
88
+ });
89
+ return (pattern.slice(0, match.index) +
90
+ formatted +
91
+ (isPercent ? "%" : "") +
92
+ pattern.slice(match.index + token.length));
93
+ };
94
+ var handleCountWorkdays = function (to, from) {
95
+ var _a;
96
+ var start = handleToFormulaDate(from);
97
+ var end = handleToFormulaDate(to);
98
+ if (!start || !end)
99
+ return NaN;
100
+ start = start.startOf("day");
101
+ end = end.startOf("day");
102
+ var sign = end.isBefore(start) ? -1 : 1;
103
+ if (sign < 0)
104
+ _a = [end, start], start = _a[0], end = _a[1];
105
+ // INFO: whole weeks are counted at once and only the remainder (under 7
106
+ // days) is walked — a span of centuries is as quick as a span of days, so a
107
+ // mistyped year cannot freeze the table
108
+ var totalDays = end.diff(start, "day") + 1;
109
+ var fullWeeks = Math.floor(totalDays / 7);
110
+ var count = fullWeeks * 5;
111
+ var cursor = start.add(fullWeeks * 7, "day");
112
+ while (!cursor.isAfter(end)) {
113
+ var weekday = cursor.day();
114
+ if (weekday !== 0 && weekday !== 6)
115
+ count += 1;
116
+ cursor = cursor.add(1, "day");
117
+ }
118
+ return count * sign;
119
+ };
120
+ var handleAddWorkdays = function (date, days) {
121
+ var cursor = handleToFormulaDate(date);
122
+ if (!cursor)
123
+ return "";
124
+ var total = Math.trunc((0, exports.handleToFormulaNumber)(days));
125
+ if (!Number.isFinite(total))
126
+ return "";
127
+ var step = total < 0 ? -1 : 1;
128
+ // INFO: every 5 working days is exactly one calendar week, so whole weeks
129
+ // jump at once and only the last few days are walked
130
+ var fullWeeks = Math.floor(Math.abs(total) / 5);
131
+ cursor = cursor.add(step * fullWeeks * 7, "day");
132
+ var remaining = Math.abs(total) - fullWeeks * 5;
133
+ // INFO: a start on a weekend lands on the weekend after the jump; with
134
+ // nothing left to add the result moves to the next working day in the
135
+ // direction of travel, as a day-by-day walk would have
136
+ if (remaining === 0 && fullWeeks > 0)
137
+ while (cursor.day() === 0 || cursor.day() === 6)
138
+ cursor = cursor.add(-step, "day");
139
+ while (remaining > 0) {
140
+ cursor = cursor.add(step, "day");
141
+ if (cursor.day() !== 0 && cursor.day() !== 6)
142
+ remaining -= 1;
143
+ }
144
+ return handleFormatFormulaDate(cursor);
145
+ };
146
+ var handleParseHours = function (value) {
147
+ var _a = (0, exports.handleToFormulaText)(value).split(":").map(Number), hours = _a[0], minutes = _a[1];
148
+ if (isNaN(hours))
149
+ return NaN;
150
+ return hours * 60 + (isNaN(minutes) ? 0 : minutes);
151
+ };
152
+ //=====================================================================================
153
+ //SECTION: Function library — names, descriptions and examples follow
154
+ // monday.com's "Available functions in the Formula Column"
155
+ //=====================================================================================
156
+ exports.FORMULA_FUNCTIONS = [
157
+ // INFO: Text
158
+ {
159
+ name: "CONCATENATE",
160
+ category: "Text",
161
+ description: "Joins text values into a single text value.",
162
+ example: 'CONCATENATE("I", "love", "monday") => Ilovemonday',
163
+ fn: function () {
164
+ var args = [];
165
+ for (var _i = 0; _i < arguments.length; _i++) {
166
+ args[_i] = arguments[_i];
167
+ }
168
+ return handleJoinCapped(handleFlattenArgs(args).map(exports.handleToFormulaText));
169
+ },
170
+ },
171
+ {
172
+ name: "LEFT",
173
+ category: "Text",
174
+ description: "Extracts a given number of characters from the left side.",
175
+ example: 'LEFT("monday.com", 3) => mon',
176
+ fn: function (text, count) {
177
+ if (count === void 0) { count = 1; }
178
+ return (0, exports.handleToFormulaText)(text).slice(0, (0, exports.handleToFormulaNumber)(count));
179
+ },
180
+ },
181
+ {
182
+ name: "LEN",
183
+ category: "Text",
184
+ description: "Returns the number of characters in a text value.",
185
+ example: 'LEN("hello") => 5',
186
+ fn: function (text) { return (0, exports.handleToFormulaText)(text).length; },
187
+ },
188
+ {
189
+ name: "LOWER",
190
+ category: "Text",
191
+ description: "Converts text to lowercase.",
192
+ example: 'LOWER("Some STRING") => some string',
193
+ fn: function (text) { return (0, exports.handleToFormulaText)(text).toLowerCase(); },
194
+ },
195
+ {
196
+ name: "REPLACE",
197
+ category: "Text",
198
+ description: "Replaces part of a text value, from a start position (1-based) for a number of characters.",
199
+ example: 'REPLACE("Goat", 1, 2, "Fl") => Flat',
200
+ fn: function (text, start, count, replacement) {
201
+ var source = (0, exports.handleToFormulaText)(text);
202
+ var from = Math.max(0, (0, exports.handleToFormulaNumber)(start) - 1);
203
+ return handleJoinCapped([
204
+ source.slice(0, from),
205
+ (0, exports.handleToFormulaText)(replacement),
206
+ source.slice(from + (0, exports.handleToFormulaNumber)(count)),
207
+ ]);
208
+ },
209
+ },
210
+ {
211
+ name: "REPT",
212
+ category: "Text",
213
+ description: "Repeats text a given number of times.",
214
+ example: 'REPT("monday", 3) => mondaymondaymonday',
215
+ fn: function (text, count) {
216
+ var source = (0, exports.handleToFormulaText)(text);
217
+ var times = Math.max(0, Math.trunc((0, exports.handleToFormulaNumber)(count)));
218
+ // INFO: capped at monday's 10K-character formula limit — one cell is
219
+ // drawn in every row, so an unbounded repeat would freeze the board
220
+ if (!source || !Number.isFinite(times))
221
+ return "";
222
+ return source
223
+ .repeat(Math.min(times, Math.ceil(exports.FORMULA_MAX_TEXT / source.length)))
224
+ .slice(0, exports.FORMULA_MAX_TEXT);
225
+ },
226
+ },
227
+ {
228
+ name: "RIGHT",
229
+ category: "Text",
230
+ description: "Extracts a given number of characters from the right side.",
231
+ example: 'RIGHT("monday", 3) => day',
232
+ fn: function (text, count) {
233
+ if (count === void 0) { count = 1; }
234
+ var source = (0, exports.handleToFormulaText)(text);
235
+ var size = (0, exports.handleToFormulaNumber)(count);
236
+ return size <= 0 ? "" : source.slice(-size);
237
+ },
238
+ },
239
+ {
240
+ name: "SEARCH",
241
+ category: "Text",
242
+ description: "Finds text within other text and returns its position (1-based), or 0 when not found.",
243
+ example: 'IF(SEARCH("love", "I love monday") > 0, "Exist", "Not") => Exist',
244
+ fn: function (find, within, start) {
245
+ if (start === void 0) { start = 1; }
246
+ return (0, exports.handleToFormulaText)(within)
247
+ .toLowerCase()
248
+ .indexOf((0, exports.handleToFormulaText)(find).toLowerCase(), Math.max(0, (0, exports.handleToFormulaNumber)(start) - 1)) + 1;
249
+ },
250
+ },
251
+ {
252
+ name: "SUBSTITUTE",
253
+ category: "Text",
254
+ description: "Replaces every match of a text with new text.",
255
+ example: 'SUBSTITUTE("goodmorning", "morning", "night") => goodnight',
256
+ fn: function (text, search, replacement) {
257
+ var needle = (0, exports.handleToFormulaText)(search);
258
+ if (!needle)
259
+ return (0, exports.handleToFormulaText)(text);
260
+ var pieces = (0, exports.handleToFormulaText)(text).split(needle);
261
+ var glue = (0, exports.handleToFormulaText)(replacement);
262
+ // INFO: interleaved and joined with the cap, so 10K matches of a 10K
263
+ // replacement never build the 100M-character string first
264
+ var parts = [];
265
+ pieces.forEach(function (each, index) {
266
+ if (index > 0)
267
+ parts.push(glue);
268
+ parts.push(each);
269
+ });
270
+ return handleJoinCapped(parts);
271
+ },
272
+ },
273
+ {
274
+ name: "TEXT",
275
+ category: "Text",
276
+ description: "Formats a number using a text format.",
277
+ example: 'TEXT(8500.6, "$#,##0.00") => $8,500.60',
278
+ fn: function (value, pattern) {
279
+ return handleFormatNumberPattern(value, (0, exports.handleToFormulaText)(pattern));
280
+ },
281
+ },
282
+ {
283
+ name: "TRIM",
284
+ category: "Text",
285
+ description: "Removes extra spaces, keeping single spaces between words.",
286
+ example: 'TRIM(" I love MDY ") => I love MDY',
287
+ fn: function (text) { return (0, exports.handleToFormulaText)(text).trim().replace(/\s+/g, " "); },
288
+ },
289
+ {
290
+ name: "UPPER",
291
+ category: "Text",
292
+ description: "Converts text to uppercase.",
293
+ example: 'UPPER("monday.com") => MONDAY.COM',
294
+ fn: function (text) { return (0, exports.handleToFormulaText)(text).toUpperCase(); },
295
+ },
296
+ // INFO: Logical
297
+ {
298
+ name: "AND",
299
+ category: "Logical",
300
+ description: "Returns true when every condition is true.",
301
+ example: "AND(3 > 1, 4 > 2) => true",
302
+ fn: function () {
303
+ var args = [];
304
+ for (var _i = 0; _i < arguments.length; _i++) {
305
+ args[_i] = arguments[_i];
306
+ }
307
+ return args.length > 0 && args.every(Boolean);
308
+ },
309
+ },
310
+ {
311
+ name: "EXACT",
312
+ category: "Logical",
313
+ description: "Returns true when two values are exactly the same.",
314
+ example: "EXACT({Status}, {Status}) => true",
315
+ fn: function (a, b) { return (0, exports.handleToFormulaText)(a) === (0, exports.handleToFormulaText)(b); },
316
+ },
317
+ {
318
+ name: "IF",
319
+ category: "Logical",
320
+ description: "Checks a condition. Returns the first value when it is met, otherwise the second.",
321
+ example: 'IF({Budget} > 100, "Big Deal", "Small Deal")',
322
+ fn: function (condition, yes, no) {
323
+ if (no === void 0) { no = ""; }
324
+ return (condition ? yes : no);
325
+ },
326
+ },
327
+ {
328
+ name: "OR",
329
+ category: "Logical",
330
+ description: "Returns true when any condition is true.",
331
+ example: "OR(3 > 10, 4 > 2) => true",
332
+ fn: function () {
333
+ var args = [];
334
+ for (var _i = 0; _i < arguments.length; _i++) {
335
+ args[_i] = arguments[_i];
336
+ }
337
+ return args.some(Boolean);
338
+ },
339
+ },
340
+ {
341
+ name: "XOR",
342
+ category: "Logical",
343
+ description: "Returns true when an odd number of conditions are true.",
344
+ example: "XOR(3 > 0, 2 > 9) => true",
345
+ fn: function () {
346
+ var args = [];
347
+ for (var _i = 0; _i < arguments.length; _i++) {
348
+ args[_i] = arguments[_i];
349
+ }
350
+ return args.filter(Boolean).length % 2 === 1;
351
+ },
352
+ },
353
+ {
354
+ name: "NOT",
355
+ category: "Logical",
356
+ description: "Reverses a condition.",
357
+ example: "NOT(3 > 5) => true",
358
+ fn: function (value) { return !value; },
359
+ },
360
+ {
361
+ name: "SWITCH",
362
+ category: "Logical",
363
+ description: "Compares a value against pairs of value and result, returning the matching result or the default.",
364
+ example: 'SWITCH({Priority}, "High", 3, "Medium", 2, "Low", 1, 0) => 2',
365
+ fn: function (value) {
366
+ var cases = [];
367
+ for (var _i = 1; _i < arguments.length; _i++) {
368
+ cases[_i - 1] = arguments[_i];
369
+ }
370
+ for (var i = 0; i + 1 < cases.length; i += 2) {
371
+ if ((0, exports.handleToFormulaText)(value) === (0, exports.handleToFormulaText)(cases[i]))
372
+ return cases[i + 1];
373
+ }
374
+ return cases.length % 2 === 1 ? cases[cases.length - 1] : "";
375
+ },
376
+ },
377
+ // INFO: Numeric
378
+ {
379
+ name: "ABS",
380
+ category: "Numeric",
381
+ description: "Returns the absolute value of a number.",
382
+ example: "ABS(-1) => 1",
383
+ fn: function (value) { return Math.abs((0, exports.handleToFormulaNumber)(value)); },
384
+ },
385
+ {
386
+ name: "AVERAGE",
387
+ category: "Numeric",
388
+ description: "Returns the average of the given numbers.",
389
+ example: "AVERAGE(1, 2, 3) => 2",
390
+ fn: function () {
391
+ var args = [];
392
+ for (var _i = 0; _i < arguments.length; _i++) {
393
+ args[_i] = arguments[_i];
394
+ }
395
+ var values = handleFlattenArgs(args).map(exports.handleToFormulaNumber);
396
+ return values.length
397
+ ? values.reduce(function (a, b) { return a + b; }, 0) / values.length
398
+ : 0;
399
+ },
400
+ },
401
+ {
402
+ name: "COUNT",
403
+ category: "Numeric",
404
+ description: "Counts how many of the given values are numbers.",
405
+ example: 'COUNT(1, 2, "a") => 2',
406
+ fn: function () {
407
+ var args = [];
408
+ for (var _i = 0; _i < arguments.length; _i++) {
409
+ args[_i] = arguments[_i];
410
+ }
411
+ return handleFlattenArgs(args).filter(function (each) {
412
+ return each !== "" &&
413
+ typeof each !== "boolean" &&
414
+ Number.isFinite(Number(each));
415
+ }).length;
416
+ },
417
+ },
418
+ {
419
+ name: "DIVIDE",
420
+ category: "Numeric",
421
+ description: "Divides one number by another.",
422
+ example: "DIVIDE(10, 5) => 2",
423
+ fn: function (a, b) { return (0, exports.handleToFormulaNumber)(a) / (0, exports.handleToFormulaNumber)(b); },
424
+ },
425
+ {
426
+ name: "LOG",
427
+ category: "Numeric",
428
+ description: "Returns the logarithm of a number in a base (default 10).",
429
+ example: "LOG(16, 2) => 4",
430
+ fn: function (value, base) {
431
+ if (base === void 0) { base = 10; }
432
+ return Math.log((0, exports.handleToFormulaNumber)(value)) /
433
+ Math.log((0, exports.handleToFormulaNumber)(base));
434
+ },
435
+ },
436
+ {
437
+ name: "MAX",
438
+ category: "Numeric",
439
+ description: "Returns the largest of the given numbers.",
440
+ example: "MAX(1, 3, 5, 9) => 9",
441
+ fn: function () {
442
+ var args = [];
443
+ for (var _i = 0; _i < arguments.length; _i++) {
444
+ args[_i] = arguments[_i];
445
+ }
446
+ return Math.max.apply(Math, handleFlattenArgs(args).map(exports.handleToFormulaNumber));
447
+ },
448
+ },
449
+ {
450
+ name: "MIN",
451
+ category: "Numeric",
452
+ description: "Returns the smallest of the given numbers.",
453
+ example: "MIN(1, 3, 5, 9) => 1",
454
+ fn: function () {
455
+ var args = [];
456
+ for (var _i = 0; _i < arguments.length; _i++) {
457
+ args[_i] = arguments[_i];
458
+ }
459
+ return Math.min.apply(Math, handleFlattenArgs(args).map(exports.handleToFormulaNumber));
460
+ },
461
+ },
462
+ {
463
+ name: "MINUS",
464
+ category: "Numeric",
465
+ description: "Subtracts the second number from the first.",
466
+ example: "MINUS(5, 3) => 2",
467
+ fn: function (a, b) { return (0, exports.handleToFormulaNumber)(a) - (0, exports.handleToFormulaNumber)(b); },
468
+ },
469
+ {
470
+ name: "MOD",
471
+ category: "Numeric",
472
+ description: "Returns the remainder of a division.",
473
+ example: "MOD(10, 3) => 1",
474
+ fn: function (a, b) { return (0, exports.handleToFormulaNumber)(a) % (0, exports.handleToFormulaNumber)(b); },
475
+ },
476
+ {
477
+ name: "MULTIPLY",
478
+ category: "Numeric",
479
+ description: "Multiplies the given numbers.",
480
+ example: "MULTIPLY(5, 2) => 10",
481
+ fn: function () {
482
+ var args = [];
483
+ for (var _i = 0; _i < arguments.length; _i++) {
484
+ args[_i] = arguments[_i];
485
+ }
486
+ return handleFlattenArgs(args)
487
+ .map(exports.handleToFormulaNumber)
488
+ .reduce(function (a, b) { return a * b; }, 1);
489
+ },
490
+ },
491
+ {
492
+ name: "POWER",
493
+ category: "Numeric",
494
+ description: "Raises a number to a power.",
495
+ example: "POWER(2, 3) => 8",
496
+ fn: function (a, b) { return Math.pow((0, exports.handleToFormulaNumber)(a), (0, exports.handleToFormulaNumber)(b)); },
497
+ },
498
+ {
499
+ name: "ROUND",
500
+ category: "Numeric",
501
+ description: "Rounds a number to a number of digits.",
502
+ example: "ROUND(1.123456, 2) => 1.12",
503
+ fn: function (value, digits) {
504
+ if (digits === void 0) { digits = 0; }
505
+ return handleRoundTo((0, exports.handleToFormulaNumber)(value), (0, exports.handleToFormulaNumber)(digits));
506
+ },
507
+ },
508
+ {
509
+ name: "ROUNDUP",
510
+ category: "Numeric",
511
+ description: "Always rounds a number up, away from zero.",
512
+ example: "ROUNDUP(1.1, 0) => 2",
513
+ fn: function (value, digits) {
514
+ if (digits === void 0) { digits = 0; }
515
+ var factor = Math.pow(10, (0, exports.handleToFormulaNumber)(digits));
516
+ var numberValue = (0, exports.handleToFormulaNumber)(value);
517
+ return ((Math.sign(numberValue) * Math.ceil(Math.abs(numberValue) * factor)) /
518
+ factor);
519
+ },
520
+ },
521
+ {
522
+ name: "ROUNDDOWN",
523
+ category: "Numeric",
524
+ description: "Always rounds a number down, towards zero.",
525
+ example: "ROUNDDOWN(1.9, 0) => 1",
526
+ fn: function (value, digits) {
527
+ if (digits === void 0) { digits = 0; }
528
+ var factor = Math.pow(10, (0, exports.handleToFormulaNumber)(digits));
529
+ var numberValue = (0, exports.handleToFormulaNumber)(value);
530
+ return ((Math.sign(numberValue) * Math.floor(Math.abs(numberValue) * factor)) /
531
+ factor);
532
+ },
533
+ },
534
+ {
535
+ name: "SQRT",
536
+ category: "Numeric",
537
+ description: "Returns the square root of a positive number.",
538
+ example: "SQRT(9) => 3",
539
+ fn: function (value) { return Math.sqrt((0, exports.handleToFormulaNumber)(value)); },
540
+ },
541
+ {
542
+ name: "SUM",
543
+ category: "Numeric",
544
+ description: "Adds up the given numbers.",
545
+ example: "SUM(2, 3, 8) => 13",
546
+ fn: function () {
547
+ var args = [];
548
+ for (var _i = 0; _i < arguments.length; _i++) {
549
+ args[_i] = arguments[_i];
550
+ }
551
+ return handleFlattenArgs(args)
552
+ .map(exports.handleToFormulaNumber)
553
+ .reduce(function (a, b) { return a + b; }, 0);
554
+ },
555
+ },
556
+ // INFO: Date
557
+ {
558
+ name: "ADD_DAYS",
559
+ category: "Date",
560
+ description: "Adds days to a date and returns the new date.",
561
+ example: 'ADD_DAYS("2019-01-20", 5) => 2019-01-25',
562
+ fn: function (date, days) {
563
+ var parsed = handleToFormulaDate(date);
564
+ return parsed
565
+ ? handleFormatFormulaDate(parsed.add((0, exports.handleToFormulaNumber)(days), "day"))
566
+ : "";
567
+ },
568
+ },
569
+ {
570
+ name: "DATE",
571
+ category: "Date",
572
+ description: "Builds a date from a year, month and day.",
573
+ example: "DATE(2018, 5, 30) => 2018-05-30",
574
+ fn: function (year, month, day) {
575
+ return handleFormatFormulaDate(dayjs(new Date((0, exports.handleToFormulaNumber)(year), (0, exports.handleToFormulaNumber)(month) - 1, (0, exports.handleToFormulaNumber)(day))));
576
+ },
577
+ },
578
+ {
579
+ name: "DATEVALUE",
580
+ category: "Date",
581
+ description: "Converts text that represents a date into a date.",
582
+ example: 'DATEVALUE("2025-11-12") => 2025-11-12',
583
+ fn: function (text) { return handleFormatFormulaDate(handleToFormulaDate(text)); },
584
+ },
585
+ {
586
+ name: "DAY",
587
+ category: "Date",
588
+ description: "Returns the day of the month of a date.",
589
+ example: "DAY({Created At}) => 31",
590
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.date()) !== null && _b !== void 0 ? _b : ""; },
591
+ },
592
+ {
593
+ name: "DAYS",
594
+ category: "Date",
595
+ description: "Returns the number of days between two dates.",
596
+ example: "DAYS({End Date}, {Start Date}) => 14",
597
+ fn: function (to, from) {
598
+ var end = handleToFormulaDate(to);
599
+ var start = handleToFormulaDate(from);
600
+ if (!end || !start)
601
+ return "";
602
+ return end.startOf("day").diff(start.startOf("day"), "day");
603
+ },
604
+ },
605
+ {
606
+ name: "FORMAT_DATE",
607
+ category: "Date",
608
+ description: 'Formats a date. The default format is "MMM D, YYYY".',
609
+ example: 'FORMAT_DATE(TODAY(), "YYYY-MM-DD") => 2020-02-16',
610
+ fn: function (date, pattern) {
611
+ var _a, _b;
612
+ if (pattern === void 0) { pattern = "MMM D, YYYY"; }
613
+ return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.format((0, exports.handleToFormulaText)(pattern))) !== null && _b !== void 0 ? _b : "";
614
+ },
615
+ },
616
+ {
617
+ name: "HOUR",
618
+ category: "Date",
619
+ description: "Returns the hour of a date, from 0 to 23.",
620
+ example: "HOUR(NOW()) => 23",
621
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.hour()) !== null && _b !== void 0 ? _b : ""; },
622
+ },
623
+ {
624
+ name: "HOURS_DIFF",
625
+ category: "Date",
626
+ description: "Returns the difference between two times as HH:mm.",
627
+ example: 'HOURS_DIFF("23:00", "20:00") => 03:00',
628
+ fn: function (to, from) {
629
+ var diff = handleParseHours(to) - handleParseHours(from);
630
+ if (isNaN(diff))
631
+ return "";
632
+ var sign = diff < 0 ? "-" : "";
633
+ var absolute = Math.abs(diff);
634
+ var hours = String(Math.floor(absolute / 60)).padStart(2, "0");
635
+ var minutes = String(absolute % 60).padStart(2, "0");
636
+ return "".concat(sign).concat(hours, ":").concat(minutes);
637
+ },
638
+ },
639
+ {
640
+ name: "ISOWEEKNUM",
641
+ category: "Date",
642
+ description: "Returns the ISO week number of a date.",
643
+ example: "ISOWEEKNUM({Created At}) => 42",
644
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.isoWeek()) !== null && _b !== void 0 ? _b : ""; },
645
+ },
646
+ {
647
+ name: "MINUTE",
648
+ category: "Date",
649
+ description: "Returns the minute of a date, from 0 to 59.",
650
+ example: "MINUTE(NOW()) => 10",
651
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.minute()) !== null && _b !== void 0 ? _b : ""; },
652
+ },
653
+ {
654
+ name: "MONTH",
655
+ category: "Date",
656
+ description: "Returns the month of a date, from 1 to 12.",
657
+ example: "MONTH({Created At}) => 7",
658
+ fn: function (date) {
659
+ var parsed = handleToFormulaDate(date);
660
+ return parsed ? parsed.month() + 1 : "";
661
+ },
662
+ },
663
+ {
664
+ name: "NOW",
665
+ category: "Date",
666
+ description: "Returns the current date and time.",
667
+ example: "NOW() => 2020-02-16 23:10",
668
+ fn: function () { return dayjs().format("YYYY-MM-DD HH:mm"); },
669
+ },
670
+ {
671
+ name: "SECOND",
672
+ category: "Date",
673
+ description: "Returns the second of a date, from 0 to 59.",
674
+ example: "SECOND(NOW()) => 1",
675
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.second()) !== null && _b !== void 0 ? _b : ""; },
676
+ },
677
+ {
678
+ name: "SUBTRACT_DAYS",
679
+ category: "Date",
680
+ description: "Subtracts days from a date and returns the new date.",
681
+ example: 'SUBTRACT_DAYS("2019-01-20", 5) => 2019-01-15',
682
+ fn: function (date, days) {
683
+ var parsed = handleToFormulaDate(date);
684
+ return parsed
685
+ ? handleFormatFormulaDate(parsed.subtract((0, exports.handleToFormulaNumber)(days), "day"))
686
+ : "";
687
+ },
688
+ },
689
+ {
690
+ name: "SUBTRACT_MINUTES",
691
+ category: "Date",
692
+ description: "Subtracts minutes from a date and returns the new date.",
693
+ example: "SUBTRACT_MINUTES({Date}, 30)",
694
+ fn: function (date, minutes) {
695
+ var parsed = handleToFormulaDate(date);
696
+ return parsed
697
+ ? parsed
698
+ .subtract((0, exports.handleToFormulaNumber)(minutes), "minute")
699
+ .format("YYYY-MM-DD HH:mm")
700
+ : "";
701
+ },
702
+ },
703
+ {
704
+ name: "TODAY",
705
+ category: "Date",
706
+ description: "Returns the current date.",
707
+ example: "TODAY() => 2018-07-05",
708
+ fn: function () { return dayjs().format("YYYY-MM-DD"); },
709
+ },
710
+ {
711
+ name: "WEEKNUM",
712
+ category: "Date",
713
+ description: "Returns the week number of a date within its year.",
714
+ example: "WEEKNUM({Created At}) => 42",
715
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.week()) !== null && _b !== void 0 ? _b : ""; },
716
+ },
717
+ {
718
+ name: "WORKDAY",
719
+ category: "Date",
720
+ description: "Adds working days (Monday to Friday) to a date.",
721
+ example: "WORKDAY({Date}, 20)",
722
+ fn: handleAddWorkdays,
723
+ },
724
+ {
725
+ name: "WORKDAYS",
726
+ category: "Date",
727
+ description: "Returns the number of working days between two dates.",
728
+ example: "WORKDAYS({To Date}, {From Date}) => 10",
729
+ fn: handleCountWorkdays,
730
+ },
731
+ {
732
+ name: "YEAR",
733
+ category: "Date",
734
+ description: "Returns the year of a date.",
735
+ example: "YEAR({Created At}) => 2018",
736
+ fn: function (date) { var _a, _b; return (_b = (_a = handleToFormulaDate(date)) === null || _a === void 0 ? void 0 : _a.year()) !== null && _b !== void 0 ? _b : ""; },
737
+ },
738
+ // INFO: Constants
739
+ {
740
+ name: "PI",
741
+ category: "Constants",
742
+ description: "The value of PI (3.14159).",
743
+ example: "PI() => 3.14159",
744
+ constant: true,
745
+ },
746
+ {
747
+ name: "TRUE",
748
+ category: "Constants",
749
+ description: "The logical true value.",
750
+ example: 'IF(3 > 5 = TRUE, "a", "b") => b',
751
+ constant: true,
752
+ },
753
+ {
754
+ name: "FALSE",
755
+ category: "Constants",
756
+ description: "The logical false value.",
757
+ example: 'IF(3 > 5 = FALSE, "a", "b") => a',
758
+ constant: true,
759
+ },
760
+ ];
761
+ exports.FORMULA_CONSTANTS = {
762
+ PI: Math.PI,
763
+ TRUE: true,
764
+ FALSE: false,
765
+ };
766
+ exports.FORMULA_FUNCTION_CATEGORIES = [
767
+ "Text",
768
+ "Logical",
769
+ "Numeric",
770
+ "Date",
771
+ "Constants",
772
+ ];
773
+ //# sourceMappingURL=functions.js.map