Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![MIT](https://img.shields.io/github/license/rameel/ramstack.hotkey.js)](https://github.com/rameel/ramstack.hotkey.js/blob/main/LICENSE)

The `@ramstack/hotkey` package is a very small and lightweight library for handling hotkeys.
The library weighs around 1.4KB and approximately 800 bytes when gzipped.
The library weighs around 1.3KB and approximately 800 bytes when gzipped.

## Installation

Expand Down
27 changes: 11 additions & 16 deletions src/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,17 @@ function describe(hotkey: string): Hotkey {
const keys = hotkey.replace(/\s+/g, "").toLowerCase().split("+");
const info = keys.reduce((data, k) => {
k = aliases[k] ?? k;
switch (k) {
case "ctrl":
case "alt":
case "shift":
case "meta":
data[`${k}Key`] = true;
break;

default:
k.length || error_invalid_key(hotkey);
k = k.toUpperCase();

data.code = /^[A-Z]$/.test(k) ? `KEY${k}`
: /^[0-9]$/.test(k) ? `DIGIT${k}`
: k;
break;
if (/^(ctrl|alt|shift|meta)$/.test(k)) {
// @ts-ignore
data[`${k}Key`] = true;
}
else {
k.length || error_invalid_key(hotkey);
k = k.toUpperCase();

data.code = /^[A-Z]$/.test(k) ? `KEY${k}`
: /^[0-9]$/.test(k) ? `DIGIT${k}`
: k;
}
return data;
}, {
Expand Down
Loading