const functionMap = {
"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,
"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,
"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,
"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,
"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,
"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":