lh-tools
Version:
lh提供了格式化时间、HTMLEscape相关的功能
42 lines (36 loc) • 906 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
}