tyler-tools
Version:
这是一个字符转义工具
36 lines (34 loc) • 823 B
JavaScript
function htmlEscape(dateStr){
var regStr = /<|>|&|"/g;
return dateStr.replace(regStr, (match)=>{
switch(match){
case "<":
return "<"
case ">":
return ">"
case "&":
return "&"
case '"':
return """
}
})
}
function htmlUnescape(dateStr){
var regStr = /<|>|&|"/g;
return dateStr.replace(regStr, (match)=>{
switch(match){
case "<":
return "<"
case ">":
return ">"
case "&":
return "&"
case '"':
return '"'
}
})
}
module.exports = {
htmlEscape,
htmlUnescape
}