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

js-keycodes

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-keycodes

Identify and work with keycodes on JavaScript

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-78.26%
Maintainers
1
Weekly downloads
 
Created
Source

js-keycodes

travis build Codecov NPM version Downloads License

Identify and work with keyCodes on JavaScript

Install

npm i -S js-keyCodes

Usage

First import the lib into your code:

import * as KeyCodes from 'js-keycodes';

Or individual functions:

import { isLetter, isNumber } from 'js-keycodes';
Verify if a keyCode is a letter
const myKeyCode = 90;
if (KeyCodes.isLetter(myKeyCode)) {
  // Do stuff if your keyCode is a letter
}
Verify if ENTER is pressed on an event
const handleAnEvent = (event) => {
  if (event.which === KeyCodes.ENTER) {
    // Do your stuff here.
  }
}

Methods

KeyCodes.isNumber()

Return true if the keyCode is a number from 0 to 9.

KeyCodes.isLetter()

Return true if the keyCode is a letter from A to Z.

KeyCodes.isNavigation()

Return true if the keyCode represents an Arrow key like UP, DOWN, LEFT or RIGHT.

KeyCodes.isWhitespace()

Return true if the keyCode represent ENTER, SPACE or TAB

KeyCodes.isF1ToF12()

Return true if the keyCode represent any of the F buttons from F1 to F12

KeyCodes.keyCodeToString()

Return a string representation of the keyCode.

const myLetter = KeyCodes.keyCodeToString(90);
// -> 'Z'

const myNumber = KeyCodes.keyCodeToString(50)
//  '2'
KeyCodes.getKeyNameFromKeyCode()

Return a string representation based on the programmatic name of the keyCode

const myLetter = KeyCodes.getKeyNameFromKeyCode(90);
// -> 'Z'

const myNumber = KeyCodes.getKeyNameFromKeyCode(50);
// -> 'TWO'

const myKey = KeyCodes.getKeyNameFromKeyCode(13);
// -> 'ENTER'

const myF = KeyCodes.getKeyNameFromKeyCode(121);
// -> 'F10'

Keywords

FAQs

Package last updated on 15 May 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