import ReactHtmlParser from 'react-html-parser';

function getParsedHtml(content: string) {
  return ReactHtmlParser(content) as any; 
}

function getStripHtml(html: string) {
  const tmp = document.createElement('DIV');
  tmp.innerHTML = html;
  return tmp.textContent || tmp.innerText || '';
}

function encodeHtmlEntities(text: string) {
  return text.split('').map((str) => str.replace('<', '&lt;').replace('>', '&gt;').replace('/', '&#x2F;')).join('');
}

// ios에서 \n 동작 안하는 이슈 대응
function replaceNewLineEscape(str: string) {
  return str.split(/(\n)/g).map(item => item.replace('\n', '<br>')).join('');
}

export default {
  getParsedHtml,
  getStripHtml,
  encodeHtmlEntities,
  replaceNewLineEscape,
};
