export async function formulaEndpoint(req) {
if (req.method !== "GET") {
return new Response("Method Not Allowed", { status: 405 });
}
const params = new URLSearchParams(req.url.split("?")[1]);
const method = params.get("method");
params.delete("method");
const vars = {};
params.forEach((value, key) => {
if (value) {
vars[key] = value;
}
});
if (Object.keys(vars).length === 0) {
return new Response("No parameters provided", { status: 400 });
}
let result = null;
const functions = {
"add": ["infinite", "number"],
"subtract": ["infinite", "number"],
"multiply": ["infinite", "number"],
"mod": [2, "number"],
"pow": [2, "number"],
"divide": [2, "number"],
"equal": [2, "any"],
"!=": [2, "any"],
">": [2, "number"],
"<": [2, "number"],
">=": [2, "number"],
"<=": [2, "number"],
"and": [2, "boolean"],
"or": [2, "boolean"],
"not": [1, "boolean"],
"xor": [2, "boolean"],
"nand": [2, "boolean"],
"nor": [2, "boolean"],
"xnor": [2, "boolean"],
"true": [3, "string"],
"false": [3, "string"],
"if_empty": [1, "any"],
"length": [1, "string"],
"contains": [2, "string"],
"test": [2, "string"],
"match": [2, "string"],
"replace": [3, "string"],
"replaceAll": [3, "string"],
"lowercase": [1, "string"],
"uppercase": [1, "string"],
"repeat": [2, "string", "number"],
"strip_formatting": [1, "string"],
"min": ["infinite", "number"],
"max": ["infinite", "number"],
"absolute": [1, "number"],
"round": [1, "number"],
"ceiling": [1, "number"],
"floor": [1, "number"],
"squareroot": [1, "number"],
"cuberoot": [1, "number"],
"exponent": [2, "number"],
"ln": [1, "number"],
"log10": [1, "number"],
"log2": [1, "number"],
"now": [1, "number"],
"minute": [1, "date"],
"hour": [1, "date"],
"day": [1, "date"],
"date": [1, "date"],
"week": [1, "date"],
"month": [1, "date"],
"year": [1, "date"],
"dateAdd": [3, "date", "number", "string"],
"dateSubtract": [3, "date", "number", "string"],
"dateBetween": [3, "date", "date", "string"],
"timestamp": [1, "date"],
"fromTimestamp": [1, "number"],
"formatDate": [2, "string"],
"parseDate": [2, "string"],