
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
ts-keycode-enum
Advanced tools
A TypeScript enum definition that maps human-friendly key names to JavaScript key codes
A TypeScript enum definition that maps human-friendly key names to JavaScript key codes
event.which
and event.keyCode
have been deprecated. It is recommended to instead use event.key
in combination with this very similar module: ts-key-enum.
npm install ts-keycode-enum --save
Tired of referencing JavaScript keycodes by number?
onKeyPress = (ev) => {
// gross
if (ev.which === 13) {
...
}
}
Me too. With this module, you can do this instead (in a TypeScript file):
onKeyPress = (ev) => {
// much better
if (ev.which === Key.Enter) {
...
}
}
To use this module, import the Key
enum at the top of your TypeScript file using the enum:
import { Key } from 'ts-keycode-enum';
You can now use a readable enum value in place of any raw keycodes throughout the file:
if (ev.which === Key.Escape) { ... }
See Key.enum.ts for a complete list of available keys.
In addition, to aid with readability, a number of enum values have aliases. For example:
// this true - these values are equal
Key.One === Key.ExclamationMark
Use whichever value makes more sense for readability.
To build this module yourself, first install its dependencies using
npm install
Then, run the build using
npm run build
Build output is placed in the dist
directory.
This module only contains some of the most commonly-used key codes. If it's missing keycodes that you need, feel free to request the codes via an issue or a pull request.
MIT
FAQs
A TypeScript enum definition that maps human-friendly key names to JavaScript key codes
The npm package ts-keycode-enum receives a total of 33,874 weekly downloads. As such, ts-keycode-enum popularity was classified as popular.
We found that ts-keycode-enum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.