UNPKG

huang-tools

Version:

提供格式化日期时间,转换及还原标签的功能

35 lines (34 loc) 765 B
// 定义转换为html字符串函数 function htmlEscape(htmlStr) { return htmlStr.replace(/>|<|"|&/g, function (match) { switch (match) { case '>': return '&gt;'; case '<': return '&lt;'; case '"': return '&quot;'; case '&': return '&amp'; } }); } // 定义将包含实体字符的字符串还原成html字符串的函数 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 };