UNPKG

achilles-tools

Version:

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

41 lines (35 loc) 905 B
// 定义转义 HTML 字符串的函数 function htmlEcape(htmlstr) { return htmlstr.replace(/<|>|"|&/g,(match) => { switch(match) { case '<': return '&lt;' case '>': return '&gt;' case'"': return '&quot;' case "&": return '&amp;' } }) } // 定义 还原 HTML 字符串函数 function htmlUnEcape(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 = { htmlEcape, htmlUnEcape }