Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { h } from "https://esm.town/v/tmcw/h";
export function t(tag: string, args: any = {}, children: any[] = []) {
const func = (...argsOrChildren: any) => {
if (Array.isArray(argsOrChildren[0]))
return func(...argsOrChildren[0], ...argsOrChildren.slice(1));
const args2 = { ...args },
ch2 = [...children];
for (const c of argsOrChildren) {
if (typeof c === "string") ch2.push(c);
else if (typeof c.html === "string") ch2.push(c.html);
else for (const k in c) args2[k] = c[k];
}
return t(tag, args2, ch2);
};
const html = h(tag, args, ...children).html;
return Object.assign(func, {
html,
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023