I'm building a logic expression parser. I really like the way mongoDB structures their logic statements. However, I'm thinking if this is the best structure to store and parse logic expressions.
const logicPayload = [
{ varA: { $eq: "meow" } },
{ $and: [{ varB: { $lt: "varD" } }, { varB: { $gte: "varC" } }] },
{ $not: [{ varB: { $eq: "varA" } }] }
];
Given the payload above, how can i design a function to parse the expression. varA, varB varC and varD will be resolve at runtime.
A dummy resolve function is below.
const resovleValue = varID => {
switch (varID) {
case "varA":
return "meow";
break;
case "varB":
return 100;
case "varC":
return 100;
case "varD":
return 983;
}
};
I'm trying to create the logic function below
/**
* This logic function must only return true or false
*/
const logicFunction = logicPayload => {};
Any guidance is much appreciated. thanks.