@svta/common-media-library
Version:
A common library for media playback in JavaScript
42 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unescapeHtml = unescapeHtml;
const escapedHtml = /&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g;
/**
* Unescapes HTML entities
*
* @param text - The text to unescape
* @returns The unescaped text
*
* @group Utils
*
* @beta
*
* @example
* {@includeCode ../../test/utils/unescapeHtml.test.ts#example}
*/
function unescapeHtml(text) {
if (text.indexOf('&') === -1) {
return text;
}
return text.replace(escapedHtml, (match) => {
switch (match) {
case '&': return '&';
case '<': return '<';
case '>': return '>';
case '"': return '"';
case ''': return '\'';
case ' ': return '\u{a0}';
case '‎': return '\u{200e}';
case '‏': return '\u{200f}';
default: {
if (match[1] === '#') {
const code = match[2] === 'x' || match[2] === 'X' ? parseInt(match.slice(3), 16) : parseInt(match.slice(2), 10);
return String.fromCodePoint(code);
}
return match;
}
}
});
}
//# sourceMappingURL=unescapeHtml.js.map