(text: string)
| 72 | } |
| 73 | |
| 74 | function decodeHtmlEntities(text: string): string { |
| 75 | const namedEntities: Record<string, string> = { |
| 76 | amp: '&', |
| 77 | apos: "'", |
| 78 | copy: '(c)', |
| 79 | hellip: '...', |
| 80 | gt: '>', |
| 81 | lt: '<', |
| 82 | mdash: '-', |
| 83 | middot: '*', |
| 84 | nbsp: ' ', |
| 85 | ndash: '-', |
| 86 | quot: '"', |
| 87 | rsquo: "'", |
| 88 | } |
| 89 | |
| 90 | return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (entity, body) => { |
| 91 | if (body[0] === '#') { |
| 92 | const isHex = body[1]?.toLowerCase() === 'x' |
| 93 | const value = Number.parseInt(body.slice(isHex ? 2 : 1), isHex ? 16 : 10) |
| 94 | return Number.isFinite(value) && value >= 0 && value <= 0x10ffff |
| 95 | ? String.fromCodePoint(value) |
| 96 | : entity |
| 97 | } |
| 98 | return namedEntities[body] ?? entity |
| 99 | }) |
| 100 | } |
| 101 | |
| 102 | function normalizeText(text: string): string { |
| 103 | return text |
no outgoing calls
no test coverage detected