(value: string)
| 45 | } |
| 46 | |
| 47 | function decodeJSXAttributeValue(value: string): string { |
| 48 | return value.replace( |
| 49 | /&(#(?:x[0-9a-fA-F]+|\d+)|[a-zA-Z][\w.-]*);/g, |
| 50 | (match, entity: string) => { |
| 51 | if (entity[0] === '#') { |
| 52 | const radix = entity[1]?.toLowerCase() === 'x' ? 16 : 10 |
| 53 | const digits = radix === 16 ? entity.slice(2) : entity.slice(1) |
| 54 | const codePoint = Number.parseInt(digits, radix) |
| 55 | if ( |
| 56 | !Number.isFinite(codePoint) || |
| 57 | codePoint <= 0 || |
| 58 | codePoint > 0x10ffff |
| 59 | ) { |
| 60 | return match |
| 61 | } |
| 62 | return String.fromCodePoint(codePoint) |
| 63 | } |
| 64 | |
| 65 | const decoded = decodeNamedCharacterReference(entity) |
| 66 | return decoded === false ? match : decoded |
| 67 | } |
| 68 | ) |
| 69 | } |
| 70 | |
| 71 | export function transform( |
| 72 | code: string, |
no test coverage detected