1.0.0 • Published 4 years ago

hotkey-chain v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

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, moyuyc95@gmail.com.

License

MIT - imcuttle 🐟