add conditional bosses filter if gamemode is seasonal

This commit is contained in:
NotJayden
2021-06-07 14:50:21 +08:00
parent 062e5e02b2
commit e7e54741d2
3 changed files with 13 additions and 6 deletions

View File

@@ -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/**/*"

View File

@@ -68,7 +68,7 @@ export async function getRSNFormat(rsn: string): Promise<string> {
* @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<Skills>((prev, curr, index) => {
const newSkills = { ...prev };
@@ -123,7 +125,7 @@ export function parseStats(csv: string): Stats {
const bosses: Bosses = bossObjects.reduce<Bosses>((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;
}

View File

@@ -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__/*"]