Skip to content

Commit

Permalink
Merge pull request #31 from acdvorak/fix-navigator-warning
Browse files Browse the repository at this point in the history
Don't `console.warn()` when `navigator` is `undefined`
  • Loading branch information
amcdnl authored May 8, 2024
2 parents 031a5db + c10d24d commit 55a743e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
let isMac: boolean = false;
try {
if (navigator) isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
} catch (e) {
console.warn(e);
type ModifierKey = '⌘' | 'CTRL';

function isMac(): boolean {
try {
return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
} catch {
return false;
}
}

function getModifierKey(): ModifierKey {
isMac() ? '⌘' : 'CTRL'
}

export const MODIFIER_KEY = isMac ? '⌘' : 'CTRL';
export const MODIFIER_KEY = getModifierKey();

export function getHotkeyText(hotkey: string) {
return hotkey
.replace('modifier', MODIFIER_KEY)
.replace('mod', MODIFIER_KEY)
.replace('modifier', getModifierKey())
.replace('mod', getModifierKey())
.replace('shift', '⇧');
}

0 comments on commit 55a743e

Please sign in to comment.