1import htm from "htm";
2
3export function h(
4 tag: string | ((props: unknown) => string),
5 props: Record<string, unknown>,
6 ...children: unknown[]
7): string {
8 if (typeof tag === "function") return tag({ ...props, children });
9
10 let attrs = "";
11 if (props) {
12 for (const k in props) {
13 if (props[k] != null && k !== "children") attrs += ` ${k}="${props[k]}"`;
14 }
15 }
16
17 const content = children.flat().join("");
18 return `<${tag}${attrs}>${content}</${tag}>`;
19}
20
21const html = htm.bind(h) as unknown as (
22 strings: TemplateStringsArray,
23 ...values: unknown[]
24) => string;
25export { html };