1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const functionMap = {
// Basic Arithmetic Operations, with checks for type as numbers
"add": (a, b) => typeof a === "number" && typeof b === "number" ? a + b : null,
"subtract": (a, b) => typeof a === "number" && typeof b === "number" ? a - b : null,
"multiply": (a, b) => typeof a === "number" && typeof b === "number" ? a * b : null,
"mod": (a, b) => typeof a === "number" && typeof b === "number" ? a % b : null,
"pow": (a, b) => typeof a === "number" && typeof b === "number" ? Math.pow(a, b) : null,
"divide": (a, b) => (typeof a === "number" && typeof b === "number" && b !== 0) ? a / b : null,
// Comparison Operations, with checks for type as numbers
"equal": (a, b) => typeof a === "number" && typeof b === "number" ? a === b : null,
"notequal": (a, b) => typeof a === "number" && typeof b === "number" ? a !== b : null,
"greaterthan": (a, b) => typeof a === "number" && typeof b === "number" ? a > b : null,
"lessthan": (a, b) => typeof a === "number" && typeof b === "number" ? a < b : null,
"greaterthanorequal": (a, b) => typeof a === "number" && typeof b === "number" ? a >= b : null,
"lessthanorequal": (a, b) => typeof a === "number" && typeof b === "number" ? a <= b : null,
// Logical Operations, with checks
"and": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? b : c : null,
"or": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a || b : null,
"not": (a) => typeof a === "boolean" ? !a : null,
"xor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a !== b : null,
"nand": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? !(a && b) : null,
"nor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? !(a || b) : null,
"xnor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a === b : null,
// Boolean Values
// true receives a boolean, b is if true, c is if false
"true": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? b : c : null,
"false": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? c : b : null,
// String and Array Operations with checks
"contains": (a, b) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a.includes(b) : null,
"length": (a) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a.length : null,
"empty": (a) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a === "" : null,
"test": (a, b) => typeof a === "string" ? b.includes(a) : null,
"match": (a, b) => typeof a === "string" ? a.match(b) : null,
"replace": (a, b, c) => typeof a === "string" ? a.replace(b, c) : null,
"replaceAll": (a, b, c) => typeof a === "string" ? a.replaceAll(b, c) : null,
"lowercase": (a) => typeof a === "string" ? a.toLowerCase() : null,
"uppercase": (a) => typeof a === "string" ? a.toUpperCase() : null,
"repeat": (a, b) => typeof a === "string" ? a.repeat(b) : null,
"stripformatting": (a) => typeof a === "string" ? a.replace(/<[^>]*>/g, "") : null,
"min": (a) => Array.isArray(a) ? Math.min(...a) : null,
"max": (a) => Array.isArray(a) ? Math.max(...a) : null,
"absolute": (a) => typeof a === "number" ? Math.abs(a) : null,
"round": (a) => typeof a === "number" ? Math.round(a) : null,
"ceiling": (a) => typeof a === "number" ? Math.ceil(a) : null,
"floor": (a) => typeof a === "number" ? Math.floor(a) : null,
"squareroot": (a) => typeof a === "number" ? Math.sqrt(a) : null,
"cuberoot": (a) => typeof a === "number" ? Math.cbrt(a) : null,
"exponent": (a) => typeof a === "number" ? Math.exp(a) : null,
"ln": (a) => typeof a === "number" ? Math.log(a) : null,
"log10": (a) => typeof a === "number" ? Math.log10(a) : null,
"log2": (a) => typeof a === "number" ? Math.log2(a) : null,
"sin": (a) => typeof a === "number" ? Math.sin(a) : null,
"cos": (a) => typeof a === "number" ? Math.cos(a) : null,
"tan": (a) => typeof a === "number" ? Math.tan(a) : null,
"asin": (a) => typeof a === "number" ? Math.asin(a) : null,
"acos": (a) => typeof a === "number" ? Math.acos(a) : null,
"atan": (a) => typeof a === "number" ? Math.atan(a) : null,
"atan2": (a, b) => typeof a === "number" && typeof b === "number" ? Math.atan2(a, b) : null,
"degrees": (a) => typeof a === "number" ? a * 180 / Math.PI : null,
"radians": (a) => typeof a === "number" ? a * Math.PI / 180 : null,
"random": (a, b) => typeof a === "number" && typeof b === "number" ? Math.random() * (b - a) + a : null,
"randomint": (a, b) =>
typeof a === "number" && typeof b === "number" ? Math.floor(Math.random() * (b - a + 1)) + a : null,
"pi": () => Math.PI,
"e": () => Math.E,
// Date and Time Operations, with checks
"now": (a) => typeof a === "date" ? a.getTime() : null,
"minute": (a) => typeof a === "date" ? a.getMinutes() : null,
"hour": (a) => typeof a === "date" ? a.getHours() : null,
"day": (a) => typeof a === "date" ? a.getDay() : null,
"date": (a) => typeof a === "date" ? a.getDate() : null,
"week": (a) => typeof a === "date" ? a.getWeek() : null,
"month": (a) => typeof a === "date" ? a.getMonth() : null,
"year": (a) => typeof a === "date" ? a.getFullYear() : null,
"dateadd": (a, b) =>
typeof a === "date" && typeof b === "number" ? new Date(a.getTime() + b * 24 * 60 * 60 * 1000) : null,
"datesubtract": (a, b) =>
typeof a === "date" && typeof b === "number" ? new Date(a.getTime() - b * 24 * 60 * 60 * 1000) : null,
"datebetween": (startDate, endDate, unit) => {
if (!startDate || !endDate || typeof unit !== "string") {
return new Response("Invalid arguments for datebetween function");
}
let difference = Math.abs(endDate - startDate);
switch (unit) {
case "days":
return difference / (1000 * 60 * 60 * 24);
case "hours":
return difference / (1000 * 60 * 60);
case "minutes":
return difference / (1000 * 60);
case "seconds":
return difference / 1000;
case "milliseconds":
return difference;
case "weeks":
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
syncretizm-singleformulaendpoint.web.val.run
v169
December 10, 2023