UNPKG

lys-tools-a

Version:

提供了格式化事件,HTMLEscape 功能

33 lines (30 loc) 799 B
function htmlEscape(htmlStr) { return htmlStr.replace(/<|>|"|&/g, function (match) { if (match === '<') { return '&lt;' } else if (match === '>') { return '&gt;' } else if (match === '"') { return '&quot;' } else if(match === '&'){ return '&amp;' } }) } function htmlUnEscape(str) { return str.replace(/&lt;|&gt;|&quot;|&amp;/g, function (match) { if (match === '&lt;') { return '<' } else if (match === '&gt;') { return '>' } else if (match === '&quot;') { return '"' } else if (match === '&amp;') { return '&' } }) } module.exports = { htmlEscape, htmlUnEscape }