JSPM

ts-keycode

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 49
  • Score
    100M100P100Q49432F
  • License MIT

The package for check some data in typescript.

Package Exports

  • ts-keycode
  • ts-keycode/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-keycode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ts-keycode

NPM Latest Version Downloads Count Bundle Size Test Status Last Update Date Project License

Installation

$ npm install ts-keycode

Import

/**
 * It is a map with all keyboard codes
 */
import {keycode} from 'ts-keycode';

/**
 *  Or if you need segregate by segemnts:
 *  accents,
 *  alphabet,
 *  commands,
 *  f,
 *  functions,
 *  numbers,
 *  numpad,
 *  operators,
 *  select
 *  
 *  Use it below
 */
import {keycodeSegments} from 'ts-keycode';

Examples

import {NumbersEnum} from 'ts-keycode/consts/numbers';
import {NumpadEnum} from 'ts-keycode/consts/numpad';

const twoFactorId: string = 'authorization-login-form-two-factor-code';
const inputTwoFactor: HTMLInputElement = document.getElementById(twoFactorId);

// ...

const allowKeyboardCodesMap: (typeof NumbersEnum | typeof NumpadEnum)[] = {
    ...NumbersEnum,
    ...NumpadEnum
};

// ...

inputTwoFactor.addEventListener('keydown', ($event) => {
   if ($event?.isTrusted) {

       // ...
       const keycode: number = $event.which ?? $event.keyCode;
       if (allowKeyboardCodes.hasOwnProperty(keycode)) {
           
           // ...
           
       }
       // ...

   } 
});

Twitter Profile

LinkedIn Profile

GitHub Profile

medium.com Profile