#![forbid(unsafe_code)]
use wasm_bindgen::prelude::*;
mod core;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Document {
inner: oxml::Document,
}
#[wasm_bindgen]
pub fn parse(source: &str) -> Result<Document, JsError> {
core::parse(source)
.map(|inner| Document { inner })
.map_err(|e| JsError::new(&e))
}
#[wasm_bindgen]
impl Document {
#[wasm_bindgen(getter)]
#[must_use]
pub fn size(&self) -> usize {
self.inner.len()
}
#[wasm_bindgen(js_name = rootName)]
#[must_use]
pub fn root_name(&self) -> Option<String> {
core::root_name(&self.inner)
}
#[wasm_bindgen(js_name = queryText)]
pub fn query_text(&self, expression: &str) -> Result<Vec<String>, JsError> {
core::query_text(&self.inner, expression).map_err(|e| JsError::new(&e))
}
#[wasm_bindgen(js_name = queryValue)]
pub fn query_value(&self, expression: &str) -> Result<String, JsError> {
core::query_value(&self.inner, expression).map_err(|e| JsError::new(&e))
}
#[wasm_bindgen(js_name = queryCount)]
pub fn query_count(&self, expression: &str) -> Result<usize, JsError> {
core::query_count(&self.inner, expression).map_err(|e| JsError::new(&e))
}
}
#[wasm_bindgen(js_name = isWellFormed)]
#[must_use]
pub fn is_well_formed(source: &str) -> bool {
core::is_well_formed(source)
}