UNPKG

huiguang-tools

Version:

提供了格式化时间,HTMLEscape的功能

40 lines (38 loc) 870 B
// 定义转义HTML字符的函数 function htmlEscape(htmlstr) { return htmlstr.replace(/<|>|"|&/g,(match) =>{ switch(match) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } // 定义还原html字符串的函数 function htmlUnescape(htmlstr) { return htmlstr.replace(/&lt;|&gt;|&quot;|&amp;/g, (match)=>{ switch(match) { case '&lt;': return '<' case '&gt;': return '>' case '&quot;': return '"' case '&amp;': return '&' } }) } module.exports = { htmlEscape, htmlUnescape }