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

shortkey-parser

v1.0.6

Published

Keyboard shortkey parser for JavaScript.

Downloads

2

Readme

shortkey-parser

Keyboard shortkey parser.

GitHub Build Status Coverage Status

Installation

npm install shortkey-parser

Usage

shortkey-parser is exposing a parse method, which can be used to parse shortkey strings.

const { parse } = require('shortkey-parser');

const shortkeys = parse('ctrl+k, a');

const json = shortkeys.toJSON();

Definitions

Key

Key represents a single key on the keyboard. It has a type of KeyType which is represented as a most basic object in shortkey-parser.

Keys are represented in a flat object. As an example, this is a A key on the keyboard:

// key A on keyboard
{
    which: 65,
    keyCode: 65,
    code: 'KeyA',
    key: 'a',
    location: 0,
},

KeyGroup

KeyGroups are groups of keyboard keys. Each Key has its own group and some keys are grouped under same alias names:

// Left alt key on keyboard
'left-alt': [
    {
        which: 18,
        keyCode: 18,
        code: 'AltLeft',
        key: 'Alt',
        location: 1,
    },
],

// alt Keys
'alt': [
    {
        which: 18,
        keyCode: 18,
        code: 'AltLeft',
        key: 'Alt',
        location: 1,
    },
    {
        which: 18,
        keyCode: 18,
        code: 'AltRight',
        key: 'Alt',
        location: 2,
    },
]

KeyGroup has methods below:

  • size(): number of Keys in the KeyGroup.
  • toJSON(): Json representation of the KeyGroup.
  • from(str): static method which gets a string (representing the key or alias) and returns a KeyGroup.

Shortkey

Shortkeys are combination of KeyGroups separated by "+". Here is an example of alt+d Shortkey.

// "alt+d" Shortkey
[
    [
        {
            which: 18,
            keyCode: 18,
            code: 'AltLeft',
            key: 'Alt',
            location: 1,
        },
        {
            which: 18,
            keyCode: 18,
            code: 'AltRight',
            key: 'Alt',
            location: 2,
        },
    ],
    [
        {
            which: 68,
            keyCode: 68,
            code: 'KeyD',
            key: 'd',
            location: 0,
        },
    ]
]

In our convention, you are not tied to modifiers like alt and only one general key. Here is an example of a+d Shortkey.

// "a+d" Shortkey
[
    [
        {
            which: 65,
            keyCode: 65,
            code: 'KeyA',
            key: 'a',
            location: 0,
        },
    ],
    [
        {
            which: 68,
            keyCode: 68,
            code: 'KeyD',
            key: 'd',
            location: 0,
        },
    ]
]

Shortkey has methods below:

  • size(): number of KeyGroups in the Shortkey.
  • toJSON(): Json representation of the Shortkey.
  • from(str): static method which gets a string representing a shortkey and returns a Shortkey.

ShortkeySequence

ShortkeySequences are list of Shortkeys separated by ",". Here is an example of ctrl+k, d Shortkey.

// "ctrl+k, d" ShortkeySequence
[

    [
        [
            [
                {
                    which: 17,
                    keyCode: 17,
                    code: 'ControlLeft',
                    key: 'Control',
                    location: 1,
                },
            ],
            [
                {
                    which: 17,
                    keyCode: 17,
                    code: 'ControlRight',
                    key: 'Control',
                    location: 2,
                },
            ]
        ],
        [
            {
                which: 75,
                keyCode: 75,
                code: 'KeyK',
                key: 'k',
                location: 0,
            },
        ]
    ],
    [
        [
            {
                which: 68,
                keyCode: 68,
                code: 'KeyD',
                key: 'd',
                location: 0,
            },
        ]
    ]

]

ShortkeySequence has methods below:

  • first(): returns the first Shortkey in the ShortkeySequence.
  • last(): returns the last Shortkey in the ShortkeySequence.
  • get(n): returns the nth Shortkey in the ShortkeySequence.
  • size(): number of Shortkeys in the ShortkeySequence.
  • toJSON(): Json representation of the ShortkeySequence.
  • toString(): String representation of the ShortkeySequence. (This is only for debugging and cannot be passed to ShortkeySequence for parsing again)
  • from(str): static method which gets a string representing a shortkeySequence and returns a ShortkeySequence.

Special Cases

Whitespaces

All whitespaces are ignored.

Special Characters

You can put special characters inside quotes or double quotes. Also remember that always in this cases there is an equivalent alias.

alt+'+'
alt+plus

Any Key can be put inside a quote or double quote. If you are not sure you need one, you can always put it in quotes or use an alias.

Keys and Aliases

Please refer to Keys and Aliases.