feel-tools
Version:
提供了格式化时间,HTMLEscape,HTMLUnEscape等工具
35 lines (32 loc) • 789 B
JavaScript
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g,function(match) {
switch(match) {
case '<' :
return '%lt';
case '>' :
return '%gt';
case '"' :
return '%quot';
case '&':
return '&';
}
})
}
function htmlUnEscape(str) {
return str.replace(/%lt|%gt|%quot|&/g,function(match) {
switch(match) {
case '%lt' :
return '<';
case '%gt' :
return '>';
case '%quot' :
return '"';
case '&' :
return '&';
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}