sa-tasche / js-vastly

Everything you need to support a custom formula language

Home Page:https://vastly.mavo.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vᴀꜱᴛly

Everything you need to support a custom expression language in your application.

What is this?

vᴀꜱᴛly is a toolkit for handling expression ASTs (such as those produced by JSEP). These ASTs are a subset of ASTs produced by full-blown parsers like Esprima.

Intended to be used in conjunction with JSEP, but should work with any AST that conforms to the same structure.

Extracted from Mavo.

Features

  • Zero dependencies
  • Small footprint
  • Works in Node and the browser
  • Tree-shakeable

Usage

npm i vastly

Then you can use it either by importing the whole library:

import * as vastly from "vastly"; // or const vastly = require("vastly"); in CJS
import { parse } from "jsep";

const ast = parse("1 + x * y");
const result = vastly.evaluate(ast, {x: 2, y: 3});

or individual functions:

import { evaluate } from "vastly"; // or const { evaluate } = require("vastly"); in CJS
import { parse } from "jsep";

const ast = parse("1 + x * y");
const result = evaluate(ast, {x: 2, y: 3});

If you’re using vastly from a browser, without a bundler, fear not! You can just import from src directly:

import { evaluate } from "https://vastly.mavo.io/src/evaluate.js";
/* or */
import * as vastly from "https://vastly.mavo.io/src/index-fn.js";
/* or */
import { evaluate } from "https://vastly.mavo.io/dist/vastly.js";
/* or */
import * as vastly from "https://vastly.mavo.io/dist/vastly.js";

Full API reference

<script type=module> // Create global variable to facilitate experimentation import * as vastly from "./src/index.js"; globalThis.vastly = vastly; </script>

About

Everything you need to support a custom formula language

https://vastly.mavo.io

License:MIT License


Languages

Language:JavaScript 93.9%Language:Nunjucks 3.4%Language:HTML 2.5%Language:CSS 0.2%