is-hotkey
Check whether a keyboard event matches a hotkey string like 'mod+s' or 'cmd+alt+space'
Repository Health
Technical Analysis
is-hotkey is a tiny (under 1kb minified+gzipped) utility that answers one question: does this KeyboardEvent match a given hotkey pattern? Instead of hand-rolling event.key/event.which/event.metaKey comparisons, you write hotkeys as natural strings like mod+s, where mod resolves to cmd on Mac and ctrl elsewhere, and pass the browser event straight through.
What You Get
isHotkey(hotkeyString, event)— a single function call returning true/false for a match against aKeyboardEvent- A curried form,
isHotkey(hotkeyString), that returns a reusable matcher function so the hotkey string is parsed only once - Cross-platform
modkeyword that resolves tocmdon macOS andctrlon Windows/Linux automatically - Support for matching via either
event.which(default, broadest compatibility) orevent.key(layout-independent) depending on configuration
Common Use Cases
- Wiring keyboard shortcuts (save, bold, undo) in a rich-text editor or WYSIWYG component’s
onKeyDownhandler - Adding app-wide keyboard shortcuts (command palette, search focus) without a full hotkey-management framework
- Building editor or IDE-like web UIs that need to distinguish
cmd+son Mac fromctrl+son Windows with one hotkey string - Performance-sensitive keydown handlers that curry a hotkey matcher once and reuse it across many events
Under The Hood
Architecture The entire implementation lives in a single 222-line file (src/index.js): a hotkey string like mod+alt+s is split on +, each token normalized against a lookup table of key aliases and modifier names (including the special cross-platform mod token), then compared against the event’s modifier flags (metaKey, ctrlKey, altKey, shiftKey) and its key code or key value. Tech Stack Plain ES2015+ JavaScript compiled with Babel to CommonJS (lib/index.js) plus a UMD build (lib/is-hotkey.umd.js) for direct <script> usage, with zero runtime dependencies — the package is intentionally kept under 1kb minified and gzipped. Code Quality A 259-line Mocha test suite in test/index.js exercises the parser and matcher against a range of hotkey strings and simulated events, giving solid coverage relative to the library’s small surface area, though the project has seen no formal releases logged on GitHub despite ongoing commits, suggesting slower, informal maintenance cadence. API Design The API is a single function with two calling conventions — direct isHotkey(str, event) for one-off checks, or curried isHotkey(str)(event) when the same hotkey will be tested repeatedly — which keeps integration to one line of code in a keydown handler with no configuration objects or setup required for the common case.
Used by 11 apps in this directory
TinaCMS
CMS
An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.
Webiny JS
Blogging · CMS · Ecommerce
Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.