* @param {string} text text * @returns {string} encoded text
(text)
| 62 | * @returns {string} encoded text |
| 63 | */ |
| 64 | function encode(text) { |
| 65 | if (!text) { |
| 66 | return ""; |
| 67 | } |
| 68 | |
| 69 | return replaceUsingRegExp(text, /[<>'"&]/g, (input) => { |
| 70 | let result = references[/** @type {keyof typeof references} */ (input)]; |
| 71 | if (!result) { |
| 72 | const code = |
| 73 | input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0); |
| 74 | result = `&#${code};`; |
| 75 | } |
| 76 | return result; |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @typedef {object} Context |
no test coverage detected
searching dependent graphs…