UNPKG

jibamao-lxf

Version:

提供了格式化时间、htmlEscape、htmlUnescape三个函数

36 lines (34 loc) 771 B
// 封装转化标签特殊字符的函数 function htmlEscape(str) { return str.replace(/>|<|"|&/g, function (match) { switch (match) { case '>': return '&gt;'; case '<': return '&lt;'; case '"': return '&quot;'; case '&': return '&amp;'; } }); } // 封装函数将包含特定实体字符的字符串还原成标签字符串 function htmlUnescape(str) { return str.replace(/&gt;|&lt;|&quot;|&amp;/g, function (match) { switch (match) { case '&gt;': return '>'; case '&lt;': return '<'; case '&quot;': return '"'; case '&amp;': return '&'; } }); } module.exports = { htmlEscape, htmlUnescape }