function escapeHtmlEntities (str) {
var escapes = {
'\\' : '\\',
'"' : '"',
'/' : '/',
't' : '\t',
'n' : '\n',
'r' : '\r',
'f' : '\f',
'b' : '\b',
'<' : '<',
'>' : '>'
};
return str.replace(/\\(?:u(.{4})|([^u]))/g, function(a, b, c) {
return b ? String.fromCharCode(parseInt(b, 16)) : escapes[c];
});
}