34 releases (18 breaking)

new 0.21.0 May 14, 2024
0.19.0 Mar 25, 2024
0.17.0 Dec 12, 2023
0.16.1 Nov 30, 2023
0.8.0 Jul 28, 2023

#213 in Date and time

Download history 113/week @ 2024-01-26 85/week @ 2024-02-02 126/week @ 2024-02-09 304/week @ 2024-02-16 143/week @ 2024-02-23 241/week @ 2024-03-01 275/week @ 2024-03-08 182/week @ 2024-03-15 191/week @ 2024-03-22 419/week @ 2024-03-29 298/week @ 2024-04-05 162/week @ 2024-04-12 207/week @ 2024-04-19 621/week @ 2024-04-26 124/week @ 2024-05-03 421/week @ 2024-05-10

1,408 downloads per month
Used in 2 crates

MIT license

170KB
4K 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

~4–5.5MB
~96K SLoC