achilles-tools
Version:
提供了格式化时间、HTMLEscape相关的功能
41 lines (35 loc) • 905 B
JavaScript
// 定义转义 HTML 字符串的函数
function htmlEcape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g,(match) => {
switch(match) {
case '<':
return '<'
case '>':
return '>'
case'"':
return '"'
case "&":
return '&'
}
})
}
// 定义 还原 HTML 字符串函数
function htmlUnEcape(str) {
return str.replace(/<|>|"|&/g,(match) => {
switch(match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 向外暴露需要的成员
module.exports = {
htmlEcape,
htmlUnEcape
}