Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-keycode-enum

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-keycode-enum

A TypeScript enum definition that maps human-friendly key names to JavaScript key codes

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
43K
decreased by-5.78%
Maintainers
1
Weekly downloads
 
Created
Source

ts-keycode-enum

A TypeScript enum definition that maps human-friendly key names to JavaScript key codes

Important note

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.

Install

npm install ts-keycode-enum --save

Purpose

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) {
        ...
    }
}

Usage

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.

Building

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.

Contributions

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.

License

MIT

Keywords

FAQs

Package last updated on 18 Jun 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc