zyx-tools
Version:
提供了格式化时间、HTMLEscape相关功能
39 lines (35 loc) • 848 B
JavaScript
/* 定义转译HTML的字符的函数 */
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case "<":
return "<";
case ">":
return ">";
case '"':
return """;
case "&":
return "&";
}
});
}
/* 定义HTML还原的函数 */
function htmlUnEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case "<":
return "<";
case ">":
return ">";
case """:
return '"';
case "&":
return "&";
}
});
}
/* 暴露 */
module.exports = {
htmlEscape,
htmlUnEscape,
};