uwdata/vega-expression

Name: vega-expression

Owner: UW Interactive Data Lab

Description: Vega expression parser and code generator.

Forked from: vega/vega-expression

Created: 2016-07-08 16:02:06.0

Updated: 2016-11-26 05:57:25.0

Pushed: 2016-08-10 23:00:43.0

Homepage:

Size: 101

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

vega-expression

Vega expression parser and code generator.

Parses a limited subset of JavaScript expressions into an abstract syntax tree, and provides code generation utilities for generating eval'able output code. The parser recognizes basic JavaScript expressions, but does not allow assignment operators, new expressions, or control flow statements (for, while, switch, etc). The configurable code generator further limits the set of allowable function invocations and variable names. The goal is to provide simple, expressive and security-conscious expression evaluation.

API Usage

The top-level export includes three methods:

parse(input)

Parse the input JavaScript expression string and return the resulting abstract syntax tree in the ESTree (formerly Mozilla AST) format. The parser is based on a stripped-down version of the Esprima parser.

codegen(options)

Create a new output code generator configured according to the provided options. The resulting generator function accepts a parsed AST as input and returns eval'able JavaScript code as output. The output is an object hash with the properties code (the generated code as a string), fields (a hash of all properties referenced within the fieldvar scope), and globals (a hash of all properties referenced outside a provided whitelist).

The supported options include:


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.