UNPKG

shiyi-format-toole

Version:

格式化日期时间、htmlEscape

28 lines (26 loc) 649 B
// 转义 HTML 中的特殊字符函数 function htmlEscape(labelStr) { return labelStr.replace(/<|>|"|&/g, (suited) => { switch (suited) { case '<' : return '&tl' case '>' : return '&gl' case '"' : return '&quot' case '&' : return '&amp' } }) } // 还原 HTML 中的特殊字符 function htmlUnescape(labelStr) { return labelStr.replace(/&tl|&gl|&puot|&amp/g, (suited) => { switch (suited) { case '&tl' : return '<' case '&gl' : return '>' case '&puot' : return '"' case '&amp' : return '&' } }) } module.exports = { htmlEscape, htmlUnescape }