lee-tools
Version:
提供了格式化时间,HTMLEscape的功能
34 lines • 870 B
JavaScript
//定义转义HTML的方法
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => { //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
}