jiuyue-tools
Version:
提供了格式化时间, HTMLEscape相关的功能
39 lines (36 loc) • 990 B
JavaScript
// 定义转义 HTML 字符的函数
function htmlEscape(htmlstr) {
// 匹配html标签的正则 < 或 > 或 " 或 & 或就是| g表示匹配全局 正则是 / 内容 /
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
}