UNPKG

shijian-tools

Version:

提供时间格式化

39 lines (35 loc) 890 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 '&' } }) } // 向外共享转换html函数 module.exports = { htmlEscape, htmlUnEscape }