UNPKG

lol-constants

Version:

League of Legends constants, functions, and types. Provides a plathera of functions to easily convert between ID, Name, and Key for champions, items, summoner spells, and runes.

60 lines (59 loc) 1.93 kB
export const Regions = { 'BR': { region: 'BR', platform: 'BR1' }, 'EUNE': { region: 'EUNE', platform: 'EUN1' }, 'EUW': { region: 'EUW', platform: 'EUW1' }, 'JP': { region: 'JP', platform: 'JP1' }, 'KR': { region: 'KR', platform: 'KR' }, 'LAN': { region: 'LAN', platform: 'LA1' }, 'LAS': { region: 'LAS', platform: 'LA2' }, 'NA': { region: 'NA', platform: 'NA1' }, 'OCE': { region: 'OCE', platform: 'OC1' }, 'TR': { region: 'TR', platform: 'TR1' }, 'RU': { region: 'RU', platform: 'RU' }, 'PH': { region: 'PH', platform: 'PH2' }, 'SG': { region: 'SG', platform: 'SG2' }, 'TH': { region: 'TH', platform: 'TH2' }, 'TW': { region: 'TW', platform: 'TW2' }, 'VN': { region: 'VN', platform: 'VN2' }, 'MENA': { region: 'MENA', platform: 'ME1' }, 'PBE': { region: 'PBE', platform: 'PBE1' }, }; const failsafeRegion = { region: '', platform: '' }; export const RegionsArr = Object.values(Regions); const platforms = { 'BR1': 'BR', 'EUN1': 'EUNE', 'EUW1': 'EUW', 'JP1': 'JP', 'KR': 'KR', 'LA1': 'LAN', 'LA2': 'LAS', 'NA1': 'NA', 'OC1': 'OCE', 'TR1': 'TR', 'RU': 'RU', 'PH2': 'PH', 'SG2': 'SG', 'TH2': 'TH', 'TW2': 'TW', 'VN2': 'VN', 'ME1': 'MENA', 'PBE1': 'PBE', }; export function isRegion(region) { return typeof region == 'string' && region in Regions; } export function isPlatform(platform) { return typeof platform == 'string' && platform in platforms; } /** * Get region by its region notation (e.g. `'EUW'`) * or by its platform notation (e.g. `'EUW1'`). * Convert between the two. */ export function getRegion(region_platform) { var _a, _b; if (isRegion(region_platform)) return (_a = Regions[region_platform]) !== null && _a !== void 0 ? _a : failsafeRegion; return (_b = Regions[platforms[region_platform]]) !== null && _b !== void 0 ? _b : failsafeRegion; }