A typst plugin for unit-aware calculations
typst
1use std::str;
2use typst_wasm_protocol::wasm_export;
3
4#[wasm_export]
5fn fend_evaluate(query: &[u8]) -> Result<String, String> {
6 let input = str::from_utf8(query).map_err(|e| format!("UTF-8 error: {}", e))?;
7 let mut ctx = fend_core::Context::new();
8 let mut result = String::new();
9 match fend_core::evaluate(input, &mut ctx) {
10 Ok(res) => {
11 if !res.output_is_empty() {
12 result.push_str(res.get_main_result());
13 }
14 }
15 Err(msg) => {
16 return Err(format!("Error: {msg}"));
17 }
18 }
19 Ok(result.to_string())
20}