date5_tools
Version:
提供格式化时间、HTMLEscape相关的功能
37 lines (34 loc) • 852 B
JavaScript
// 定义转义HTML字符的函数
function htmlEscape(htmlStr){
return htmlStr.replace(/<|>|"|&/g, math=>{
switch (math){
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '&':
return '&';
}
})
}
// 定义还原转义HTML字符的函数
function htmlunEscape(htmlstr){
return htmlstr.replace(/<|>|"|&/g, marth=>{
switch(marth){
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '&':
return '&';
}
})
}
module.exports={
htmlEscape,
htmlunEscape
}