@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
18 lines (17 loc) • 594 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createElement = void 0;
/**
* Creates a dom element of a given type, applies any supplied styles, and adds to the body element (if not disbaled)
*/
function createElement(type, styles, addToDom = true) {
const element = document.createElement(type);
if (styles) {
Object.entries(styles).forEach(([property, value]) => (element.style[property] = value));
}
if (addToDom) {
document.body.appendChild(element);
}
return element;
}
exports.createElement = createElement;