npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keyevent

v2.0.0

Published

The KeyEvent object gives us all the constants for key codes (should these not already exist somewhere?!?).

Downloads

667

Readme

KeyEvent

Simply put, a cross-browser compatible set of constants for all of the different key codes that handled in HTML keypress, keydown, and keyup events. Make your event code readable.

Prerequisites

None.

Installation

Include the src/keyevent.js in your project.

Here's a very very crude example. Fit this properly into your project.

<html>
  <head>...</head>
  <body>
    Some page...
    ...
    <script type="text/javascript" src="[PATH_TO]/keyevent.js"></script>
    ...
  </body>
</html>

What Do I Get?

An object named KeyEvent that has a bunch of constants. For example: KeyEvent.DOM_VK_RETURN or KeyEvent.DOM_VK_ESCAPE, etc. Check out the src/keyevent.js It is quite trivial.

NPM

npm install --save keyevent

or

npm install --save-dev keyevent

Then simply include the node_modules/keyevent/src/keyevent.js in your HTML page/project.

Bower (this will continue to exist, but I'm using NPM instead)

You can install KeyEvent using bower.

bower install keyevent

Then simply include the bower_components/keyevent/src/keyevent.js in your HTML page/project.

Example Usage

Using jQuery's event binding, here's a couple simple cross-browser compliant ways of handling key events.

Escape Clears Text Input Value

$('#some-text-input')
  .on('keypress', function (e) {
    if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
      $(this).val('');
    }
  });

Ctrl-Enter Submits The Inputs Form

$('#some-text-input')
  .off('keypress.ctrl-enter-return-submit')
  .on('keypress.ctrl-enter-return-submit', function (e) {
    if (e.ctrlKey) {
      switch (e.keyCode) {
        case KeyEvent.DOM_VK_RETURN:
        case KeyEvent.DOM_VK_ENTER:
          this.form.submit();
      }
    }
  });

Useful Links