tool-evans
Version:
这是一款卢本伟用了都说好的格式化时间和转义HTML插件
37 lines (36 loc) • 934 B
JavaScript
function escapeHtml(htmlStr) {
var res = htmlStr.replace(/<|>|&|"/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '&':
return '&'
case '"':
return '"'
}
})
return res
}
function unescapeHtml(htmlStr) {
var res = htmlStr.replace(/<|>|&|"/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '&':
return '&'
case '"':
return '"'
}
})
return res
}
// console.log(unescapeHtml('<h1>123&"</h1>'));
// console.log(escapeHtml('<h1>123&"</h1>'));
module.exports = {
escapeHtml,
unescapeHtml
}