UNPKG

@studiometa/js-toolkit

Version:

A set of useful little bits of JavaScript to boost your project! 🚀

22 lines (21 loc) • 672 B
import { isArray, isString } from "../is.js"; import { dashCase } from "../string/changeCase.js"; function createElement(tag, attributes = {}, children = null) { const el = document.createElement(tag ?? "div"); if (children === null && (isArray(attributes) || isString(attributes) || attributes instanceof Node)) { children = attributes; attributes = {}; } for (const [name, value] of Object.entries(attributes)) { el.setAttribute(dashCase(name), value); } if (children) { children = isArray(children) ? children : [children]; el.append(...children); } return el; } export { createElement }; //# sourceMappingURL=createElement.js.map