itheima-tools-zzn
Version:
这个包提供了格式化时间 HTMLEscape功能
36 lines (35 loc) • 879 B
JavaScript
// 定义转义 HTMl 字符的函数
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 定义还原 HTML 字符的函数
function htmlUnEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match)=> {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 向外暴露的成员
module.exports = {
htmlEscape,
htmlUnEscape
}