(
hotkey: RegisterableHotkey | (string & {}),
options: FormatDisplayOptions = {},
)
| 90 | * ``` |
| 91 | */ |
| 92 | export function formatForDisplay( |
| 93 | hotkey: RegisterableHotkey | (string & {}), |
| 94 | options: FormatDisplayOptions = {}, |
| 95 | ): string { |
| 96 | const platform = options.platform ?? detectPlatform() |
| 97 | const useSymbols = options.useSymbols ?? true |
| 98 | const separatorToken = |
| 99 | options.separatorToken ?? (platform === 'mac' && useSymbols ? ' ' : '+') |
| 100 | const normalizedHotkey = normalizeRegisterableHotkey( |
| 101 | hotkey as RegisterableHotkey, |
| 102 | platform, |
| 103 | ) |
| 104 | return normalizedHotkey |
| 105 | .split('+') |
| 106 | .map((segment) => { |
| 107 | if (isModifierKey(segment)) { |
| 108 | const modifierToken = (MODIFIER_ALIASES[segment] ?? |
| 109 | MODIFIER_ALIASES[segment.toLowerCase()]) as CanonicalModifier | 'Mod' |
| 110 | return platform === 'mac' |
| 111 | ? useSymbols |
| 112 | ? MAC_MODIFIER_SYMBOLS[modifierToken] |
| 113 | : MAC_MODIFIER_LABELS[modifierToken] |
| 114 | : platform === 'windows' |
| 115 | ? WINDOWS_MODIFIER_LABELS[modifierToken] |
| 116 | : LINUX_MODIFIER_LABELS[modifierToken] |
| 117 | } else { |
| 118 | const keyDisplaySymbol = |
| 119 | useSymbols && |
| 120 | KEY_DISPLAY_SYMBOLS[segment as keyof typeof KEY_DISPLAY_SYMBOLS] |
| 121 | if (keyDisplaySymbol) return keyDisplaySymbol |
| 122 | |
| 123 | const punctuationKeyDisplayLabel = |
| 124 | !useSymbols && |
| 125 | PUNCTUATION_KEY_DISPLAY_LABELS[ |
| 126 | segment as keyof typeof PUNCTUATION_KEY_DISPLAY_LABELS |
| 127 | ] |
| 128 | return punctuationKeyDisplayLabel || segment |
| 129 | } |
| 130 | }) |
| 131 | .join(separatorToken) |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option. |
no test coverage detected
searching dependent graphs…