UNPKG

cn.edu.wust.qrz-nodejs-tools

Version:

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

37 lines (35 loc) 873 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 }