From e7e54741d27eb863110c92e029b336182be8e6bd Mon Sep 17 00:00:00 2001 From: NotJayden Date: Mon, 7 Jun 2021 14:50:21 +0800 Subject: [PATCH] add conditional bosses filter if gamemode is seasonal --- package.json | 2 +- src/hiscores.ts | 10 ++++++---- tsconfig.json | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6784221..0a9fb3b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "osrs-json-hiscores", "version": "2.5.0", "description": "The Old School Runescape API wrapper that does more!", - "main": "lib/index.js", + "main": "lib/index", "types": "lib/index.d.ts", "files": [ "lib/**/*" diff --git a/src/hiscores.ts b/src/hiscores.ts index 2b3ce0d..b1c48a8 100644 --- a/src/hiscores.ts +++ b/src/hiscores.ts @@ -68,7 +68,7 @@ export async function getRSNFormat(rsn: string): Promise { * @param csv Raw CSV from the official OSRS API. * @returns Parsed stats object. */ -export function parseStats(csv: string): Stats { +export function parseStats(csv: string, mode: Gamemode = 'main'): Stats { const splitCSV = csv .split('\n') .filter((entry) => !!entry) @@ -97,11 +97,13 @@ export function parseStats(csv: string): Stats { return activity; }); + const filteredBosses = mode === 'seasonal'? BOSSES.filter((boss) => boss !== 'tempoross') : BOSSES; + const [leaguePoints] = activityObjects.splice(0, 1); const bhObjects = activityObjects.splice(0, BH_MODES.length); const clueObjects = activityObjects.splice(0, CLUES.length); const [lastManStanding, soulWarsZeal] = activityObjects.splice(0, 2); - const bossObjects = activityObjects.splice(0, BOSSES.length); + const bossObjects = activityObjects.splice(0, filteredBosses.length); const skills: Skills = skillObjects.reduce((prev, curr, index) => { const newSkills = { ...prev }; @@ -123,7 +125,7 @@ export function parseStats(csv: string): Stats { const bosses: Bosses = bossObjects.reduce((prev, curr, index) => { const newBosses = { ...prev }; - newBosses[BOSSES[index]] = curr; + newBosses[filteredBosses[index]] = curr; return newBosses; }, {} as Bosses); @@ -250,7 +252,7 @@ export async function getStatsByGamemode( if (response.status !== 200) { throw Error('Player not found'); } - const stats = parseStats(response.data); + const stats = parseStats(response.data, mode); return stats; } diff --git a/tsconfig.json b/tsconfig.json index ca4bf6a..cf7f094 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,12 @@ "module": "commonjs", "declaration": true, "outDir": "./lib", - "strict": true + "strict": true, + "lib": ["ES2015", "DOM", "DOM.Iterable"], + "typeRoots": [ + "./node_modules/@types", + "./src/@types" + ] }, "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"]