Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Mar 9, 2024
1 parent 5bec8f9 commit ef1a665
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/mousetrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const SPECIAL_ALIASES: Record<string, string> = {
};

const keyFromEvent = (e: KeyboardEvent): string => {
if (e.type == 'keypress') {
if (e.type === 'keypress') {
const character = String.fromCharCode(e.which);
return e.shiftKey ? character : character.toLowerCase(); // ignore caps lock
}
Expand All @@ -106,7 +106,7 @@ const eventModifiers = (e: KeyboardEvent): string[] => {
return modifiers;
};

const isModifier = (key: string): boolean => key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
const isModifier = (key: string): boolean => key === 'shift' || key === 'ctrl' || key === 'alt' || key === 'meta';

const getReverseMap = (() => {
let REVERSE_MAP: Record<string, string> | undefined;
Expand All @@ -126,7 +126,7 @@ const getReverseMap = (() => {

const pickBestAction = (key: string, modifiers: string[], action?: Action): Action => {
action = action || (getReverseMap()[key] ? 'keydown' : 'keypress');
if (action == 'keypress' && modifiers.length) return 'keydown'; // modifiers incompatible with keypress
if (action === 'keypress' && modifiers.length) return 'keydown'; // modifiers incompatible with keypress
return action;
};

Expand All @@ -150,7 +150,7 @@ const getKeyInfo = (combination: string, action?: Action): KeyInfo => {
};

export class Mousetrap {
private bindings: Record<string, Binding[]> = {};
private bindings: Record<string, Binding[] | undefined> = {};

constructor(targetElement?: HTMLElement | Document) {
targetElement = targetElement || document;
Expand Down Expand Up @@ -193,10 +193,10 @@ export class Mousetrap {

for (const binding of this.getMatches(e)) {
if (
binding.combination == 'esc' ||
(el.tagName != 'INPUT' &&
el.tagName != 'SELECT' &&
el.tagName != 'TEXTAREA' &&
binding.combination === 'esc' ||
(el.tagName !== 'INPUT' &&
el.tagName !== 'SELECT' &&
el.tagName !== 'TEXTAREA' &&
!el.isContentEditable &&
!el.hasAttribute('trap-bypass'))
) {
Expand All @@ -210,14 +210,14 @@ export class Mousetrap {
private getMatches = (e: KeyboardEvent): Binding[] => {
const key = keyFromEvent(e);
const action = e.type;
const modifiers = action == 'keyup' && isModifier(key) ? [key] : eventModifiers(e);
const modifiers = action === 'keyup' && isModifier(key) ? [key] : eventModifiers(e);
return (this.bindings[key] || []).filter(
binding =>
action == binding.action &&
action === binding.action &&
// Chrome will not fire a keypress if meta or control is down,
// Safari will fire a keypress if meta or meta+shift is down,
// Firefox will fire a keypress if meta or control is down
((action == 'keypress' && !e.metaKey && !e.ctrlKey) || modifiersMatch(modifiers, binding.modifiers)),
((action === 'keypress' && !e.metaKey && !e.ctrlKey) || modifiersMatch(modifiers, binding.modifiers)),
);
};
}

0 comments on commit ef1a665

Please sign in to comment.