All files / src/plugins unescape_html.js

60% Statements 3/5
100% Branches 0/0
0% Functions 0/2
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17    2x               2x           2x
import {toStr} from "../helpers/string/to_string";
 
const unescapeCharsMap = {
    '<': /(&lt;)|(&#x0*3c;)|(&#0*60;)/gi,
    '>': /(&gt;)|(&#x0*3e;)|(&#0*62;)/gi,
    '&': /(&amp;)|(&#x0*26;)|(&#0*38;)/gi,
    '"': /(&quot;)|(&#x0*22;)|(&#0*34;)/gi,
    "'": /(&#x0*27;)|(&#0*39;)/gi,
    '`': /(&#x0*60;)|(&#0*96;)/gi,
};
const chars = Object.keys(unescapeCharsMap);
 
function reduceUnescapedString(string, key) {
    return string.replace(unescapeCharsMap[key], key);
}
 
export const unescapeHtml = s => chars.reduce(reduceUnescapedString, toStr(s))