UNPKG

itheima-tools-zzn

Version:

这个包提供了格式化时间 HTMLEscape功能

36 lines (35 loc) 879 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 '&' } }) } // 向外暴露的成员 module.exports = { htmlEscape, htmlUnEscape }