39 releases (21 breaking)

new 0.24.2 Jul 17, 2024
0.23.0 Jul 4, 2024
0.19.0 Mar 25, 2024
0.17.0 Dec 12, 2023
0.8.0 Jul 28, 2023

#95 in Date and time

Download history 504/week @ 2024-04-01 229/week @ 2024-04-08 158/week @ 2024-04-15 197/week @ 2024-04-22 635/week @ 2024-04-29 147/week @ 2024-05-06 612/week @ 2024-05-13 613/week @ 2024-05-20 334/week @ 2024-05-27 259/week @ 2024-06-03 390/week @ 2024-06-10 563/week @ 2024-06-17 322/week @ 2024-06-24 340/week @ 2024-07-01 312/week @ 2024-07-08 689/week @ 2024-07-15

1,670 downloads per month
Used in 2 crates

MIT license

185KB
4.5K SLoC

A lightweight expression language designed for the evaluation of expressions in various contexts.

Zen Expression is a versatile single-threaded expression language designed for simplicity high-performance. It's primarily used for evaluating and processing JSON data offers key components that empower developers in creating responsive and non-blocking I/O applications Out of the box, it comes with amazing benefits:

  • 🚀 Blazingly fast - Perform millions of evaluations per second
  • 🧠 Intuitive syntax - Minimalistic and expressive syntax
  • 💼 Portable - Can be compiled for all standard architectures including WASM

For a full list of language references, visit documentation.

Example

Evaluate expression using isolate:

use zen_expression::{evaluate_expression, json};

fn main() {
    let context = json!({ "tax": { "percentage": 10 } });
    let tax_amount = evaluate_expression("50 * tax.percentage / 100", &context).unwrap();

    assert_eq!(tax_amount, json!(5));
}

High Performance

When evaluating a lot of expressions at once, you can use Isolate directly. Under the hood, Isolate will re-use allocated memory from previous evaluations, drastically improving performance.

use zen_expression::{Isolate, json};

fn main() {
    let context = json!({ "tax": { "percentage": 10 } });
    let mut isolate = Isolate::with_environment(&context);

    // Fast 🚀
    for _ in 0..1_000 {
        let tax_amount = isolate.run_standard("50 * tax.percentage / 100").unwrap();
        assert_eq!(tax_amount, json!(5));
    }
}

Feature flags

Name Description Default?
regex-deprecated Uses standard regex crate Yes
regex-lite Opts for usage of lightweight regex-lite crate. Useful for reducing build size, especially in WASM. No

Dependencies

~3–5MB
~85K SLoC