yfy
Version:
�ṩ�˸�ʽ��ʱ�䡢HTMLEscape��صĹ���
37 lines (34 loc) • 817 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
}