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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kaymash

v0.1.0

Published

Hook de atalho de teclado

Readme

Perfeito! Aqui está o README.md atualizado com todas as melhorias do keymash/v2, mantendo compatibilidade com a API antiga via a função useKaymash.


# 🧠 keymash

**React Hook para atalhos de teclado com suporte a múltiplos contextos (`range`), registro em massa e bloqueio automático de eventos nativos.**  
Agora modular, mais poderoso — **e ainda compatível com a versão antiga** via `useKaymash`.

---

## 🚀 Instalação

```bash
pnpm add keymash
# ou
npm install keymash
```

Formas de utilizar

existe duas formas de usar sendo elas listando ou declarando diretamente.

  • useKeymashList
  • useKaymash

🧪 useKeymashList (versão nova)

import { useKeymashList } from "keymash";

function App() {
  useKeymashList(
    [
      {
        combo: ["Control", "k"],
        action: () => alert("🔍 Busca ativada!"),
        range: ["global"],
        description: "Abrir busca",
      },
      {
        combo: ["Shift", "p"],
        action: () => console.log("Apresentação ativada"),
        range: ["editor"],
        description: "Modo apresentação",
      },
    ],
    {
      activeRanges: ["global", "editor"],
    }
  );

  return <div>Atalhos ativados. Pressione e veja o que acontece!</div>;
}

useKaymash

Você ainda pode usar a API simples e direta da versão anterior com useKaymash, se quiser manter o estilo enxuto:

import { useKaymash } from "keymash";

function App() {
  const [ativo, setAtivo] = useState(false);

  useKaymash(["Control", "k"], () => {
    setAtivo(!ativo);
  });

  return (
    <div>
      <h1>{ativo ? "Ativado!" : "Desativado!"}</h1>
    </div>
  );
}

⚙️ API

🔹 useKeymashList(shortcuts: Shortcut[], options?: UseKeymashListOptions)

🔑 Shortcut

| Campo | Tipo | Obrigatório | Descrição | | ------------- | ------------ | ----------- | ----------------------------------------------- | | combo | string[] | ✅ | Teclas do atalho (ex: ["Control", "k"]) | | action | () => void | ✅ | Função executada ao disparar o combo | | range | string[] | ❌ | Contextos onde o atalho é válido (["editor"]) | | description | string | ❌ | Texto explicativo, útil para docs/UI |

⚙️ UseKeymashListOptions

| Campo | Tipo | Obrigatório | Descrição | | -------------- | ---------- | ----------- | ------------------------------------------------- | | activeRanges | string[] | ❌ | Quais ranges estão ativos (default: ["global"]) |


🔹 useKaymash(combo: string[], callback: () => void)

Compatível com versões anteriores. Registro simples de um atalho único.


✅ Recursos

  • [x] Registro em massa de atalhos (array de Shortcut)
  • [x] Suporte a contextos com range
  • [x] preventDefault automático (bloqueia atalhos do navegador)
  • [x] Suporte à ordem invertida de teclas
  • [x] Cleanup automático no unmount
  • [x] Arquitetura modular e extensível
  • [x] Compatível com o hook antigo useKaymash

🔧 Dica avançada

Quer listar os atalhos registrados?

import { normalizeShortcuts } from "keymash/core";

console.table(normalizeShortcuts(shortcuts));

📦 Requisitos

  • React 18 ou 19
  • TypeScript (opcional, mas altamente recomendado)

📃 Licença

MIT


Feito com café, paciência e teclado por S.Silva.