16 releases

0.2.0 Sep 13, 2024
0.1.15 Sep 5, 2023
0.1.14 Aug 26, 2023
0.1.13 Jul 3, 2023
0.1.7 Jun 27, 2023

#1540 in Web programming

Download history 43/week @ 2024-07-06 92/week @ 2024-09-07 79/week @ 2024-09-14 53/week @ 2024-09-21 9/week @ 2024-09-28

233 downloads per month

MIT license

41KB
474 lines

Exprimo

CAUTION: Beware of Sneaky Bugs in the Early Project Stages! There will be bug, probably alot at first :D

Exprimo is a JavaScript evaluator written in Rust, inspired by the functionality of angular-expressions. Designed to be simple and blazingly fast.

Description

Exprimo parses and evaluates JavaScript expressions efficiently and securely. It utilizes the power of Rust and its excellent memory safety guarantees to provide a reliable and fast JavaScript expression evaluator.

Installation

Before you can use Exprimo, you need to have Rust installed on your system. If you don't have it installed, you can download Rust from the official website here.

Once Rust is installed, you can install Exprimo by running:

cargo add exprimo

Trace logging to console can be added to the package, it is by default disabled as probably don't need it unless working on it, or need to debug AST error if required.

This will install Scribe Rust and will need LOG_LEVEL=TRACE in environment variables for logs to output.

exprimo = { version = "*", features = ["logging"]

Usage

First, you need to import Exprimo and create an instance of Evaluator:

use exprimo::Evaluator;
use std::collections::HashMap;

let mut context = HashMap::new();
context.insert("a".to_string(), serde_json::Value::Bool(true));        
context.insert("b".to_string(), serde_json::Value::Bool(false));

let evaluator = Evaluator::new(context);

Then, you can evaluate JavaScript expressions:

let result = evaluator.evaluate("a && b").unwrap();
println!("The result is {}", result);

//--outputs
// >The result is false

Examples

Running examples

LOG_LEVEL=TRACE cargo run --features "logging" --example basic

Contributing

Contributions to Exprimo are welcome! Please submit a pull request on GitHub.

License

Exprimo is licensed under the MIT license. Please see the LICENSE file in the GitHub repository for more information.

Dependencies

~5–13MB
~153K SLoC