3 releases
| 0.1.2 | Aug 1, 2025 |
|---|---|
| 0.1.1 | Jun 25, 2025 |
| 0.1.0 | May 18, 2025 |
#21 in #eval
200 downloads per month
45KB
1K
SLoC
oxide_eval
Description
oxide_eval is a simple Javascript Evaluator built on top of oxc
Example
use std::collections::HashMap;
use oxide_eval::{context::ContextEntry, Evaluator};
use serde_json::{Number, Value};
let mut context = HashMap::new();
// Map an variable
context.insert(
"a".to_string(),
ContextEntry::Variable(Value::Number(24.into())),
);
// Map a function
context.insert(
"mul".to_string(),
ContextEntry::Function(Box::new(|args| {
let a = args[0].as_f64().unwrap();
Value::Number(Number::from_f64(a * 10.0).unwrap())
})),
);
let evaluator = Evaluator::new(context);
let res = evaluator.evaluate("a + mul(2)").unwrap();
assert_eq!(res, 44);
Credits
Dependencies
~12MB
~207K SLoC