Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mavoweb/vastly
Everything you need to support a custom formula language
https://github.com/mavoweb/vastly
ast expressions formulas parsing
Last synced: about 3 hours ago
JSON representation
Everything you need to support a custom formula language
- Host: GitHub
- URL: https://github.com/mavoweb/vastly
- Owner: mavoweb
- License: mit
- Created: 2023-10-26T20:21:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-14T22:18:32.000Z (8 months ago)
- Last Synced: 2024-04-14T07:56:05.026Z (7 months ago)
- Topics: ast, expressions, formulas, parsing
- Language: JavaScript
- Homepage: https://vastly.mavo.io
- Size: 169 KB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://ericsmekens.github.io/jsep/)).
These ASTs are a subset of ASTs produced by full-blown parsers like [Esprima](https://esprima.org/).Intended to be used in conjunction with [JSEP](https://ericsmekens.github.io/jsep/), but should work with any AST that conforms to the same structure.
Extracted from [Mavo](https://mavo.io).
## Features
- [x] Zero dependencies
- [x] Small footprint
- [x] Works in Node and the browser
- [x] Tree-shakeable## Usage
```sh
npm i vastly
```Then you can use it either by importing the whole library:
```js
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:
```js
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:
```js
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](https://vastly.mavo.io/docs/)
// Create global variable to facilitate experimentation
import * as vastly from "./src/index.js";
globalThis.vastly = vastly;