Parses excel-formula-like string to JSON object tree and reverse parses to formula string.
npm i xl-formula-parser
- str | datatype: string | required
const { parse } = require("xl-formula-parser");
const formula = `=OR(EQ(./path/personName, "John Doe"), NOT(EQ(personName, "John Smith")))`;
parse(formula);
parse(formula)
returns
{
formula: "OR",
args: [
{
formula: "EQ",
args: [
{
path: "./path/personName"
},
"John Doe"
]
},
{
formula: "NOT",
args: [
{
formula: "EQ",
args:[
{
variable: "personName"
},
"John Smith"
]
}
]
}
]
}
- obj | datatype: object | required
const { stringify } = require('xl-formula-parser');
const formulaTreeObject = {
formula: "OR",
args: [
{
formula: "EQ",
args: [
{
path: "./path/personName"
},
"John Doe"
]
},
{
formula: "NOT",
args: [
{
formula: "EQ",
args:[
{
variable: "personName"
},
"John Smith"
]
}
]
}
]
};
stringify(formulaTreeObject);
stringify(formulaTreeObject)
returns
'=OR(EQ(./path/personName, "John Doe"), NOT(EQ(personName, "John Smith")))'