lesama-tools
Version:
管理时间格式化、HTMLEscape功能
36 lines (34 loc) • 727 B
JavaScript
// html转义
const htmlEscape = (str) => {
// 匹配< > " & , |表示或,g表示全局匹配, match表示匹配到的内容
return str.replace(/<|>|"|&/g, match =>{
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
const htmlUnEscape = (str) => {
return str.replace(/<|>|"|&/g, match => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}