All files / src/client/hsr hsr.helper.ts

100% Statements 32/32
100% Branches 7/7
100% Functions 1/1
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 331x 1x 1x 1x 1x 1x 1x 1x 1x 15x 15x 15x 15x 15x 15x 1x 1x 15x 1x 1x 15x 11x 11x 15x 1x 1x 15x 1x 15x 14x 14x 14x  
import { HoyoAPIError } from '../../error'
import { HsrRegion, HsrRegionKeyType } from './hsr.interface'
 
/**
 * Get Server Region by UID
 *
 * @param uid number UID
 * @returns {string}
 */
export function getHsrRegion(uid: number): HsrRegion {
  const server_region = Number(uid.toString().trim().slice(0, 1))
  let key: string
 
  switch (server_region) {
    case 6:
      key = 'USA'
      break
    case 7:
      key = 'EUROPE'
      break
    case 8:
      key = 'ASIA'
      break
    case 9:
      key = 'CHINA_TAIWAN'
      break
    default:
      throw new HoyoAPIError(`Given UID ${uid} is invalid !`)
  }
 
  return HsrRegion[key as HsrRegionKeyType]
}