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 🙏

© 2026 – Pkg Stats / Ryan Hefner

keymatch

v1.0.5

Published

Utility for matching browser keyboard events across platforms

Readme

keymatch

A utility for matching keyboard events against Electron accelerator strings.

Installation

npm install keymatch
# or
pnpm add keymatch
# or
yarn add keymatch

Usage

Adapting to Platform-Specific Modifiers

Use "CmdOrCtrl" to adapt your modifier key to "Command" (MacOS) or "Ctrl" depending on the platform. This can be combined with other modifiers like "Alt" or "Shift" using +:

import { keymatch } from 'keymatch';

document.addEventListener('keydown', (event) => {
  if (keymatch(event, 'CmdOrCtrl+Shift+N')) {
    event.preventDefault();
    createNewFile();
  }
});

Handling Single Letter Matches

You can also handle single-letter matches that explicitly don't have modifiers. For example, this matches when "A" is pressed, but not when "Cmd+A" is pressed:

document.addEventListener('keydown', (event) => {
  if (keymatch(event, 'A')) {
    event.preventDefault();
    selectAll();
  }
});

Using Platform-Specific matches

You can also create platform-specific matches by combining with the isMac() utility. This example uses Cmd for a MacOS shortcut, and Ctrl+Shift for other platforms:

import { keymatch, isMac } from 'keymatch';

document.addEventListener('keydown', (event) => {
  if (keymatch(event, isMac() ? 'Cmd+K' : 'Ctrl+Shift+K')) {
    event.preventDefault();
    openCommandPalette();
  }
});

Handling Arrow Keys

keymatch also supports Electron accelerator shorthands, like "Up" to represent "ArrowUp":

document.addEventListener('keydown', (event) => {
  if (keymatch(event, 'CmdOrCtrl+Up')) {
    event.preventDefault();
    moveSelectionToTop();
  }
});

Supported Accelerator Formats

The library supports Electron-style accelerator strings:

Modifiers

  • Cmd or Command - Maps to metaKey (⌘ on Mac)
  • Ctrl or Control - Maps to ctrlKey
  • CmdOrCtrl or CommandOrControl - Uses Cmd on MacOS, Ctrl on other platforms
  • Alt - Uses Option on MacOS, Alt on other platforms
  • Shift - Maps to shiftKey
  • Meta or Super - Maps to metaKey
  • Option - Maps to Option on MacOS. Note this modifier will only match on MacOS! Use Alt for a platform-agnostic match.

Keys

Any key that can be captured by a KeyboardEvent, including:

  • Letter keys: A, B, C, etc.
  • Number keys: 1, 2, 3, etc.
  • Function keys: F1, F2, F3, etc.
  • Special keys: Space, Enter, Escape, Tab, Delete, etc.
  • Arrow keys: Up, Down, Left, Right (also accepts ArrowUp, ArrowDown, etc.)

API

keymatch(event: KeyboardEvent, accelerator: string): boolean

Checks if a KeyboardEvent matches the given accelerator string.

Parameters:

  • event - The web-standard KeyboardEvent to test
  • accelerator - The Electron-style accelerator string

Returns:

  • boolean - True if the event matches the accelerator

isMac(): boolean

Utility function to detect if the current platform is MacOS.

Returns:

  • boolean - True if running on MacOS, false otherwise

License

MIT