damian_tools
Version:
提供了格式化时间,HTMLEscape的功能
39 lines (34 loc) • 819 B
JavaScript
//定义转义 HTML 特殊字符函数
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>"|&/g, (match) => {
switch (match) {
case "<":
return "<"
case ">":
return ">"
case '"':
return """
case '&':
return "&"
}
})
}
//定义还原 HTML 特殊字符函数
function htmlUnEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g,(match) => {
switch (match) {
case "<":
return "<"
case ">":
return ">"
case '"':
return '"'
case '&':
return "&"
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}