https://github.com/grjan7/xl-formula-parser
Parses excel-formula-like string to JSON object tree and reverse parses to formula string.
https://github.com/grjan7/xl-formula-parser
excel-like formula object-tree parse parser stringify
Last synced: 7 months ago
JSON representation
Parses excel-formula-like string to JSON object tree and reverse parses to formula string.
- Host: GitHub
- URL: https://github.com/grjan7/xl-formula-parser
- Owner: grjan7
- License: gpl-3.0
- Created: 2022-07-15T09:29:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-27T18:41:10.000Z (over 3 years ago)
- Last Synced: 2025-06-22T17:07:03.652Z (7 months ago)
- Topics: excel-like, formula, object-tree, parse, parser, stringify
- Language: JavaScript
- Homepage:
- Size: 118 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xl-formula-parser
## Description
Parses excel-formula-like string to JSON object tree and reverse parses to formula string.
## Installation
```sh
npm i xl-formula-parser
```
## APIs
### parse(str)
- **str** | datatype: string | required
#### Example
```js
const { parse } = require("xl-formula-parser");
const formula = `=OR(EQ(./path/personName, "John Doe"), NOT(EQ(personName, "John Smith")))`;
parse(formula);
```
`parse(formula)` returns
```js
{
formula: "OR",
args: [
{
formula: "EQ",
args: [
{
path: "./path/personName"
},
"John Doe"
]
},
{
formula: "NOT",
args: [
{
formula: "EQ",
args:[
{
variable: "personName"
},
"John Smith"
]
}
]
}
]
}
```
------
### stringify(obj)
- **obj** | datatype: object | required
#### Example
```js
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
```js
'=OR(EQ(./path/personName, "John Doe"), NOT(EQ(personName, "John Smith")))'
```