Skip to content

imcuttle/hotkey-chain

Repository files navigation

hotkey-chain

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

The easy way to create shortcut

Installation

npm install hotkey-chain
# or use yarn
yarn add hotkey-chain

Usage

import HotKeyChain from 'hotkey-chain'

const handler = new HotKeyChain()
  .on('enter', (event, next) => {
    if (someCondition) {
      // do something
      return
    }
    // Run next `enter` handler
    next()
  })
  .on('enter', (event, next) => {
    if (someCondition2) {
      // do something
      return
    }
    next()
  }).handler

document.addEventListener('keydown', handler)

Or use HotKeyChainManager quickly.

import { HotKeyChainManager } from 'hotkey-chain'

new HotKeyChainManager(document)
  .on('enter', (event, next) => {
    if (someCondition) {
      // do something
      return
    }
    next()
  })
  .on('enter', (event, next) => {
    if (someCondition2) {
      // do something
      return
    }
    next()
  })
  .start()

Contributing

  • Fork it!
  • Create your new branch:
    git checkout -b feature-new or git checkout -b fix-which-bug
  • Start your magic work now
  • Make sure npm test passes
  • Commit your changes:
    git commit -am 'feat: some description (close #123)' or git commit -am 'fix: some description (fix #123)'
  • Push to the branch: git push
  • Submit a pull request :)

Authors

This library is written and maintained by imcuttle, [email protected].

License

MIT - imcuttle 🐟

About

The easy way to create shortcut

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published