UNPKG

luck-tools

Version:

提供了格式时间,转义HTML中的特殊字符

34 lines 808 B
//定义HTML转义的函数 function htmlescape(htmlstr){ return htmlstr.replace(/<|>|"|&/g,math=>{ switch (math) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } //定义还原HTML的函数 function hyhtml(htmlstr){ return htmlstr.replace(/&lt;|&gt;|&quot;|&amp;/g,math=>{ switch (math) { case '&lt;': return '<' case '&gt;': return '>' case '&quot;': return '"' case '&amp;': return '&' } }) } module.exports = { htmlescape, hyhtml }