Skip to content

Commit

Permalink
add conditional bosses filter if gamemode is seasonal
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-Jayden committed Jun 7, 2021
1 parent 062e5e0 commit e7e5474
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*"
Expand Down
10 changes: 6 additions & 4 deletions src/hiscores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 };
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__/*"]
Expand Down

0 comments on commit e7e5474

Please sign in to comment.