UNPKG

@keybindy/core

Version:

A lightweight and framework-agnostic keyboard shortcut manager for web apps. Define, register, and handle keybindings with ease.

24 lines (22 loc) 728 B
const keyAliases = { ctrl: ['ctrl (left)', 'ctrl (right)'], shift: ['shift (left)', 'shift (right)'], alt: ['alt (left)', 'alt (right)'], meta: ['meta (left)', 'meta (right)', 'cmd'], }; function expandAliases(binding) { const expanded = [[]]; for (const key of binding) { const normalized = key.toLowerCase(); const variants = keyAliases[normalized] ?? [normalized]; const newExpanded = []; for (const existing of expanded) { for (const variant of variants) { newExpanded.push([...existing, variant]); } } expanded.splice(0, expanded.length, ...newExpanded); } return expanded; } export { expandAliases };