blanco-tools
Version:
提供格式化时间、HTMLEscape相关的功能
29 lines (26 loc) • 689 B
JavaScript
//1.定义HTML转义方法
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<': return '<'
case '>': return '>'
case '"': return '"'
case '&': return '&'
}
})
}
//2.定义HTML还原方法
function htmlUnEscape(str) {
return str.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<': return '<'
case '>': return '>'
case '"': return '"'
case '&': return '&'
}
})
}
//3.向外暴露两个方法
module.exports={
htmlEscape,htmlUnEscape
}