1 export function el(tag: string, attrs: Record<string, string | null> = {}, children: (string | HTMLElement)[] = []): HTMLElement {
2 const el = document.createElement(tag);
3 const attrKeys = Object.keys(attrs);
4 for (const attr of attrKeys) {
5 if (attrs[attr] !== null) {
6 el.setAttribute(attr, attrs[attr] as string);
10 for (const child of children) {
11 if (typeof child === 'string') {
12 el.append(document.createTextNode(child));
21 export function htmlToDom(html: string): Document {
22 const parser = new DOMParser();
23 return parser.parseFromString(html, 'text/html');
26 export function formatSizeValue(size: number | string, defaultSuffix: string = 'px'): string {
27 if (typeof size === 'number' || /^-?\d+$/.test(size)) {
28 return `${size}${defaultSuffix}`;