wzik-tools
Version:
提供格式化时间、HTMLEscape相关的功能
37 lines (34 loc) • 857 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
}