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.

23 lines (22 loc) 1.09 kB
import { championKeys, championNames, Champions, failsafeChampion, } from '../objects/generated/Champions'; /** Get a champion by its **id**, **key**, or **name**. */ export function getChampion(id_key_name) { var _a, _b, _c; if (typeof id_key_name == 'number') return (_a = Champions[id_key_name]) !== null && _a !== void 0 ? _a : failsafeChampion; if (isChampionKey(id_key_name)) return (_b = Champions[championKeys[id_key_name]]) !== null && _b !== void 0 ? _b : failsafeChampion; return (_c = Champions[championNames[id_key_name]]) !== null && _c !== void 0 ? _c : failsafeChampion; } export function isChampionId(id) { return typeof id == 'number' && id in Champions; } export function isChampionKey(key) { return typeof key == 'string' && key in championKeys; } export function isChampionName(name) { return typeof name == 'string' && name in championNames; } export function isChampion(id_key_name) { return typeof id_key_name == 'number' ? isChampionId(id_key_name) : (isChampionKey(id_key_name) || isChampionName(id_key_name)); }