aboutsummaryrefslogtreecommitdiff
path: root/src/util/keycodes.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 15:36:13 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 15:36:13 +0530
commit31afcecdd849529bc5d6ae0719313f0f37e7cebc (patch)
treea7afbf01aa0ca68162c352a6137f4a164b0b8a4e /src/util/keycodes.ts
parent64cb4c87978434f478227fa2ea97277ae50269aa (diff)
feat(util): add pure keycodes and safeJs template helper
Diffstat (limited to 'src/util/keycodes.ts')
-rw-r--r--src/util/keycodes.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/keycodes.ts b/src/util/keycodes.ts
new file mode 100644
index 0000000..8669d1f
--- /dev/null
+++ b/src/util/keycodes.ts
@@ -0,0 +1,12 @@
+const VIRTUAL_KEY_CODES: Readonly<Record<string, number>> = {
+ Enter: 13, Tab: 9, Backspace: 8, Escape: 27, Delete: 46, " ": 32,
+ ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40,
+ Home: 36, End: 35, PageUp: 33, PageDown: 34,
+};
+
+export const SPECIAL_KEYS: ReadonlyArray<string> = Object.keys(VIRTUAL_KEY_CODES);
+
+export const virtualKeyCode = (key: string): number =>
+ VIRTUAL_KEY_CODES[key] ?? (key.length === 1 ? key.charCodeAt(0) : 0);
+
+export const keyCode = (key: string): string => key;