UNPKG

tools-zhaoshuaiqi

Version:

提供了格式化时间,HTML.Escape相关的功能

37 lines (34 loc) 837 B
//定义转移HTML字符的函数 function htmlEscape(str) { return str.replace(/<|>|"|&/g, (math) => { switch (math) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } //定义还原html字符串的函数 function htmlUnEscape(str) { return str.replace(/&lt;|&gt;|&quot;|&amp;/g,(math)=>{ switch (math) { case '&lt;': return '<'; case '&gt;': return '>'; case '&quot;': return '"'; case '&amp;': return '&'; } }) } module.exports = { htmlEscape, htmlUnEscape }