UNPKG

blanco-tools

Version:

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

29 lines (26 loc) 689 B
//1.定义HTML转义方法 function htmlEscape(htmlStr) { return htmlStr.replace(/<|>|"|&/g, (match) => { switch (match) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } //2.定义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 '&' } }) } //3.向外暴露两个方法 module.exports={ htmlEscape,htmlUnEscape }