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

Function normalizedHotkeyStringFromParsed

packages/hotkeys/src/parse.ts:146–175  ·  view source on GitHub ↗

* Serializes a parsed hotkey to the canonical string form used for registration * and storage: `Mod` first when the platform allows, then `Alt`, then `Shift`; * otherwise full `Control+Alt+Shift+Meta` order.

(
  parsed: ParsedHotkey,
  platform: 'mac' | 'windows' | 'linux',
)

Source from the content-addressed store, hash-verified

144 * otherwise full `Control+Alt+Shift+Meta` order.
145 */
146function normalizedHotkeyStringFromParsed(
147 parsed: ParsedHotkey,
148 platform: 'mac' | 'windows' | 'linux',
149): Hotkey {
150 const canUseMod =
151 platform === 'mac'
152 ? parsed.meta && !parsed.ctrl
153 : parsed.ctrl && !parsed.meta
154
155 const parts: Array<string> = []
156
157 if (canUseMod) {
158 parts.push('Mod')
159 if (parsed.alt) {
160 parts.push('Alt')
161 }
162 if (parsed.shift) {
163 parts.push('Shift')
164 }
165 } else {
166 for (const modifier of MODIFIER_ORDER) {
167 if (parsed.modifiers.includes(modifier)) {
168 parts.push(modifier)
169 }
170 }
171 }
172
173 parts.push(normalizeKeyName(parsed.key))
174 return parts.join('+') as Hotkey
175}
176
177/**
178 * Normalizes a hotkey string to its canonical form.

Callers 3

normalizeHotkeyFunction · 0.85
normalizeHotkeyFromEventFunction · 0.85

Calls 1

normalizeKeyNameFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…