This commit is contained in:
Ian Renton
2025-12-31 10:14:52 +00:00
parent 06d582ae2d
commit 3f117a47d6
12 changed files with 52 additions and 28 deletions

View File

@@ -0,0 +1,25 @@
//
// GENERAL UTILITY FUNCTIONS
// String manipulation etc.
//
// Utility function to escape HTML characters from a string.
function escapeHtml(str) {
if (typeof str !== 'string') {
return '';
}
const escapeCharacter = (match) => {
switch (match) {
case '&': return '&';
case '<': return '&lt;';
case '>': return '&gt;';
case '"': return '&quot;';
case '\'': return '&#039;';
case '`': return '&#096;';
default: return match;
}
};
return str.replace(/[&<>"'`]/g, escapeCharacter);
}