(code)
| 3589 | * @returns {string} decoded character per WHATWG remap rules |
| 3590 | */ |
| 3591 | const decodeNumericReference = (code) => { |
| 3592 | // Per WHATWG numeric-character-reference-end-state: |
| 3593 | // - 0x00, > 0x10FFFF, or surrogate (0xD800-0xDFFF) -> U+FFFD. |
| 3594 | // - 0x80-0x9F -> Windows-1252 remap (above). |
| 3595 | // - Anything else (including noncharacters and C0 controls) -> the |
| 3596 | // code point itself; we don't surface the spec's parse-error |
| 3597 | // classes here since decoding is happening after the scanner ran. |
| 3598 | if (code === 0 || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff)) { |
| 3599 | return "�"; |
| 3600 | } |
| 3601 | if (code >= 0x80 && code <= 0x9f) { |
| 3602 | const remapped = /** @type {Record<number, string>} */ (NUMERIC_C1_REMAP)[ |
| 3603 | code |
| 3604 | ]; |
| 3605 | if (remapped !== undefined) return remapped; |
| 3606 | } |
| 3607 | return String.fromCodePoint(code); |
| 3608 | }; |
| 3609 | |
| 3610 | // Match one of three forms (each with an optional trailing `;`): |
| 3611 | // `&#x<hex>` - hex numeric reference (requires the `x`/`X`). |
no outgoing calls
no test coverage detected