basant307/AI_Governance_Project
048
1const characterReferences = {'"': 'quot', '&': 'amp', '<': 'lt', '>': 'gt'}2 3/**4 * Encode only the dangerous HTML characters.5 *6 * This ensures that certain characters which have special meaning in HTML are7 * dealt with.8 * Technically, we can skip `>` and `"` in many cases, but CM includes them.9 *10 * @param {string} value11 * Value to encode.12 * @returns {string}13 * Encoded value.14 */15export function encode(value) {16 return value.replace(/["&<>]/g, replace)17 18 /**19 * @param {string} value20 * Value to replace.21 * @returns {string}22 * Encoded value.23 */24 function replace(value) {25 return (26 '&' +27 characterReferences[28 /** @type {keyof typeof characterReferences} */ (value)29 ] +30 ';'31 )32 }33}34 