import createDOMPurify from 'dompurify';

var purifier;
var escapeHtml = function escapeHtml(html) {
  return html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
};
var getPurifier = function getPurifier() {
  if (typeof window === 'undefined') {
    return undefined;
  }
  if (!purifier) {
    purifier = createDOMPurify(window);
  }
  return purifier;
};
var sanitizeHtml = function sanitizeHtml(html) {
  var domPurify = getPurifier();
  if (!domPurify) {
    return escapeHtml(html);
  }
  return domPurify.sanitize(html);
};

export { sanitizeHtml };
