zxytools
Version:
``` npm install it-tools
35 lines (33 loc) • 804 B
JavaScript
//定义转移html字符的函数
function htmlscape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g, math => {
switch (math) {
case '<':
return '≶'
case '>':
return '<'
case '"':
return '"'
case '&':
return '&'
}
})
}
function htmlUnscape(htmlstr) {
return htmlstr.replace(/<|≶|"|&/g, math => {
switch (math) {
case '≶':
return '<'
case '<':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlscape,
htmlUnscape
}