UNPKG

zgdy_tols

Version:

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

38 lines (35 loc) 731 B
// 定义HTML的转义字符,把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(unStr){ return unStr.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 }