1.1.0 • Published 9 years ago

formula-compiler v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Formula Compiler

circleci

Compile spreadsheet formulas to JavaScript functions.

Install

npm install formula-compiler

Usage

First you must require the compiler.

var compiler = require('formula-compiler');

Then you need a data object and a context that supports a get function.

var data = { SuccessText: "Works!" };
var context = { get: function(key) { return data[key]; } };

Use the compiler to generate a function.

var myFunction = compiler.compile('IF(TRUE, SuccessText, "Broken")');

Run the function passing back in the requirements.

var result = myFunction(context, myFunction.requires)

Properties

The function comes with metadata.

The identifier:

myFunction.id

The abstract syntax tree:

myFunction.ast

The list of required libraries:

myFunction.requires

The list of precedents:

myFunction.precedents