osrs-json-hiscores 2.16.2 → 2.17.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +23 -33
- package/lib/hiscores.js +7 -6
- package/lib/types.d.ts +9 -2
- package/lib/utils/constants.d.ts +1 -0
- package/lib/utils/constants.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -5,22 +5,24 @@
|
|
5
5
|
[![types](https://img.shields.io/npm/types/osrs-json-hiscores.svg?style=flat-square)](https://github.com/maxswa/osrs-json-hiscores/blob/master/src/types.ts)
|
6
6
|
[![build](https://img.shields.io/github/actions/workflow/status/maxswa/osrs-json-hiscores/main.yml?style=flat-square&branch=main)](https://github.com/maxswa/osrs-json-hiscores/actions/workflows/main.yml?query=branch%3Amain)
|
7
7
|
|
8
|
-
**The Old School
|
8
|
+
**The Old School RuneScape API wrapper that does more!**
|
9
9
|
|
10
10
|
## What it does
|
11
11
|
|
12
|
-
The official hiscores API for Old School
|
13
|
-
This wrapper converts
|
12
|
+
The official hiscores API for Old School RuneScape (OSRS) can return CSV or a simple JSON array.
|
13
|
+
This wrapper converts the hiscores data into a more usable JSON object and provides extra information about the given player. By comparing player info it infers the player's game mode, as well as any previous modes (de-ultimated, de-ironed and/or died as a hardcore ironman).
|
14
14
|
|
15
|
-
Additional functions are provided that screen-scrape the OSRS leaderboards and return a list of players as json.
|
15
|
+
Additional functions are provided that screen-scrape the OSRS leaderboards and return a list of players as json. Also simple utility functions are provided to fetch the raw responses from Jagex's APIs, if desired.
|
16
16
|
|
17
17
|
`osrs-json-hiscores` has TypeScript support, with full definitions for all functions and custom data types.
|
18
18
|
|
19
19
|
---
|
20
20
|
|
21
|
-
### Disclaimer
|
21
|
+
### ⚠ Disclaimer ⚠
|
22
22
|
|
23
|
-
Jagex does not provide `Access-Control-Allow-Origin` headers in their responses. This means that [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) will block all browser requests to their hiscores API. In order to get around this, osrs-json-hiscores
|
23
|
+
Jagex does not provide `Access-Control-Allow-Origin` headers in their responses. This means that [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) will block all browser requests to their hiscores API. In order to get around this, osrs-json-hiscores needs to be installed on the server side and exposed to the front end via a simple API. Here is an example of this in use: [codesandbox.io/s/osrs-json-hiscores-demo](https://codesandbox.io/s/osrs-json-hiscores-demo-qz656)
|
24
|
+
|
25
|
+
TLDR: You cannot use this library directly in your client side app e.g. React or Vue, you must set up a server which uses this lib internally and have your client fetch data from your server.
|
24
26
|
|
25
27
|
---
|
26
28
|
|
@@ -42,27 +44,14 @@ $ yarn add osrs-json-hiscores
|
|
42
44
|
|
43
45
|
Install the package and then import it into your project:
|
44
46
|
|
45
|
-
```
|
46
|
-
|
47
|
+
```typescript
|
48
|
+
import { getStatsByGamemode, getSkillPage } from 'osrs-json-hiscores';
|
47
49
|
```
|
48
50
|
|
49
51
|
Once you import it you can call the functions asynchronously:
|
50
52
|
|
51
|
-
```
|
52
|
-
|
53
|
-
.getStats('Lynx Titan')
|
54
|
-
.then((res) => console.log(res))
|
55
|
-
.catch((err) => console.error(err));
|
56
|
-
```
|
57
|
-
|
58
|
-
If you are using TypeScript or transpiling your JS you can use ES6 syntax:
|
59
|
-
|
60
|
-
```javascript
|
61
|
-
import hiscores, { getSkillPage } from 'osrs-json-hiscores';
|
62
|
-
|
63
|
-
// ...
|
64
|
-
|
65
|
-
const stats = await hiscores.getStats('Lynx Titan');
|
53
|
+
```typescript
|
54
|
+
const stats = await getStatsByGamemode('Lynx Titan');
|
66
55
|
const topPage = await getSkillPage('overall');
|
67
56
|
```
|
68
57
|
|
@@ -81,9 +70,8 @@ const topPage = await getSkillPage('overall');
|
|
81
70
|
|
82
71
|
`getSkillPage` and `getActivityPage` require a skill / activity and optionally a gamemode and page:
|
83
72
|
|
84
|
-
```
|
85
|
-
|
86
|
-
.getSkillPage('attack', 'main', 1)
|
73
|
+
```typescript
|
74
|
+
getSkillPage('attack', 'main', 1)
|
87
75
|
.then((res) => console.log(res))
|
88
76
|
.catch((err) => console.error(err));
|
89
77
|
```
|
@@ -115,11 +103,12 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|
115
103
|
| Soul Wars Zeal | `soulWarsZeal` |
|
116
104
|
| Rifts closed | `riftsClosed` |
|
117
105
|
|
118
|
-
###
|
106
|
+
### Points
|
119
107
|
|
120
|
-
| Activity
|
121
|
-
|
|
122
|
-
| League Points
|
108
|
+
| Activity | Param |
|
109
|
+
| -------------- | :-------------: |
|
110
|
+
| League Points | `leaguePoints` |
|
111
|
+
| Deadman Points | `deadmanPoints` |
|
123
112
|
|
124
113
|
### Bosses
|
125
114
|
|
@@ -162,6 +151,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|
162
151
|
| Phantom Muspah | `phantomMuspah` |
|
163
152
|
| Sarachnis | `sarachnis` |
|
164
153
|
| Scorpia | `scorpia` |
|
154
|
+
| Scurrius | `scurrius` |
|
165
155
|
| Skotizo | `skotizo` |
|
166
156
|
| Spindel | `spindel` |
|
167
157
|
| Tempoross | `tempoross` |
|
@@ -188,7 +178,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|
188
178
|
|
189
179
|
`getStats` returns a player object that looks like this:
|
190
180
|
|
191
|
-
```
|
181
|
+
```typescript
|
192
182
|
{
|
193
183
|
name: 'Lynx Titan',
|
194
184
|
mode: 'main',
|
@@ -216,7 +206,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|
216
206
|
|
217
207
|
`getSkillPage` returns and array of 25 players (This represents a page on the hiscores):
|
218
208
|
|
219
|
-
```
|
209
|
+
```typescript
|
220
210
|
[
|
221
211
|
{ rank: 1, name: 'Lynx Titan', level: 2277, xp: 4600000000, dead: false },
|
222
212
|
{},
|
@@ -229,7 +219,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|
229
219
|
|
230
220
|
Get the properly formatted name of any skill, boss, clue or other activity:
|
231
221
|
|
232
|
-
```
|
222
|
+
```typescript
|
233
223
|
// kril === "K'ril Tsutsaroth"
|
234
224
|
const kril = FORMATTED_BOSS_NAMES['krilTsutsaroth'];
|
235
225
|
```
|
package/lib/hiscores.js
CHANGED
@@ -170,6 +170,7 @@ function parseJsonStats(json) {
|
|
170
170
|
var clues = reduceActivity(utils_1.CLUES, utils_1.FORMATTED_CLUE_NAMES);
|
171
171
|
var bosses = reduceActivity(utils_1.BOSSES, utils_1.FORMATTED_BOSS_NAMES);
|
172
172
|
var leaguePoints = getActivity(utils_1.FORMATTED_LEAGUE_POINTS);
|
173
|
+
var deadmanPoints = getActivity(utils_1.FORMATTED_DEADMAN_POINTS);
|
173
174
|
var lastManStanding = getActivity(utils_1.FORMATTED_LMS);
|
174
175
|
var pvpArena = getActivity(utils_1.FORMATTED_PVP_ARENA);
|
175
176
|
var soulWarsZeal = getActivity(utils_1.FORMATTED_SOUL_WARS);
|
@@ -177,6 +178,7 @@ function parseJsonStats(json) {
|
|
177
178
|
var stats = {
|
178
179
|
skills: skills,
|
179
180
|
leaguePoints: leaguePoints,
|
181
|
+
deadmanPoints: deadmanPoints,
|
180
182
|
bountyHunter: bountyHunter,
|
181
183
|
lastManStanding: lastManStanding,
|
182
184
|
pvpArena: pvpArena,
|
@@ -199,8 +201,7 @@ function parseStats(csv) {
|
|
199
201
|
.split('\n')
|
200
202
|
.filter(function (entry) { return !!entry; })
|
201
203
|
.map(function (stat) { return stat.split(','); });
|
202
|
-
if (splitCSV.length !==
|
203
|
-
utils_1.SKILLS.length + utils_1.BH_MODES.length + utils_1.CLUES.length + utils_1.BOSSES.length + 5) {
|
204
|
+
if (splitCSV.length !== utils_1.SKILLS.length + utils_1.ACTIVITIES.length) {
|
204
205
|
throw new utils_1.InvalidFormatError();
|
205
206
|
}
|
206
207
|
var skillObjects = splitCSV
|
@@ -224,10 +225,10 @@ function parseStats(csv) {
|
|
224
225
|
};
|
225
226
|
return activity;
|
226
227
|
});
|
227
|
-
var
|
228
|
+
var _a = activityObjects.splice(0, 2), leaguePoints = _a[0], deadmanPoints = _a[1];
|
228
229
|
var bhObjects = activityObjects.splice(0, utils_1.BH_MODES.length);
|
229
230
|
var clueObjects = activityObjects.splice(0, utils_1.CLUES.length);
|
230
|
-
var
|
231
|
+
var _b = activityObjects.splice(0, 4), lastManStanding = _b[0], pvpArena = _b[1], soulWarsZeal = _b[2], riftsClosed = _b[3];
|
231
232
|
var bossObjects = activityObjects.splice(0, utils_1.BOSSES.length);
|
232
233
|
var skills = skillObjects.reduce(function (prev, curr, index) {
|
233
234
|
var newSkills = __assign({}, prev);
|
@@ -252,6 +253,7 @@ function parseStats(csv) {
|
|
252
253
|
var stats = {
|
253
254
|
skills: skills,
|
254
255
|
leaguePoints: leaguePoints,
|
256
|
+
deadmanPoints: deadmanPoints,
|
255
257
|
bountyHunter: bountyHunter,
|
256
258
|
lastManStanding: lastManStanding,
|
257
259
|
pvpArena: pvpArena,
|
@@ -294,8 +296,7 @@ function getStats(rsn, options) {
|
|
294
296
|
var _a;
|
295
297
|
return __generator(this, function (_b) {
|
296
298
|
return [2 /*return*/, otherGamemodes.includes(mode)
|
297
|
-
? getOfficialStats(rsn, mode, (_a = options === null || options === void 0 ? void 0 : options.axiosConfigs) === null || _a === void 0 ? void 0 : _a[mode])
|
298
|
-
.catch(function () { return undefined; })
|
299
|
+
? getOfficialStats(rsn, mode, (_a = options === null || options === void 0 ? void 0 : options.axiosConfigs) === null || _a === void 0 ? void 0 : _a[mode]).catch(function () { return undefined; })
|
299
300
|
: undefined];
|
300
301
|
});
|
301
302
|
}); };
|
package/lib/types.d.ts
CHANGED
@@ -21,15 +21,22 @@ export type BHType = 'rogue' | 'hunter' | 'rogueV2' | 'hunterV2';
|
|
21
21
|
export type BH = {
|
22
22
|
[Type in BHType]: Activity;
|
23
23
|
};
|
24
|
-
export type Boss = 'abyssalSire' | 'alchemicalHydra' | 'artio' | 'barrows' | 'bryophyta' | 'callisto' | 'calvarion' | 'cerberus' | 'chambersOfXeric' | 'chambersOfXericChallengeMode' | 'chaosElemental' | 'chaosFanatic' | 'commanderZilyana' | 'corporealBeast' | 'crazyArchaeologist' | 'dagannothPrime' | 'dagannothRex' | 'dagannothSupreme' | 'derangedArchaeologist' | 'dukeSucellus' | 'generalGraardor' | 'giantMole' | 'grotesqueGuardians' | 'hespori' | 'kalphiteQueen' | 'kingBlackDragon' | 'kraken' | 'kreeArra' | 'krilTsutsaroth' | 'mimic' | 'nex' | 'nightmare' | 'phosanisNightmare' | 'obor' | 'phantomMuspah' | 'sarachnis' | 'scorpia' | 'skotizo' | 'spindel' | 'tempoross' | 'gauntlet' | 'corruptedGauntlet' | 'leviathan' | 'whisperer' | 'theatreOfBlood' | 'theatreOfBloodHardMode' | 'thermonuclearSmokeDevil' | 'tombsOfAmascut' | 'tombsOfAmascutExpertMode' | 'tzKalZuk' | 'tzTokJad' | 'vardorvis' | 'venenatis' | 'vetion' | 'vorkath' | 'wintertodt' | 'zalcano' | 'zulrah';
|
24
|
+
export type Boss = 'abyssalSire' | 'alchemicalHydra' | 'artio' | 'barrows' | 'bryophyta' | 'callisto' | 'calvarion' | 'cerberus' | 'chambersOfXeric' | 'chambersOfXericChallengeMode' | 'chaosElemental' | 'chaosFanatic' | 'commanderZilyana' | 'corporealBeast' | 'crazyArchaeologist' | 'dagannothPrime' | 'dagannothRex' | 'dagannothSupreme' | 'derangedArchaeologist' | 'dukeSucellus' | 'generalGraardor' | 'giantMole' | 'grotesqueGuardians' | 'hespori' | 'kalphiteQueen' | 'kingBlackDragon' | 'kraken' | 'kreeArra' | 'krilTsutsaroth' | 'mimic' | 'nex' | 'nightmare' | 'phosanisNightmare' | 'obor' | 'phantomMuspah' | 'sarachnis' | 'scorpia' | 'scurrius' | 'skotizo' | 'spindel' | 'tempoross' | 'gauntlet' | 'corruptedGauntlet' | 'leviathan' | 'whisperer' | 'theatreOfBlood' | 'theatreOfBloodHardMode' | 'thermonuclearSmokeDevil' | 'tombsOfAmascut' | 'tombsOfAmascutExpertMode' | 'tzKalZuk' | 'tzTokJad' | 'vardorvis' | 'venenatis' | 'vetion' | 'vorkath' | 'wintertodt' | 'zalcano' | 'zulrah';
|
25
25
|
export type Bosses = {
|
26
26
|
[Type in Boss]: Activity;
|
27
27
|
};
|
28
|
-
export type ActivityName = 'leaguePoints' | 'hunterBHV2' | 'rogueBHV2' | 'hunterBH' | 'rogueBH' | 'lastManStanding' | 'pvpArena' | 'soulWarsZeal' | 'riftsClosed' | 'allClues' | 'beginnerClues' | 'easyClues' | 'mediumClues' | 'hardClues' | 'eliteClues' | 'masterClues' | Boss;
|
28
|
+
export type ActivityName = 'leaguePoints' | 'deadmanPoints' | 'hunterBHV2' | 'rogueBHV2' | 'hunterBH' | 'rogueBH' | 'lastManStanding' | 'pvpArena' | 'soulWarsZeal' | 'riftsClosed' | 'allClues' | 'beginnerClues' | 'easyClues' | 'mediumClues' | 'hardClues' | 'eliteClues' | 'masterClues' | Boss;
|
29
29
|
export interface Stats {
|
30
30
|
skills: Skills;
|
31
31
|
clues: Clues;
|
32
|
+
/**
|
33
|
+
* Will only contain rank and score data for the `seasonal` gamemode.
|
34
|
+
*/
|
32
35
|
leaguePoints: Activity;
|
36
|
+
/**
|
37
|
+
* Will only contain rank and score data for the `tournament` gamemode.
|
38
|
+
*/
|
39
|
+
deadmanPoints: Activity;
|
33
40
|
bountyHunter: BH;
|
34
41
|
lastManStanding: Activity;
|
35
42
|
pvpArena: Activity;
|
package/lib/utils/constants.d.ts
CHANGED
@@ -33,6 +33,7 @@ export declare const FORMATTED_LMS = "LMS - Rank";
|
|
33
33
|
export declare const FORMATTED_PVP_ARENA = "PvP Arena - Rank";
|
34
34
|
export declare const FORMATTED_SOUL_WARS = "Soul Wars Zeal";
|
35
35
|
export declare const FORMATTED_LEAGUE_POINTS = "League Points";
|
36
|
+
export declare const FORMATTED_DEADMAN_POINTS = "Deadman Points";
|
36
37
|
export declare const FORMATTED_RIFTS_CLOSED = "Rifts closed";
|
37
38
|
export declare const INVALID_FORMAT_ERROR = "Invalid hiscores format";
|
38
39
|
export declare const PLAYER_NOT_FOUND_ERROR = "Player not found";
|
package/lib/utils/constants.js
CHANGED
@@ -24,7 +24,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
24
24
|
return to.concat(ar || Array.prototype.slice.call(from));
|
25
25
|
};
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
-
exports.HiScoresError = exports.PlayerNotFoundError = exports.InvalidRSNError = exports.InvalidFormatError = exports.HISCORES_ERROR = exports.PLAYER_NOT_FOUND_ERROR = exports.INVALID_FORMAT_ERROR = exports.FORMATTED_RIFTS_CLOSED = exports.FORMATTED_LEAGUE_POINTS = exports.FORMATTED_SOUL_WARS = exports.FORMATTED_PVP_ARENA = exports.FORMATTED_LMS = exports.FORMATTED_BH_NAMES = exports.FORMATTED_CLUE_NAMES = exports.FORMATTED_SKILL_NAMES = exports.FORMATTED_BOSS_NAMES = exports.ACTIVITIES = exports.BOSSES = exports.GAMEMODES = exports.BH_MODES = exports.CLUES = exports.SKILLS = exports.GAMEMODE_URL = exports.SCORES_URL = exports.JSON_STATS_URL = exports.STATS_URL = exports.BASE_URL = void 0;
|
27
|
+
exports.HiScoresError = exports.PlayerNotFoundError = exports.InvalidRSNError = exports.InvalidFormatError = exports.HISCORES_ERROR = exports.PLAYER_NOT_FOUND_ERROR = exports.INVALID_FORMAT_ERROR = exports.FORMATTED_RIFTS_CLOSED = exports.FORMATTED_DEADMAN_POINTS = exports.FORMATTED_LEAGUE_POINTS = exports.FORMATTED_SOUL_WARS = exports.FORMATTED_PVP_ARENA = exports.FORMATTED_LMS = exports.FORMATTED_BH_NAMES = exports.FORMATTED_CLUE_NAMES = exports.FORMATTED_SKILL_NAMES = exports.FORMATTED_BOSS_NAMES = exports.ACTIVITIES = exports.BOSSES = exports.GAMEMODES = exports.BH_MODES = exports.CLUES = exports.SKILLS = exports.GAMEMODE_URL = exports.SCORES_URL = exports.JSON_STATS_URL = exports.STATS_URL = exports.BASE_URL = void 0;
|
28
28
|
exports.BASE_URL = 'https://secure.runescape.com/m=hiscore_oldschool';
|
29
29
|
exports.STATS_URL = 'index_lite.ws?player=';
|
30
30
|
exports.JSON_STATS_URL = 'index_lite.json?player=';
|
@@ -124,6 +124,7 @@ exports.BOSSES = [
|
|
124
124
|
'phantomMuspah',
|
125
125
|
'sarachnis',
|
126
126
|
'scorpia',
|
127
|
+
'scurrius',
|
127
128
|
'skotizo',
|
128
129
|
'spindel',
|
129
130
|
'tempoross',
|
@@ -148,6 +149,7 @@ exports.BOSSES = [
|
|
148
149
|
];
|
149
150
|
exports.ACTIVITIES = __spreadArray([
|
150
151
|
'leaguePoints',
|
152
|
+
'deadmanPoints',
|
151
153
|
'hunterBHV2',
|
152
154
|
'rogueBHV2',
|
153
155
|
'hunterBH',
|
@@ -202,6 +204,7 @@ exports.FORMATTED_BOSS_NAMES = {
|
|
202
204
|
phantomMuspah: 'Phantom Muspah',
|
203
205
|
sarachnis: 'Sarachnis',
|
204
206
|
scorpia: 'Scorpia',
|
207
|
+
scurrius: 'Scurrius',
|
205
208
|
skotizo: 'Skotizo',
|
206
209
|
spindel: 'Spindel',
|
207
210
|
tempoross: 'Tempoross',
|
@@ -269,6 +272,7 @@ exports.FORMATTED_LMS = 'LMS - Rank';
|
|
269
272
|
exports.FORMATTED_PVP_ARENA = 'PvP Arena - Rank';
|
270
273
|
exports.FORMATTED_SOUL_WARS = 'Soul Wars Zeal';
|
271
274
|
exports.FORMATTED_LEAGUE_POINTS = 'League Points';
|
275
|
+
exports.FORMATTED_DEADMAN_POINTS = 'Deadman Points';
|
272
276
|
exports.FORMATTED_RIFTS_CLOSED = 'Rifts closed';
|
273
277
|
exports.INVALID_FORMAT_ERROR = 'Invalid hiscores format';
|
274
278
|
exports.PLAYER_NOT_FOUND_ERROR = 'Player not found';
|