UNPKG

tyler-tools

Version:

这是一个字符转义工具

36 lines (34 loc) 823 B
function htmlEscape(dateStr){ var regStr = /<|>|&|"/g; return dateStr.replace(regStr, (match)=>{ switch(match){ case "<": return "&lt;" case ">": return "&gt;" case "&": return "&amp;" case '"': return "&quot;" } }) } function htmlUnescape(dateStr){ var regStr = /&lt;|&gt;|&amp;|&quot;/g; return dateStr.replace(regStr, (match)=>{ switch(match){ case "&lt;": return "<" case "&gt;": return ">" case "&amp;": return "&" case '&quot;': return '"' } }) } module.exports = { htmlEscape, htmlUnescape }