itheima-tools-lgx
Version:
提供了格式化时间、HTML Escape相关的功能-离歌笑
36 lines (34 loc) • 844 B
JavaScript
//定义转义HTM字符的函数
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
}