yeying-tools
Version:
提供了格式化功能和转义还原HTML中的特殊字符
34 lines • 836 B
JavaScript
// 1.定义转义html方法
function htmlEscape(htmlstr){
return htmlstr.replace(/<|>|"|&/g, (oldstr) => {
switch(oldstr){
case '<':
return "<"
case '>':
return ">"
case '"':
return """
case '&':
return '&'
}
})
}
// 2.定义还原html的方法
function htmlUnEscape(htmlstr){
return htmlstr.replace(/<|>|"|&/g, (oldstr) => {
switch(oldstr){
case '<':
return "<"
case '>':
return ">"
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}