AK-21/Graphite-Industrial-Intelligence
0
1/// <reference lib="dom" />2 3/* global document */4 5const element = document.createElement('i')6 7/**8 * @param {string} value9 * @returns {string | false}10 */11export function decodeNamedCharacterReference(value) {12 const characterReference = '&' + value + ';'13 element.innerHTML = characterReference14 const character = element.textContent15 16 // Some named character references do not require the closing semicolon17 // (`¬`, for instance), which leads to situations where parsing the assumed18 // named reference of `¬it;` will result in the string `¬it;`.19 // When we encounter a trailing semicolon after parsing, and the character20 // reference to decode was not a semicolon (`;`), we can assume that the21 // matching was not complete.22 if (23 character.charCodeAt(character.length - 1) === 59 /* `;` */ &&24 value !== 'semi'25 ) {26 return false27 }28 29 // If the decoded string is equal to the input, the character reference was30 // not valid.31 return character === characterReference ? false : character32}33 