ustyler
Version:
A minimalistic CSS style injector
18 lines (17 loc) • 714 B
JavaScript
;
/**
* Create, append, and return, a style node with the passed CSS content.
* @param {string|string[]} template the CSS text or a template literal array.
* @param {...any} values the template literal interpolations.
* @return {HTMLStyleElement} the node appended as head last child.
*/
function ustyler(template) {
const text = typeof template == 'string' ? [template] : [template[0]];
for (let i = 1, {length} = arguments; i < length; i++)
text.push(arguments[i], template[i]);
const style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(text.join('')));
return document.head.appendChild(style);
}
module.exports = ustyler;