zdd-tools
Version:
提供了格式化时间,HTMLEscape相关的功能
41 lines (39 loc) • 867 B
JavaScript
// 定义转义HTML字符的函数
//正则表达式 //g
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,
htmlUnEscape
}