yf-node-utils
Version:
格式化日期 html特殊字符转换
38 lines (36 loc) • 944 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":htmlEscape,
"htmlUnEscape":htmlUnEscape
}