UNPKG

hxb

Version:

这是一个处理时间和特殊字符的包

35 lines (32 loc) 629 B
function htmlEscape(htmlStr) { return htmlStr.replace(/<|>|"|&/g, match => { switch (match) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp' } }) } function htmlUnEscape(str) { return str.replace(/&lt;|&gt;|&amp;|&quot;/g, match => { switch (match) { case '&lt;': return '<' case '&gt;': return '>' case '&amp;': return '&' case '&quot': return '"' } }) } module.exports = { htmlEscape, htmlUnEscape }