1.2.1 • Published 3 years ago

paraformula v1.2.1

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
3 years ago

paraformula

An Excel formula language parser, written in Typescript

A blurry picture of the Excel logo flying over some trees.

Availability

Paraformula is available via NPM:

$ npm install --save paraformula

Paraformula has one dependency, the Parsecco combinator library. Parsecco itself has no dependencies.

Usage

Paraformula allows you to parse Excel formula expressions into an AST.

import { Paraformula } from "paraformula";

const ast = Paraformula.parse('=COUNTIFS(C5:C14,"red",D5:D14,"tx")');
console.log(JSON.stringify(ast));

parse returns an AST on success, otherwise it throws an exception. A complete, runnable Node version of the above program is in the examples/simple directory. To run it:

$ cd example/simple
$ npm install
$ npm run build
$ npm run start

which prints something like:

{
  "tag": "FunctionApplication",
  "path": "",
  "workbookName": "",
  "worksheetName": "",
  "name": "COUNTIFS",
  "args":
    [
      {
        "tag": "ReferenceRange",
        "path": "",
        "workbookName": "",
        "worksheetName": "",
        "rng":
          {
            "tag": "Range",
            "regions":
              [
                [
                  {
                    "tag": "Address",
                    "row": 5,
                    "column": 3,
                    "rowMode": { "tag": "RelativeAddress" },
                    "colMode": { "tag": "RelativeAddress" },
                    "env":
                      {
                        "tag": "Env",
                        "path": "",
                        "workbookName": "",
                        "worksheetName": "",
                      },
                  },
                  {
                    "tag": "Address",
                    "row": 14,
                    "column": 3,
                    "rowMode": { "tag": "RelativeAddress" },
                    "colMode": { "tag": "RelativeAddress" },
                    "env":
                      {
                        "tag": "Env",
                        "path": "",
                        "workbookName": "",
                        "worksheetName": "",
                      },
                  },
                ],
              ],
          },
      },
      {
        "tag": "StringLiteral",
        "path": "",
        "workbookName": "",
        "worksheetName": "",
        "value": "red",
      },
      {
        "tag": "ReferenceRange",
        "path": "",
        "workbookName": "",
        "worksheetName": "",
        "rng":
          {
            "tag": "Range",
            "regions":
              [
                [
                  {
                    "tag": "Address",
                    "row": 5,
                    "column": 4,
                    "rowMode": { "tag": "RelativeAddress" },
                    "colMode": { "tag": "RelativeAddress" },
                    "env":
                      {
                        "tag": "Env",
                        "path": "",
                        "workbookName": "",
                        "worksheetName": "",
                      },
                  },
                  {
                    "tag": "Address",
                    "row": 14,
                    "column": 4,
                    "rowMode": { "tag": "RelativeAddress" },
                    "colMode": { "tag": "RelativeAddress" },
                    "env":
                      {
                        "tag": "Env",
                        "path": "",
                        "workbookName": "",
                        "worksheetName": "",
                      },
                  },
                ],
              ],
          },
      },
      {
        "tag": "StringLiteral",
        "path": "",
        "workbookName": "",
        "worksheetName": "",
        "value": "tx",
      },
    ],
  "arity": { "num": 2 },
}

Partial Parses (coming soon)

Paraformula has the ability to parse a partial Excel expression.

Reference Extraction (coming soon)

Paraformula can also extract all of a formula's references, either addresses or ranges.

More Documentation (coming soon)

Stay tuned.

1.2.1

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago