Rule Parser for Rule Engine, generates Rule JSON in format required by Rule Engine.
X != Y && U == 6 && (O == 9 || U != 9)
{
"operator":"&&",
"criteria":[
{
"operator":"!=",
"param":"Y",
"value":"X"
},
{
"operator":"&&",
"criteria":[
{
"operator":"==",
"param":"6",
"value":"U"
},
{
"operator":"||",
"criteria":[
{
"operator":"==",
"param":"9",
"value":"O"
},
{
"operator":"!=",
"param":"9",
"value":"U"
}
]
}
]
}
]
}
This repo has 3 packages: Node Package Package for browsers Package to implement with Salesoforce - Lightning Web Component framework (LWC)
You'd find a working example for RuleParser in the example module with each package, here's the description. Refer main.js/RuleParser js modules which are at the core of this library.
for node
const formulaParser = require("./index.js");
for lwc:
import { loadParserDependencies, formulaParser} from 'c/ruleParser'
ruleJSON = formulaParser.parse(userInput);
//throws error if logic is incorrect
-use parantheses for logic separation for '&&' and '||' operators