headers support

This commit is contained in:
Toshit Chawda 2024-01-09 20:03:43 -08:00
parent 59a26fd4d2
commit 81e78c89bc
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
5 changed files with 126 additions and 69 deletions

View file

@ -1,5 +1,7 @@
use wasm_bindgen::prelude::*;
use js_sys::{Array, Object};
pub fn set_panic_hook() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
@ -15,7 +17,6 @@ extern "C" {
pub fn console_error(s: &str);
}
macro_rules! debug {
($($t:tt)*) => (utils::console_debug(&format_args!($($t)*).to_string()))
}
@ -27,3 +28,20 @@ macro_rules! log {
macro_rules! error {
($($t:tt)*) => (utils::console_error(&format_args!($($t)*).to_string()))
}
pub fn entries_of_object(obj: &Object) -> Vec<Vec<String>> {
js_sys::Object::entries(obj)
.to_vec()
.iter()
.map(|val| {
Array::from(val)
.to_vec()
.iter()
.map(|val| {
val.as_string()
.expect_throw("failed to get string from object entry")
})
.collect()
})
.collect::<Vec<Vec<_>>>()
}