Skip to content

Parses excel-formula-like string to JSON object tree and reverse parses to formula string.

License

Notifications You must be signed in to change notification settings

grjan7/xl-formula-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xl-formula-parser

Description

Parses excel-formula-like string to JSON object tree and reverse parses to formula string.

Installation

  npm i xl-formula-parser

APIs

parse(str)

  • str | datatype: string | required

Example

  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"
            ]
          }
        ]
      }
    ]
  }

stringify(obj)

  • obj | datatype: object | required

Example

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")))'

About

Parses excel-formula-like string to JSON object tree and reverse parses to formula string.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published