From 486a29154c68ca9a1f1acf1d7cf829e44d500d0a Mon Sep 17 00:00:00 2001 From: rameel Date: Sat, 4 Apr 2026 22:00:11 +0500 Subject: [PATCH 1/2] Replace switch with if --- src/hotkey.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/hotkey.ts b/src/hotkey.ts index cd64c33..c5cc9b1 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -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; }, { From 86978cef5862d8657d774afd99fbdbfcb70409e3 Mon Sep 17 00:00:00 2001 From: rameel Date: Sat, 4 Apr 2026 22:01:48 +0500 Subject: [PATCH 2/2] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea37e48..3f47b65 100644 --- a/README.md +++ b/README.md @@ -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