yiquan0816-tools
Version:
提供了格式化时间、HTMLEscape相关功能
28 lines (26 loc) • 712 B
JavaScript
// 定义转义 HTML 字符的函数
function htmlEscape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g, match => {
switch (match) {
case '<': return '<'
case '>': return '>'
case '"': return '"'
case '&': return '&'
}
})
}
// 定义还原 HTML 字符串的函数
function htmlUnEscape(str) {
return str.replace(/<|>|"|&/g, match => {
switch (match) {
case '<': return '<'
case '>': return '>'
case '"': return '"'
case '&': return '&'
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}