MCPcopy Create free account
hub / github.com/TanStack/hotkeys / formatForDisplay

Function formatForDisplay

packages/hotkeys/src/format.ts:92–132  ·  view source on GitHub ↗
(
  hotkey: RegisterableHotkey | (string & {}),
  options: FormatDisplayOptions = {},
)

Source from the content-addressed store, hash-verified

90 * ```
91 */
92export 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.

Callers 15

SequenceListRowFunction · 0.90
HotkeyListFunction · 0.90
labelFunction · 0.90
format.test.tsFile · 0.90
renderRowsFunction · 0.90
formatWithLabelsFunction · 0.85
AppFunction · 0.85
BasicMultiHotkeysFunction · 0.85
CommonOptionsDemoFunction · 0.85
DynamicHotkeysDemoFunction · 0.85
RegistrationsViewerFunction · 0.85

Calls 3

detectPlatformFunction · 0.90
isModifierKeyFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…