Compare commits

..

2 Commits

Author SHA1 Message Date
maxswa
468b43f66f v2.0.1 2020-01-05 20:43:45 -05:00
maxswa
d5bbe2a169 Update getActivityPage to accept bosses. 2020-01-05 20:43:15 -05:00
6 changed files with 31 additions and 20 deletions

View File

@@ -78,7 +78,7 @@ const topPage = await getSkillPage('overall');
| Tournament | `tournament` | | Tournament | `tournament` |
| Leagues | `seasonal` | | Leagues | `seasonal` |
`getSkillPage` and `getActivityPage` require a skill/activity and optionally a gamemode and page: `getSkillPage` and `getActivityPage` require a skill / activity and optionally a gamemode and page:
```javascript ```javascript
hiscores hiscores
@@ -109,6 +109,12 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
| Bounty Hunter (Hunter) | `hunterBH` | | Bounty Hunter (Hunter) | `hunterBH` |
| Last Man Standing | `lastManStanding` | | Last Man Standing | `lastManStanding` |
### Leagues
| Activity | Param |
| ------------- | :------------: |
| League Points | `leaguePoints` |
### Bosses ### Bosses
| Boss Name | Param | | Boss Name | Param |

View File

@@ -1,6 +1,6 @@
{ {
"name": "osrs-json-hiscores", "name": "osrs-json-hiscores",
"version": "2.0.0", "version": "2.0.1",
"description": "The Oldschool Runescape API wrapper that does more!", "description": "The Oldschool Runescape API wrapper that does more!",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -151,14 +151,15 @@ export async function getSkillPage(
const players: PlayerSkillRow[] = playersHTML.map(row => { const players: PlayerSkillRow[] = playersHTML.map(row => {
const cells = row.children.filter(el => el.name === 'td'); const cells = row.children.filter(el => el.name === 'td');
const [rankEl, nameCell, levelEl, xpEl] = cells; const [rankEl, nameCell, levelEl, xpEl] = cells;
const [nameEl] = nameCell.children.filter(el => el.name === 'a'); const nameEl = nameCell.children.find(el => el.name === 'a');
const isDead = !!nameCell.children.find(el => el.name === 'img');
return { return {
name: rsnFromElement(nameEl), name: rsnFromElement(nameEl),
rank: numberFromElement(rankEl), rank: numberFromElement(rankEl),
level: numberFromElement(levelEl), level: numberFromElement(levelEl),
xp: numberFromElement(xpEl), xp: numberFromElement(xpEl),
dead: nameCell.children.length === 4, dead: isDead,
}; };
}); });
@@ -186,13 +187,14 @@ export async function getActivityPage(
const players: PlayerActivityRow[] = playersHTML.map(row => { const players: PlayerActivityRow[] = playersHTML.map(row => {
const cells = row.children.filter(el => el.name === 'td'); const cells = row.children.filter(el => el.name === 'td');
const [rankEl, nameCell, scoreEl] = cells; const [rankEl, nameCell, scoreEl] = cells;
const [nameEl] = nameCell.children.filter(el => el.name === 'a'); const nameEl = nameCell.children.find(el => el.name === 'a');
const isDead = !!nameCell.children.find(el => el.name === 'img');
return { return {
name: rsnFromElement(nameEl), name: rsnFromElement(nameEl),
rank: numberFromElement(rankEl), rank: numberFromElement(rankEl),
score: numberFromElement(scoreEl), score: numberFromElement(scoreEl),
dead: nameCell.children.length === 4, dead: isDead,
}; };
}); });

View File

@@ -109,6 +109,7 @@ export type Boss =
export type Bosses = { [Type in Boss]: Activity }; export type Bosses = { [Type in Boss]: Activity };
export type ActivityName = export type ActivityName =
| 'leaguePoints'
| 'hunterBH' | 'hunterBH'
| 'rogueBH' | 'rogueBH'
| 'lastManStanding' | 'lastManStanding'

View File

@@ -60,18 +60,6 @@ export const CLUES: ClueType[] = [
'master', 'master',
]; ];
export const BH_MODES: BHType[] = ['rogue', 'hunter']; export const BH_MODES: BHType[] = ['rogue', 'hunter'];
export const ACTIVITIES: ActivityName[] = [
'hunterBH',
'rogueBH',
'lastManStanding',
'allClues',
'beginnerClues',
'easyClues',
'mediumClues',
'hardClues',
'eliteClues',
'masterClues',
];
export const GAMEMODES: Gamemode[] = [ export const GAMEMODES: Gamemode[] = [
'main', 'main',
'ironman', 'ironman',
@@ -126,6 +114,20 @@ export const BOSSES: Boss[] = [
'zalcano', 'zalcano',
'zulrah', 'zulrah',
]; ];
export const ACTIVITIES: ActivityName[] = [
'leaguePoints',
'hunterBH',
'rogueBH',
'allClues',
'beginnerClues',
'easyClues',
'mediumClues',
'hardClues',
'eliteClues',
'masterClues',
'lastManStanding',
...BOSSES,
];
export type FormattedBossNames = { export type FormattedBossNames = {
[key in Boss]: string; [key in Boss]: string;

View File

@@ -41,7 +41,7 @@ export const numberFromElement = (el: CheerioElement) => {
return parseInt(number, 10); return parseInt(number, 10);
}; };
export const rsnFromElement = (el: CheerioElement) => { export const rsnFromElement = (el: CheerioElement | undefined) => {
const innerText = el.firstChild.data; const innerText = el?.firstChild.data;
return innerText ? innerText.replace(/\uFFFD/g, ' ') : ''; return innerText ? innerText.replace(/\uFFFD/g, ' ') : '';
}; };