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.

35 lines (34 loc) 1.02 kB
const maxRiotGameNameCharCount = 16; const maxRiotTaglineCharCount = 5; /** E.g. `Faker#T1` ⇒ `{name: 'Faker', tag: 'T1'}` */ export function splitRiotId(riotId, /** @default '#' */ splitChar = '#') { var _a, _b; const split = riotId.split(splitChar); let name = (_a = split[0]) !== null && _a !== void 0 ? _a : ''; let tag = (_b = split[1]) !== null && _b !== void 0 ? _b : ''; if (tag.includes(splitChar)) tag = ''; return { name, tag, }; } /** Default `splitChar` is "#". */ export function makeRiotId(riotId, /** @default '#' */ splitChar = '#') { return riotId.name + splitChar + riotId.tag; } /** Default `splitChar` is "#". */ export function validateRiotId(riotId, /** @default '#' */ splitChar = '#') { const id = splitRiotId(riotId, splitChar); if (id.name == '' || id.name.length > maxRiotGameNameCharCount) return false; if (id.tag == '' || id.tag.length > maxRiotTaglineCharCount) return false; return true; }