UNPKG

wl-node-uils

Version:

是供了格式化时间,HTMLEscape的功能

38 lines (34 loc) 952 B
// 将html字符串转换成转义字符的字符串 function html(htmlStr){ return htmlStr.replace(/<|>|"|&/g,(match)=>{ switch (match){ case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } // 将包含转义字符的字符串转换为html字符串 function htmlEsc(str){ return str.replace(/&lt;|&gt;|&quot;|&amp;/g,(match)=>{ switch (match){ case '&lt;': return '<' case '&gt;': return '>' case '&quot;': return '"' case '&amp;': return '&' } }) } // 将两个函数对外暴露 module.exports={ html,htmlEsc }