zhx-tools
Version:
提供了格式化时间, HTMLEscape的功能
36 lines (34 loc) • 818 B
JavaScript
//格式化字符串
function htmlEscape(htmlStr){
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch(match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
//反格式化字符串
function unhtmlEscape(htmlStr){
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch(match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlEscape,
unhtmlEscape
}