(key: string)
| 455 | * ``` |
| 456 | */ |
| 457 | export function normalizeKeyName(key: string): string { |
| 458 | // key can be undefined in rare cases |
| 459 | // (browser extensions synthesizing key events, accessibility tools, certain OS/browser combinations). |
| 460 | if (!key) return '' |
| 461 | // Check aliases first |
| 462 | if (key in KEY_ALIASES) { |
| 463 | return KEY_ALIASES[key]! |
| 464 | } |
| 465 | |
| 466 | if (isSingleLetterKey(key)) { |
| 467 | const upper = key.toUpperCase() |
| 468 | // Some Unicode letters (e.g., 'ß') uppercase to multi-character sequences |
| 469 | // ('SS'). Avoid changing the string length so the rest of the matching |
| 470 | // logic can rely on a stable single-character key value. |
| 471 | return upper.length === 1 ? upper : key |
| 472 | } |
| 473 | |
| 474 | // Check if it's a function key (normalize case) |
| 475 | const upperKey = key.toUpperCase() |
| 476 | if (/^F([1-9]|1[0-2])$/.test(upperKey)) { |
| 477 | return upperKey |
| 478 | } |
| 479 | |
| 480 | return key |
| 481 | } |
| 482 | |
| 483 | // ============================================================================= |
| 484 | // Display Symbols |
no test coverage detected
searching dependent graphs…