dt-escape-format
Version:
格式化日期时间,处理 html 特殊字符
38 lines (36 loc) • 742 B
JavaScript
// 转义 HTML 特殊字符
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|'|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
case "'":
return '"'
case '&':
return '&'
}
})
}
// 还原 HTML 特殊字符
function htmlUnEscape(htmlStr) {
console.log(htmlStr)
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}