New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

keyboardevent-key-standardiser-shim

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keyboardevent-key-standardiser-shim

Shim fixing most non-standard event.key values

  • 0.2.1
  • beta
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

KeyboardEvent key standardiser shim

This project is in an alpha state, and needs testing. Use in a production environment is not recommended.

Internet Explorer, Edge, and Firefox 36 and older (Firefox up to 48 in case of some media keys) suffer from non-standard event.key values. This shim fixes most (or at least the most common) of those. It doesn't polyfill event.key if it doesn't exist natively, but it plays well polyfills that do, such as https://github.com/cvan/keyboardevent-key-polyfill.

Usage

The shim self-executes. Simply import it or require it.

import 'keyboardevent-key-standardiser-shim';

The KEYMAP is exported in case you want to customise the shim. The main scenario for doing so would be to switch the numpad Decimal and Separator keys to use , and . instead of the other way around.

import { KEYMAP } from 'keyboardevent-key-standardiser-shim';

// Modern browsers return either ',' or '.' for the numpad "Decimal", depending on region.
KEYMAP.Decimal = ',';
KEYMAP.Separator = '.';

Implementation details

It is not possible, or at least not straightforward, to directly detect whether KeyboardEvent.prototype.key follows the latest standard. This shim instead replaces the native getter and returns a standard-complient key. Furthermore, if it notices a verified good key, it unloads itself and reverts to fully native event.key handling.

This does not fix all event.key issues and bugs with older browser. E.g. Internet Explorer reports "Unidentified" for multiple non-latin modifier keys. Also, some browsers may return the wrong key value, such as Firefox returning "AltGraph" instead of "ModeChange".

Further reading:

Keywords

FAQs

Package last updated on 08 Apr 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