All files insert-style.js

100% Statements 15/15
100% Branches 17/17
100% Functions 3/3
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  5x 2x     3x       3x       14x 14x   14x 2x   12x     14x 10x 10x 2x   8x       14x    
export function getStyle(elm) {
  if ('styleSheet' in elm && 'cssText' in elm.styleSheet) {
    return elm.styleSheet.cssText; // IE8
  }
 
  return elm.textContent;
}
 
export function removeStyle(elm) {
  return elm.parentNode.removeChild(elm);
}
 
export default function (css, options = {}) {
  const elm = options.element || document.createElement('style');
  elm.setAttribute('type', 'text/css');
 
  if ('styleSheet' in elm && 'cssText' in elm.styleSheet) {
    elm.styleSheet.cssText = css; // IE8
  } else {
    elm.textContent = css;
  }
 
  if (!options.element) {
    const head = document.getElementsByTagName('head')[0];
    if (options && options.prepend) {
      head.insertBefore(elm, head.childNodes[0]);
    } else {
      head.appendChild(elm);
    }
  }
 
  return elm;
}