mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-16 01:09:55 +00:00
30 lines
565 B
TypeScript
30 lines
565 B
TypeScript
export function isKeyboardEvent(event: Event): event is KeyboardEvent {
|
|
return 'key' in event;
|
|
}
|
|
|
|
export function normalizeKey(key: string): string {
|
|
const lowerKey = key.toLowerCase();
|
|
|
|
switch (lowerKey) {
|
|
case ' ':
|
|
case 'spacebar': // for older browsers
|
|
return 'space';
|
|
|
|
case 'arrowup':
|
|
return 'up';
|
|
case 'arrowdown':
|
|
return 'down';
|
|
case 'arrowleft':
|
|
return 'left';
|
|
case 'arrowright':
|
|
return 'right';
|
|
|
|
case 'esc':
|
|
case 'escape':
|
|
return 'escape';
|
|
|
|
default:
|
|
return lowerKey;
|
|
}
|
|
}
|