You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ts-key-enum

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-key-enum - npm Package Compare versions

Comparing version

to
2.0.2

43

dist/declarations/Key.enum.d.ts
/**
* An enum that includes all non-printable string values one can expect from $event.key.
* For example, this enum includes values like "CapsLock", "Backspace", and "AudioVolumeMute",
* but does not include values like "a", "A", "#", "é", or "¿".
* Auto generated from MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values#Speech_recognition_keys
*/
* An enum that includes all non-printable string values one can expect from $event.key.
* For example, this enum includes values like "CapsLock", "Backspace", and "AudioVolumeMute",
* but does not include values like "a", "A", "#", "é", or "¿".
* Auto generated from MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values#Speech_recognition_keys
*/
export declare enum Key {

@@ -102,9 +102,11 @@ /** The user agent wasn't able to map the event's virtual keycode to a specific key value. This can happen due to hardware or software constraints, or because of constraints around the platform on which the user agent is running. */

Help = "Help",
/** The Pause key. Pauses the current application or state, if applicable.
This shouldn't be confused with the "MediaPause" key value, which is used for media controllers, rather than to control applications and processes.
*/
/**
* The Pause key. Pauses the current application or state, if applicable.
* This shouldn't be confused with the "MediaPause" key value, which is used for media controllers, rather than to control applications and processes.
*/
Pause = "Pause",
/** The Play key. Resumes a previously paused application, if applicable.
This shouldn't be confused with the "MediaPlay" key value, which is used for media controllers, rather than to control applications and processes.
*/
/**
* The Play key. Resumes a previously paused application, if applicable.
* This shouldn't be confused with the "MediaPlay" key value, which is used for media controllers, rather than to control applications and processes.
*/
Play = "Play",

@@ -127,5 +129,6 @@ /** The Props (Properties) key. */

LogOff = "LogOff",
/** The Power button or key, to toggle power on and off.
Not all systems pass this key through to to the user agent.
*/
/**
* The Power button or key, to toggle power on and off.
* Not all systems pass this key through to to the user agent.
*/
Power = "Power",

@@ -560,13 +563,13 @@ /** The PowerOff or PowerDown key. Shuts off the system. */

MailSend = "MailSend",
/** The Calculator key, often labeled with an icon such as . This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP2). */
/** The Calculator key, often labeled with an icon. This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP2). */
LaunchCalculator = "LaunchCalculator",
/** The Calendar key, often labeled with an icon like . */
/** The Calendar key, often labeled with an icon. */
LaunchCalendar = "LaunchCalendar",
/** The Contacts key. */
LaunchContacts = "LaunchContacts",
/** The Mail key. This is often displayed as . */
/** The Mail key. This is often displayed with an icon. */
LaunchMail = "LaunchMail",
/** The Media Player key. */
LaunchMediaPlayer = "LaunchMediaPlayer",
/** The Music Player key, often labeled with an icon such as . */
/** The Music Player key, often labeled with an icon. */
LaunchMusicPlayer = "LaunchMusicPlayer",

@@ -579,5 +582,5 @@ /** The My Computer key on Windows keyboards. This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP1). */

LaunchScreenSaver = "LaunchScreenSaver",
/** The Spreadsheet key. This key may be labeled with an icon such as or that of a specific spreadsheet application. */
/** The Spreadsheet key. This key may be labeled with an icon. */
LaunchSpreadsheet = "LaunchSpreadsheet",
/** The Web Browser key. This key is frequently labeled with an icon such as or the icon of a specific browser, depending on the device manufacturer. */
/** The Web Browser key. This key is frequently labeled with an icon. */
LaunchWebBrowser = "LaunchWebBrowser",

@@ -584,0 +587,0 @@ /** The WebCam key. Opens the webcam application. */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* An enum that includes all non-printable string values one can expect from $event.key.
* For example, this enum includes values like "CapsLock", "Backspace", and "AudioVolumeMute",
* but does not include values like "a", "A", "#", "é", or "¿".
* Auto generated from MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values#Speech_recognition_keys
*/
* An enum that includes all non-printable string values one can expect from $event.key.
* For example, this enum includes values like "CapsLock", "Backspace", and "AudioVolumeMute",
* but does not include values like "a", "A", "#", "é", or "¿".
* Auto generated from MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values#Speech_recognition_keys
*/
var Key;

@@ -105,9 +105,11 @@ (function (Key) {

Key["Help"] = "Help";
/** The Pause key. Pauses the current application or state, if applicable.
This shouldn't be confused with the "MediaPause" key value, which is used for media controllers, rather than to control applications and processes.
*/
/**
* The Pause key. Pauses the current application or state, if applicable.
* This shouldn't be confused with the "MediaPause" key value, which is used for media controllers, rather than to control applications and processes.
*/
Key["Pause"] = "Pause";
/** The Play key. Resumes a previously paused application, if applicable.
This shouldn't be confused with the "MediaPlay" key value, which is used for media controllers, rather than to control applications and processes.
*/
/**
* The Play key. Resumes a previously paused application, if applicable.
* This shouldn't be confused with the "MediaPlay" key value, which is used for media controllers, rather than to control applications and processes.
*/
Key["Play"] = "Play";

@@ -130,5 +132,6 @@ /** The Props (Properties) key. */

Key["LogOff"] = "LogOff";
/** The Power button or key, to toggle power on and off.
Not all systems pass this key through to to the user agent.
*/
/**
* The Power button or key, to toggle power on and off.
* Not all systems pass this key through to to the user agent.
*/
Key["Power"] = "Power";

@@ -563,13 +566,13 @@ /** The PowerOff or PowerDown key. Shuts off the system. */

Key["MailSend"] = "MailSend";
/** The Calculator key, often labeled with an icon such as . This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP2). */
/** The Calculator key, often labeled with an icon. This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP2). */
Key["LaunchCalculator"] = "LaunchCalculator";
/** The Calendar key, often labeled with an icon like . */
/** The Calendar key, often labeled with an icon. */
Key["LaunchCalendar"] = "LaunchCalendar";
/** The Contacts key. */
Key["LaunchContacts"] = "LaunchContacts";
/** The Mail key. This is often displayed as . */
/** The Mail key. This is often displayed with an icon. */
Key["LaunchMail"] = "LaunchMail";
/** The Media Player key. */
Key["LaunchMediaPlayer"] = "LaunchMediaPlayer";
/** The Music Player key, often labeled with an icon such as . */
/** The Music Player key, often labeled with an icon. */
Key["LaunchMusicPlayer"] = "LaunchMusicPlayer";

@@ -582,5 +585,5 @@ /** The My Computer key on Windows keyboards. This is often used as a generic application launcher key (APPCOMMAND_LAUNCH_APP1). */

Key["LaunchScreenSaver"] = "LaunchScreenSaver";
/** The Spreadsheet key. This key may be labeled with an icon such as or that of a specific spreadsheet application. */
/** The Spreadsheet key. This key may be labeled with an icon. */
Key["LaunchSpreadsheet"] = "LaunchSpreadsheet";
/** The Web Browser key. This key is frequently labeled with an icon such as or the icon of a specific browser, depending on the device manufacturer. */
/** The Web Browser key. This key is frequently labeled with an icon. */
Key["LaunchWebBrowser"] = "LaunchWebBrowser";

@@ -587,0 +590,0 @@ /** The WebCam key. Opens the webcam application. */

{
"name": "ts-key-enum",
"version": "2.0.0",
"version": "2.0.2",
"description": "A TypeScript string enum for compile-time safety when working with event.key",

@@ -12,7 +12,13 @@ "main": "dist/js/Key.enum.js",

"build": "tsc",
"scrape": "./node_modules/.bin/ts-node scrapeMDNForKeys.ts"
"scrape": "./node_modules/.bin/ts-node scrapeMDNForKeys.ts",
"tslint": "tslint -p .",
"tslint-fix": "tslint -p . --fix",
"prettier": "prettier --check '**/*.ts' '!dist/**'",
"prettier-fix": "prettier --write '**/*.ts' '!dist/**'",
"lint": "npm run prettier; npm run tslint",
"lint-fix": "npm run prettier-fix; npm run tslint-fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nfriend/ts-key-enum.git"
"url": "git+https://gitlab.com/nfriend/ts-key-enum.git"
},

@@ -37,19 +43,21 @@ "keywords": [

"bugs": {
"url": "https://github.com/nfriend/ts-key-enum/issues"
"url": "https://gitlab.com/nfriend/ts-key-enum/issues"
},
"homepage": "https://github.com/nfriend/ts-key-enum#readme",
"homepage": "https://gitlab.com/nfriend/ts-key-enum#readme",
"devDependencies": {
"@types/bluebird": "^3.5.20",
"@types/cheerio": "^0.22.7",
"@types/lodash": "^4.14.109",
"@types/request": "^2.47.1",
"@types/request-promise": "^4.1.41",
"bluebird": "^3.5.1",
"chalk": "^2.4.1",
"cheerio": "^1.0.0-rc.2",
"request": "^2.87.0",
"request-promise": "^4.2.2",
"ts-node": "^6.1.1",
"typescript": "^2.9.1"
"@types/bluebird": "3.5.28",
"@types/cheerio": "0.22.13",
"@types/lodash": "4.14.144",
"@types/request": "2.48.3",
"@types/request-promise": "4.1.44",
"bluebird": "3.7.1",
"chalk": "2.4.2",
"cheerio": "1.0.0-rc.3",
"prettier": "^1.18.2",
"request": "2.88.0",
"request-promise": "4.2.4",
"ts-node": "8.4.1",
"tslint": "^5.20.0",
"typescript": "3.6.4"
}
}
# ts-key-enum
<a href="https://gitlab.com/nfriend/ts-key-enum/pipelines/latest" target="_blank">
<img src="https://gitlab.com/nfriend/ts-key-enum/badges/master/pipeline.svg" alt="GitLab build status">
</a>
A TypeScript string enum for compile-time safety when working with `event.key`.

@@ -8,3 +13,3 @@

```bash
```sh
npm install ts-key-enum --save

@@ -17,3 +22,3 @@ ```

```JavaScript
```js
onKeyPress = (ev) => {

@@ -28,5 +33,5 @@

Me too. With this module, you can do this instead (in a TypeScript file):
Me too. With this module, you can do this instead (in a TypeScript file):
```JavaScript
```ts
onKeyPress = (ev) => {

@@ -49,3 +54,3 @@

```JavaScript
```js
import { Key } from 'ts-key-enum';

@@ -56,3 +61,3 @@ ```

```JavaScript
```js
// if (ev.key === 'Escape') { ... }

@@ -62,12 +67,46 @@ if (ev.key === Key.Escape) { ... }

See [`Key.enum.ts`](./Key.enum.ts) for a complete list of available keys. This file is auto-generated from the list of keys found at MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values.
See [`Key.enum.ts`](./Key.enum.ts) for a complete list of available keys. This file is auto-generated from the list of keys found at MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values.
## What's included
The `Key` enum contains values for all standard non-printable keys such as "CapsLock", "Backspace", and "AudioVolumeMute". The enum does not contain values for printable keys such as "a", "A", "#", "é", or "¿", simply because the list of possible values is too vast to include in a single enum. To test for printable values, simply use a string comparison:
The `Key` enum contains values for all standard non-printable keys such as "CapsLock", "Backspace", and "AudioVolumeMute". The enum does _not_ contain values for printable keys such as "a", "A", "#", "é", or "¿", simply because the list of possible values is too vast to include in a single enum. To test for printable values, simply use a string comparison:
```JavaScript
```js
if (ev.key === 'é') { ... }
```
## v2 vs v3
This package is published as two versions on NPM: `v2.x` and `v3.x`.
### v2
`v2.x` defines the `Key` enum as [a "basic" enum](https://www.typescriptlang.org/docs/handbook/enums.html#enums):
```ts
export enum Key { ... }
```
The end result is a JavaScript object that contains every enum value. You can see this object here: https://gitlab.com/nfriend/ts-key-enum/blob/v2/dist/js/Key.enum.js.
### v3
`v3.x` defines the `Key` enum as [a `const` enum](https://www.typescriptlang.org/docs/handbook/enums.html#const-enums):
```ts
export const enum Key { ... }
```
This allows the enum's definition to live entirely in the definition file `https://gitlab.com/nfriend/ts-key-enum/blob/master/Key.enum.d.ts`. Consumers can use this enum without including _all_ of the enum's values in their own JavaScript bundle; only the values referenced in their code will be injected into their bundle.
## Which version should I use?
It's advisable to use `v3.x` unless you have a reason to use `v2.x`. Some reasons you may need to use `v2.x`:
- You are using this package as a JavaScript module (not a TypeScript module).
- You are using TypeScript < `1.4`, which doesn't support `const enum`.
- You are using [`@babel/plugin-transform-typescript`](https://babeljs.io/docs/en/babel-plugin-transform-typescript), which [does not support `const enum`](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats).
- See #2 and https://github.com/babel/babel/issues/8741
- Alternatively, use [`babel-plugin-const-enum`](https://www.npmjs.com/package/babel-plugin-const-enum) to convert `const enum`s to regular `enum` in your development environment, allowing you to reap the benefits of `const enum`s in your production build (see https://www.npmjs.com/package/babel-plugin-const-enum#transform-removeconst-default).
## Building

@@ -77,3 +116,3 @@

```bash
```sh
npm install

@@ -84,3 +123,3 @@ ```

```bash
```sh
npm run scrape

@@ -93,3 +132,3 @@ ```

```bash
```sh
npm run build

@@ -102,2 +141,2 @@ ```

MIT
MIT