wl-node-uils
Version:
是供了格式化时间,HTMLEscape的功能
38 lines (34 loc) • 952 B
JavaScript
// 将html字符串转换成转义字符的字符串
function html(htmlStr){
return htmlStr.replace(/<|>|"|&/g,(match)=>{
switch (match){
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 将包含转义字符的字符串转换为html字符串
function htmlEsc(str){
return str.replace(/<|>|"|&/g,(match)=>{
switch (match){
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 将两个函数对外暴露
module.exports={
html,htmlEsc
}