UNPKG

lh-tools

Version:

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

42 lines (36 loc) 906 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 }