'use strict'; const re = /(\r\n)|["\'<>]/g; const htmlEntity = { '&': '\u0026', '"': '\u0022', ''': '\u0027', '<': '\u003c', '>': '\u003e' }; exports.htmlDecode = function(txt) { txt = txt + '' || ''; return txt.replace(/((&(([a-z][a-z0-9]*)|(#[0-9]+)|(#x[0-9a-f]+));)|["'<>&])/gi, function(s) { s = s || ''; const s1 = htmlEntity[s.toLowerCase()]; if (s1) { s = s1; } return s; }); }; exports.htmlEncode = function(str) { str = str + '' || ''; return str.replace(re, function(s) { switch (s) { case '"': return '"'; case '\'': return '''; case '<': return '<'; case '>': return '>'; default: return s; } }); };