pub fn origin_of(scheme: &str) -> String {
origin_on(scheme, cfg!(any(windows, target_os = "android")))
}
pub fn origin_on(scheme: &str, over_http: bool) -> String {
if over_http {
format!("http://{scheme}.localhost")
} else {
format!("{scheme}://localhost")
}
}
pub fn init_script(origin: &str) -> String {
let origin = serde_json::Value::String(origin.to_owned());
format!("globalThis.__COMPMD__ = Object.freeze({{ origin: {origin} }});")
}
pub fn is_scheme(name: &str) -> bool {
let mut bytes = name.bytes();
bytes.next().is_some_and(|first| first.is_ascii_lowercase())
&& bytes.all(|byte| {
byte.is_ascii_lowercase() || byte.is_ascii_digit() || matches!(byte, b'+' | b'-' | b'.')
})
}