tools-zhaoshuaiqi
Version:
提供了格式化时间,HTML.Escape相关的功能
37 lines (34 loc) • 837 B
JavaScript
//定义转移HTML字符的函数
function htmlEscape(str) {
return str.replace(/<|>|"|&/g, (math) => {
switch (math) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
//定义还原html字符串的函数
function htmlUnEscape(str) {
return str.replace(/<|>|"|&/g,(math)=>{
switch (math) {
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '&':
return '&';
}
})
}
module.exports = {
htmlEscape,
htmlUnEscape
}