lee-tool
Version:
常用的数据处理方法
26 lines • 567 B
JavaScript
// html转义
function htmlEscape(str){
if(!str){
return ''
}
const newStr = str.replace(/<|>|"|&/g,function(match){
const obj = {'<':'<',">":">",'"':""","&":"&"}
return obj[match]
})
return newStr
}
//html的还原
function htmlUnescape(str){
if(!str){
return ''
}
const newStr = str.replace(/<|>|"|&/g,function(match){
const obj = {'<':'<',">":">",""":'"',"&":"&"}
return obj[match]
})
return newStr
}
module.exports = {
htmlUnescape,
htmlEscape
}