/**
* Function that parses a string boolean value and returns the corresponding boolean value
* @param {string | number} candidate - The string boolean value to be parsed
* @return {boolean} - The parsed boolean value
*/
export function parseBoolean(candidate: string | number) {
try {
// lowercase the string, so TRUE becomes true
const candidateString = String(candidate).toLowerCase();
// wrap in boolean to ensure that the return value
// is a boolean even if values like 0 or 1 are passed
return Boolean(JSON.parse(candidateString));
} catch (error) {
return false;
}
}
/**
* Sanitizes text for safe HTML rendering by escaping potentially dangerous characters
* while preserving valid HTML tags.
*
* This function performs the following transformations:
* - Converts newline characters (\n) to HTML line breaks (
)
* - Escapes stray '<' characters that are not part of valid HTML tags (e.g., "x < 5" → "x < 5")
* - Escapes stray '>' characters that are not part of valid HTML tags (e.g., "x > 5" → "x > 5")
* - Preserves valid HTML tags and their attributes (e.g.,