echogarden
Version:
An easy-to-use speech toolset. Includes tools for synthesis, recognition, alignment, speech translation, language detection, source separation and more.
30 lines • 817 B
JavaScript
export function escapeHtml(text) {
return text.replaceAll(/[&<>"']/g, (char) => htmlEscapeLookup[char]);
}
const htmlEscapeLookup = {
'&': '&',
'<': '<',
'>': '>',
"'": ''',
'"': '"'
};
// This HTML unescape method is not fully standard compliant
// I implemented a fully compliant one in the package html-escape-compliant
function unescapeHtml(text) {
return text.replaceAll(/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160);/g, (str) => htmlUnescapeLookup[str]);
}
const htmlUnescapeLookup = {
'&': '&',
'&': '&',
'<': '<',
'<': '<',
'>': '>',
'>': '>',
''': "'",
''': "'",
'"': '"',
'"': '"',
' ': '\u00A0',
' ': '\u00A0'
};
//# sourceMappingURL=HtmlEscape.js.map