gloo_utils/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3pub mod errors;
4pub mod iter;
5pub mod format {
6    mod json;
7    #[cfg(feature = "serde")]
8    pub use json::JsValueSerdeExt;
9}
10use wasm_bindgen::UnwrapThrowExt;
11
12/// Convenience function to avoid repeating expect logic.
13pub fn window() -> web_sys::Window {
14    web_sys::window().expect_throw("Can't find the global Window")
15}
16
17/// Convenience function to access the head element.
18pub fn head() -> web_sys::HtmlHeadElement {
19    document()
20        .head()
21        .expect_throw("Can't find the head element")
22}
23
24/// Convenience function to access the web_sys DOM document.
25pub fn document() -> web_sys::Document {
26    window().document().expect_throw("Can't find document")
27}
28
29/// Convenience function to access `document.body`.
30pub fn body() -> web_sys::HtmlElement {
31    document().body().expect_throw("Can't find document body")
32}
33
34/// Convenience function to access `document.documentElement`.
35pub fn document_element() -> web_sys::Element {
36    document()
37        .document_element()
38        .expect_throw("Can't find document element")
39}
40
41/// Convenience function to access the web_sys history.
42pub fn history() -> web_sys::History {
43    window().history().expect_throw("Can't find history")
44}