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

keykit

v1.1.7

Published

KeyEvents and KeyStrokes general utilities

Downloads

13

Readme

KeyKit module

Some basic shit to handle KeyEvents, transform keyCodes into chars and stuff like that. Mind the formulation. This is not intended for production use. It is based on my keyboard, using US(en) and CA(fr) layouts. Although, it works great for testing and development.

It can:

  • parse a keystroke from text/kbEvent and return a model
  • retrieve keyCodes/names/properties
  • execute a sequence of keys

Install : npm install keykit

Usage

{KeyKit, KeyStroke, KeySequence, KeyCode} = require 'keykit'
# KeyKit == KeyKit.Key == KeyKit.Kit

# General layout:
# - Key (or KeyKit):  General utilities; key data, kbEvent handling, ...
#                           .code(string) return key name
#                           .name(number) return key code
#                           .key(string || number) returns key data
# - KeyCode:          Object where indexes match keycodes (ex.: KeyCode[27] is Escape)
# - KeyStroke:        Keystroke model. Pretty straight-forward, see definition
#                     below. No cmd key handling, even if the field is present.
# - KeySequence:      Ok. This one is not my greatest work, but it is meant to
#                     represent a sequence of keystrokes in general. For
#                     example:
#                               ctrl-x, ctrl-v, h, e, l, l, o
#
#                     will be represented as an array of [KeyStrokes] under the
#                     'keys' property. 
#                     The interesting part is that it can execute the given
#                     sequence of keys, as if the user was typing it.

###
KeyKit/KeyCode: keycodes and names data
###

KeyKit.code('escape')
# <= 27

KeyKit.name(9)
# <= 'tab'

KeyKit.isMod(18)
# <= true

KeyKit.isMod('shift')
# <= true

KeyKit.key('SLASH') == KeyKit.key(191)
### <= {
    name: "/"
    code: 191
    printable: true
    visible: true
    char: [ "/", "?" ]
} however, != from ###
KeyKit.key '/'
### <= {
    name: "/"
    code: 111
    printable: true
    visible: true
    char: [ "/", "?" ]
} (Note the code. KEYPAD_SLASH != SLASH_QUESTION_KEY)
### 

KeyCode[57]
### <= {
    name: "9"
    sysname: "KEY_9"
    printable: true
    visible: true
    char: [ "9", "(" ]
} ###

###
KeyStroke model
###

# Parsing text representations of keystrokes:
# all of these (normally) return the same object
KeyStroke.fromKeyStroke('ctrl-alt-x')
KeyStroke.fromKBEvent(kbEvent)
KeyStroke.fromVim('<C-A-x>')
KeyStroke.fromVim('<C-M-x>')
# <= {KeyStroke}

class KeyStroke
    ctrl:  false || true
    alt:   false || true
    shift: false || true
    meta:  false || true
    cmd:   false || true

    name: 'space'                       # name, as usually returned by kbEvents
    char: ' '                           # char  OR  [unshiftedChar, shiftedChar]
    code: 20                            # kbEvent.keyCode
    identifier: 'U+0000' || 'space'     # if there is a key name, uses it.

# see also
# KeyStroke.fromChar(string)    where string.length == 1
# KeyStroke.parse(string)       which does magic and returns the appropriate
#                               model no matter the input format

###
KeySequence: 
 - constructor takes any KeyStroke.parse parsable string 
 - stores (and replays) a keystroke sequence
###

seq = KeySequence 'hello'
seq.execute()
# triggers 'h', 'e', 'l', 'l', 'o' on document.activeElement

seq = KeySequence 'ggVG<C-x>'
# ...

Note that you should read before using this anywhere

This is published because I needed a library to test key events across multiple platforms, quickly; finding no available ressource, I had to write this. If it can spare you some time, go ahead, use it. However:

  • it is not meant for efficiency
  • no doc
  • not tested on macs
  • don't expect it to be accurate on anything else than US(en) layout keyboard