UNPKG

date5_tools

Version:

提供格式化时间、HTMLEscape相关的功能

37 lines (34 loc) 852 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 htmlunEscape(htmlstr){ return htmlstr.replace(/&lt;|&gt;|&quot;|&amp;/g, marth=>{ switch(marth){ case '&lt;': return '<'; case '&gt;': return '>'; case '&quot;': return '"'; case '&amp;': return '&'; } }) } module.exports={ htmlEscape, htmlunEscape }