UNPKG

itheima-tools-zm

Version:

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

37 lines (34 loc) 886 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(str){ return str.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 }