import { HTML_ESCAPES } from './consts';

/**
 * 转义HTML字符
 * @param {string} html
 *
 * escapeHtml('<a href="">点我</a>'); // => '&lt;a href=&quot;&quot;&gt;点我&lt;/a&gt;'
 */
function escapeHtml(html) {
  return html.replace(/[&<>"'``]/g, function (tag) {
    return HTML_ESCAPES[tag] || tag;
  });
}

export default escapeHtml;
