1
0
mirror of https://github.com/S2-/gitlit synced 2025-08-03 12:50:04 +02:00
Files
gitlit/app/node_modules/electron-is-accelerator/index.js
2019-06-06 15:44:24 +02:00

22 lines
849 B
JavaScript

"use strict";
const modifiers = /^(Command|Cmd|Control|Ctrl|CommandOrControl|CmdOrCtrl|Alt|Option|AltGr|Shift|Super)$/;
const keyCodes = /^([0-9A-Z)!@#$%^&*(:+<_>?~{|}";=,\-./`[\\\]']|F1*[1-9]|F10|F2[0-4]|Plus|Space|Tab|Backspace|Delete|Insert|Return|Enter|Up|Down|Left|Right|Home|End|PageUp|PageDown|Escape|Esc|VolumeUp|VolumeDown|VolumeMute|MediaNextTrack|MediaPreviousTrack|MediaStop|MediaPlayPause|PrintScreen)$/;
module.exports = function (str) {
let parts = str.split("+");
let keyFound = false;
return parts.every((val, index) => {
const isKey = keyCodes.test(val);
const isModifier = modifiers.test(val);
if (isKey) {
// Key must be unique
if (keyFound) return false;
keyFound = true;
}
// Key is required
if (index === parts.length - 1 && !keyFound) return false;
return isKey || isModifier;
});
};