UNPKG

@plexis/escape-html

Version:

Takes the input text and converts HTML special characters to their entity equivalents.

28 lines (25 loc) 669 B
"use strict"; exports.__esModule = true; exports["default"] = void 0; /** * @description Takes the input text and converts HTML special characters to their entity equivalents. * @param {String} text * @example * escapeHTML('ABCD'); // returns 'ABCD' * escapeHtml('<3') // returns '&lt;3' * escapeHtml('<p>This is cool</p>') // returns '&lt;p&gt;This is cool&lt;/p&gt;' */ var escapeHTML = function escapeHTML(text) { var map = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#039;' }; return text.replace(/[&<>"']/g, function (m) { return map[m]; }); }; var _default = escapeHTML; exports["default"] = _default;