use super::model::TsParam;
mod dts;
pub use dts::dts;
pub(crate) fn params_ts(params: &[TsParam]) -> String {
params
.iter()
.map(|p| format!("{}{}: {}", p.name, if p.optional { "?" } else { "" }, p.ts))
.collect::<Vec<_>>()
.join(", ")
}
pub(crate) fn apply_generic(iface: &str, generic: &str, s: &str) -> String {
if generic.is_empty() {
return s.to_string();
}
let full = format!("{iface}{generic}");
let collapsed = s.replace(&full, iface);
let mut out = String::new();
let mut word = String::new();
let flush = |out: &mut String, word: &mut String| {
out.push_str(if word == iface { &full } else { word });
word.clear();
};
for ch in collapsed.chars() {
if ch.is_alphanumeric() || ch == '_' {
word.push(ch);
} else {
flush(&mut out, &mut word);
out.push(ch);
}
}
flush(&mut out, &mut word);
out
}