nodes/packages/plantarium/src/helpers.rs

30 lines
728 B
Rust
Raw Normal View History

2024-04-04 19:17:27 +02:00
use wasm_bindgen::prelude::*;
pub fn unwrap_int(val: JsValue) -> u8 {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_f64().unwrap() as u8;
}
pub fn unwrap_float(val: JsValue) -> f64 {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_f64().unwrap();
}
2024-04-04 21:04:51 +02:00
pub fn unwrap_string(val: JsValue) -> String {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_string().unwrap();
}
pub fn evaluate_parameter(val: JsValue) -> String {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_string().unwrap();
}