xiaoruan-tools
Version:
格式化时间,html字符串转义与还原
35 lines (34 loc) • 699 B
JavaScript
// 转义html字符串
const htmlescape = (htmlstr) => {
return htmlstr.replace(/<|>|"|&/g, function (match) {
switch (match) {
case "<":
return "<";
case ">":
return ">";
case '"':
return """;
case "&":
return "&";
}
});
};
// 还原字符串
const htmlrestore = (str) => {
return str.replace(/<|>|"|&/g, (match) => {
switch (match) {
case "<":
return "<";
case ">":
return ">";
case """:
return '"';
case "&":
return "&";
}
});
};
module.exports = {
htmlescape,
htmlrestore,
};