23 lines
485 B
JavaScript
23 lines
485 B
JavaScript
// @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;
|
|
}
|