formats.exposed/public/common/crel.js

23 lines
485 B
JavaScript
Raw Normal View History

// @ts-check
/**
* Create a DOM element. Inspired by [Crel][0].
* [0]: https://npm.im/crel
*
* @param {string} tagName
* @param {object} [attributes={}]
* @param {...(string | Node)} children
* @returns {HTMLElement}
*/
export default function crel(tagName, attributes = {}, ...children) {
const el = document.createElement(tagName);
for (const [key, value] of Object.entries(attributes)) {
el.setAttribute(key, value);
}
el.append(...children);
return el;
}