Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

electron-shortcut-normalizer

1.0.0 • Public • Published

electron-shortcut-normalizer

Normalize electron keyboard shortcuts so they work on different operating systems.

shortcut

  • is a function
  • makes your electron keyboard shortcuts platform-agnostic
  • can make them platform-specific too
  • accepts target platform in an options object
  • converts Option to Alt, because Alt exists on all platforms
  • converts CmdOrCtrl modifier to CommandOrControl
  • supports mixed-case modifiers like MediaPreviousTrack
  • capitalizes first letter of each modifier
  • removes whitespace from shorcuts
  • converts hyphens (-) to plusses (+)

Installation

npm install electron-shortcut-normalizer --save

Usage

const normalize = require("electron-shortcut-normalizer")
 
normalize('Ctrl+A')
// => 'CommandOrControl+A'
 
normalize('CommandOrControl+Z', process.platform)
// => 'Command+Z' on Mac OS X
// => 'Control+Z' on Windows and Linux
 
normalize('CmdOrCtrl+a', 'darwin')
// => 'Command+A'
 
normalize('CmdOrCtrl+a', 'win32')
// => 'Control+A'
 
// `Option` is unique to Mac OS X, so it's normalized to `Alt`:
normalize('Option+Up')
// => 'Alt+Up'

For more specific usage information, see test.js

See Also

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

  • tape: tap-producing test harness for node and browsers
  • tap-spec: Formatted TAP output like Mocha's spec reporter

License

MIT

Generated by package-json-to-readme

Install

npm i electron-shortcut-normalizer

DownloadsWeekly Downloads

585

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar