File "normalizeKey.ts"

Full path: /home/fsibplc/public_html/sommilito-bank2/splide-4.1.3/src/js/utils/dom/normalizeKey/normalizeKey.ts
File size: 652 B (652 B bytes)
MIME-type: text/x-java
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

import { ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP } from '../../../constants/arrows';
import { isString } from '../../type/type';


/**
 * The map to associate a non-standard name to the standard one.
 *
 * @since 4.0.0
 */
export const NORMALIZATION_MAP = {
  Spacebar: ' ',
  Right   : ARROW_RIGHT,
  Left    : ARROW_LEFT,
  Up      : ARROW_UP,
  Down    : ARROW_DOWN,
};

/**
 * Normalizes the key.
 *
 * @param key - A string or a KeyboardEvent object.
 *
 * @return A normalized key.
 */
export function normalizeKey( key: string | KeyboardEvent ): string {
  key = isString( key ) ? key : key.key;
  return NORMALIZATION_MAP[ key ] || key;
}