UNPKG

lesama-tools

Version:

管理时间格式化、HTMLEscape功能

36 lines (34 loc) 727 B
// html转义 const htmlEscape = (str) => { // 匹配< > " & , |表示或,g表示全局匹配, match表示匹配到的内容 return str.replace(/<|>|"|&/g, match =>{ switch (match) { case '<': return '&lt;' case '>': return '&gt;' case '"': return '&quot;' case '&': return '&amp;' } }) } const htmlUnEscape = (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 = { htmlEscape, htmlUnEscape }