🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@wordpress/keycodes

Package Overview
Dependencies
Maintainers
14
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/keycodes

Keycodes utilities for WordPress. Used to check for keyboard events across browsers/operating systems.

2.13.0
Source
npm
Version published
Weekly downloads
121K
-5.78%
Maintainers
14
Weekly downloads
 
Created

What is @wordpress/keycodes?

@wordpress/keycodes is a utility package that provides constants and helper functions for working with keyboard key codes. It is particularly useful for handling keyboard events in a consistent manner across different browsers and environments.

What are @wordpress/keycodes's main functionalities?

Keycode Constants

The package provides constants for common key codes, making it easier to reference and use them in your code without having to remember the numeric values.

const { ENTER, ESCAPE } = require('@wordpress/keycodes');
console.log(ENTER); // Outputs: 13
console.log(ESCAPE); // Outputs: 27

isKeyboardEvent

This helper function checks if a given keyboard event matches a specified key. It simplifies the process of handling specific key events.

const { isKeyboardEvent } = require('@wordpress/keycodes');
const event = new KeyboardEvent('keydown', { keyCode: 13 });
console.log(isKeyboardEvent(event, 'enter')); // Outputs: true

getKeycodeByKey

This function returns the keycode for a given key name, providing a convenient way to map key names to their corresponding key codes.

const { getKeycodeByKey } = require('@wordpress/keycodes');
console.log(getKeycodeByKey('Enter')); // Outputs: 13

Other packages similar to @wordpress/keycodes

Keywords

wordpress

FAQs

Package last updated on 28 May 2020

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