osrs-json-hiscores 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -125,9 +125,11 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
125
125
  | --------------------------------- | :----------------------------: |
126
126
  | Abyssal Sire | `abyssalSire` |
127
127
  | Alchemical Hydra | `alchemicalHydra` |
128
+ | Artio | `artio` |
128
129
  | Barrows Chests | `barrows` |
129
130
  | Bryophyta | `bryophyta` |
130
131
  | Callisto | `callisto` |
132
+ | Cal'varion | `calvarion` |
131
133
  | Cerberus | `cerberus` |
132
134
  | Chambers Of Xeric | `chambersOfXeric` |
133
135
  | Chambers Of Xeric: Challenge Mode | `chambersOfXericChallengeMode` |
@@ -158,6 +160,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
158
160
  | Sarachnis | `sarachnis` |
159
161
  | Scorpia | `scorpia` |
160
162
  | Skotizo | `skotizo` |
163
+ | Spindel | `spindel` |
161
164
  | Tempoross | `tempoross` |
162
165
  | The Gauntlet | `gauntlet` |
163
166
  | The Corrupted Gauntlet | `corruptedGauntlet` |
package/lib/hiscores.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Player, Stats, Gamemode, SkillName, PlayerSkillRow, ActivityName, PlayerActivityRow } from './types';
1
+ import { Player, Stats, Gamemode, SkillName, PlayerSkillRow, ActivityName, PlayerActivityRow, GetStatsOptions } from './types';
2
2
  /**
3
3
  * Screen scrapes the hiscores to get the formatted rsn of a player.
4
4
  *
@@ -22,7 +22,7 @@ export declare function parseStats(csv: string): Stats;
22
22
  * @param rsn Username of the player.
23
23
  * @returns Player object.
24
24
  */
25
- export declare function getStats(rsn: string): Promise<Player>;
25
+ export declare function getStats(rsn: string, options?: GetStatsOptions): Promise<Player>;
26
26
  /**
27
27
  * Fetches stats from the OSRS API and returns them as an object.
28
28
  *
package/lib/hiscores.js CHANGED
@@ -62,15 +62,7 @@ function getRSNFormat(rsn) {
62
62
  return __generator(this, function (_b) {
63
63
  switch (_b.label) {
64
64
  case 0:
65
- if (typeof rsn !== 'string') {
66
- throw Error('RSN must be a string');
67
- }
68
- else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
69
- throw Error('RSN contains invalid character');
70
- }
71
- else if (rsn.length > 12 || rsn.length < 1) {
72
- throw Error('RSN must be between 1 and 12 characters');
73
- }
65
+ utils_1.validateRSN(rsn);
74
66
  url = utils_1.getPlayerTableURL('main', rsn);
75
67
  _b.label = 1;
76
68
  case 1:
@@ -177,34 +169,49 @@ exports.parseStats = parseStats;
177
169
  * @param rsn Username of the player.
178
170
  * @returns Player object.
179
171
  */
180
- function getStats(rsn) {
172
+ function getStats(rsn, options) {
173
+ var _a, _b;
181
174
  return __awaiter(this, void 0, void 0, function () {
182
- var mainRes, otherResponses, ironRes, hcRes, ultRes, formattedName, player;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
175
+ var otherGamemodes, shouldGetFormattedRsn, mainRes, emptyResponse_1, getModeStats, formattedName, _c, player, ironRes, hcRes, ultRes;
176
+ var _this = this;
177
+ return __generator(this, function (_d) {
178
+ switch (_d.label) {
185
179
  case 0:
186
- if (typeof rsn !== 'string') {
187
- throw Error('RSN must be a string');
188
- }
189
- else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
190
- throw Error('RSN contains invalid character');
191
- }
192
- else if (rsn.length > 12 || rsn.length < 1) {
193
- throw Error('RSN must be between 1 and 12 characters');
194
- }
180
+ utils_1.validateRSN(rsn);
181
+ otherGamemodes = (_a = options === null || options === void 0 ? void 0 : options.otherGamemodes) !== null && _a !== void 0 ? _a : [
182
+ 'ironman',
183
+ 'hardcore',
184
+ 'ultimate'
185
+ ];
186
+ shouldGetFormattedRsn = (_b = options === null || options === void 0 ? void 0 : options.shouldGetFormattedRsn) !== null && _b !== void 0 ? _b : true;
195
187
  return [4 /*yield*/, utils_1.httpGet(utils_1.getStatsURL('main', rsn))];
196
188
  case 1:
197
- mainRes = _a.sent();
198
- if (!(mainRes.status === 200)) return [3 /*break*/, 3];
199
- return [4 /*yield*/, Promise.all([
200
- utils_1.httpGet(utils_1.getStatsURL('ironman', rsn)).catch(function (err) { return err; }),
201
- utils_1.httpGet(utils_1.getStatsURL('hardcore', rsn)).catch(function (err) { return err; }),
202
- utils_1.httpGet(utils_1.getStatsURL('ultimate', rsn)).catch(function (err) { return err; }),
203
- getRSNFormat(rsn).catch(function () { return undefined; })
204
- ])];
189
+ mainRes = _d.sent();
190
+ if (!(mainRes.status === 200)) return [3 /*break*/, 9];
191
+ emptyResponse_1 = {
192
+ status: 404,
193
+ data: '',
194
+ statusText: '',
195
+ headers: {},
196
+ config: {}
197
+ };
198
+ getModeStats = function (mode) { return __awaiter(_this, void 0, void 0, function () {
199
+ return __generator(this, function (_a) {
200
+ return [2 /*return*/, otherGamemodes.includes(mode)
201
+ ? utils_1.httpGet(utils_1.getStatsURL(mode, rsn)).catch(function (err) { return err; })
202
+ : emptyResponse_1];
203
+ });
204
+ }); };
205
+ if (!shouldGetFormattedRsn) return [3 /*break*/, 3];
206
+ return [4 /*yield*/, getRSNFormat(rsn).catch(function () { return undefined; })];
205
207
  case 2:
206
- otherResponses = _a.sent();
207
- ironRes = otherResponses[0], hcRes = otherResponses[1], ultRes = otherResponses[2], formattedName = otherResponses[3];
208
+ _c = _d.sent();
209
+ return [3 /*break*/, 4];
210
+ case 3:
211
+ _c = undefined;
212
+ _d.label = 4;
213
+ case 4:
214
+ formattedName = _c;
208
215
  player = {
209
216
  name: formattedName !== null && formattedName !== void 0 ? formattedName : rsn,
210
217
  mode: 'main',
@@ -213,42 +220,51 @@ function getStats(rsn) {
213
220
  deironed: false
214
221
  };
215
222
  player.main = parseStats(mainRes.data);
216
- if (ironRes.status === 200) {
217
- player.ironman = parseStats(ironRes.data);
218
- if (hcRes.status === 200) {
219
- player.mode = 'hardcore';
220
- player.hardcore = parseStats(hcRes.data);
221
- if (player.ironman.skills.overall.xp !== player.hardcore.skills.overall.xp) {
222
- player.dead = true;
223
- player.mode = 'ironman';
224
- }
225
- if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
226
- player.deironed = true;
227
- player.mode = 'main';
228
- }
223
+ return [4 /*yield*/, getModeStats('ironman')];
224
+ case 5:
225
+ ironRes = _d.sent();
226
+ if (!(ironRes.status === 200)) return [3 /*break*/, 8];
227
+ player.ironman = parseStats(ironRes.data);
228
+ return [4 /*yield*/, getModeStats('hardcore')];
229
+ case 6:
230
+ hcRes = _d.sent();
231
+ return [4 /*yield*/, getModeStats('ultimate')];
232
+ case 7:
233
+ ultRes = _d.sent();
234
+ if (hcRes.status === 200) {
235
+ player.mode = 'hardcore';
236
+ player.hardcore = parseStats(hcRes.data);
237
+ if (player.ironman.skills.overall.xp !== player.hardcore.skills.overall.xp) {
238
+ player.dead = true;
239
+ player.mode = 'ironman';
229
240
  }
230
- else if (ultRes.status === 200) {
231
- player.mode = 'ultimate';
232
- player.ultimate = parseStats(ultRes.data);
233
- if (player.ironman.skills.overall.xp !== player.ultimate.skills.overall.xp) {
234
- player.deulted = true;
235
- player.mode = 'ironman';
236
- }
237
- if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
238
- player.deironed = true;
239
- player.mode = 'main';
240
- }
241
+ if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
242
+ player.deironed = true;
243
+ player.mode = 'main';
241
244
  }
242
- else {
245
+ }
246
+ else if (ultRes.status === 200) {
247
+ player.mode = 'ultimate';
248
+ player.ultimate = parseStats(ultRes.data);
249
+ if (player.ironman.skills.overall.xp !== player.ultimate.skills.overall.xp) {
250
+ player.deulted = true;
243
251
  player.mode = 'ironman';
244
- if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
245
- player.deironed = true;
246
- player.mode = 'main';
247
- }
252
+ }
253
+ if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
254
+ player.deironed = true;
255
+ player.mode = 'main';
256
+ }
257
+ }
258
+ else {
259
+ player.mode = 'ironman';
260
+ if (player.main.skills.overall.xp !== player.ironman.skills.overall.xp) {
261
+ player.deironed = true;
262
+ player.mode = 'main';
248
263
  }
249
264
  }
250
- return [2 /*return*/, player];
251
- case 3: throw Error('Player not found');
265
+ _d.label = 8;
266
+ case 8: return [2 /*return*/, player];
267
+ case 9: throw Error('Player not found');
252
268
  }
253
269
  });
254
270
  });
@@ -268,16 +284,8 @@ function getStatsByGamemode(rsn, mode) {
268
284
  return __generator(this, function (_a) {
269
285
  switch (_a.label) {
270
286
  case 0:
271
- if (typeof rsn !== 'string') {
272
- throw Error('RSN must be a string');
273
- }
274
- else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
275
- throw Error('RSN contains invalid character');
276
- }
277
- else if (rsn.length > 12 || rsn.length < 1) {
278
- throw Error('RSN must be between 1 and 12 characters');
279
- }
280
- else if (!utils_1.GAMEMODES.includes(mode)) {
287
+ utils_1.validateRSN(rsn);
288
+ if (!utils_1.GAMEMODES.includes(mode)) {
281
289
  throw Error('Invalid game mode');
282
290
  }
283
291
  return [4 /*yield*/, utils_1.httpGet(utils_1.getStatsURL(mode, rsn))];
package/lib/types.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare type BHType = 'rogue' | 'hunter';
20
20
  export declare type BH = {
21
21
  [Type in BHType]: Activity;
22
22
  };
23
- export declare type Boss = 'abyssalSire' | 'alchemicalHydra' | 'barrows' | 'bryophyta' | 'callisto' | 'cerberus' | 'chambersOfXeric' | 'chambersOfXericChallengeMode' | 'chaosElemental' | 'chaosFanatic' | 'commanderZilyana' | 'corporealBeast' | 'crazyArchaeologist' | 'dagannothPrime' | 'dagannothRex' | 'dagannothSupreme' | 'derangedArchaeologist' | 'generalGraardor' | 'giantMole' | 'grotesqueGuardians' | 'hespori' | 'kalphiteQueen' | 'kingBlackDragon' | 'kraken' | 'kreeArra' | 'krilTsutsaroth' | 'mimic' | 'nex' | 'nightmare' | 'phosanisNightmare' | 'obor' | 'phantomMuspah' | 'sarachnis' | 'scorpia' | 'skotizo' | 'tempoross' | 'gauntlet' | 'corruptedGauntlet' | 'theatreOfBlood' | 'theatreOfBloodHardMode' | 'thermonuclearSmokeDevil' | 'tombsOfAmascut' | 'tombsOfAmascutExpertMode' | 'tzKalZuk' | 'tzTokJad' | 'venenatis' | 'vetion' | 'vorkath' | 'wintertodt' | 'zalcano' | 'zulrah';
23
+ export declare type Boss = 'abyssalSire' | 'alchemicalHydra' | 'artio' | 'barrows' | 'bryophyta' | 'callisto' | 'calvarion' | 'cerberus' | 'chambersOfXeric' | 'chambersOfXericChallengeMode' | 'chaosElemental' | 'chaosFanatic' | 'commanderZilyana' | 'corporealBeast' | 'crazyArchaeologist' | 'dagannothPrime' | 'dagannothRex' | 'dagannothSupreme' | 'derangedArchaeologist' | 'generalGraardor' | 'giantMole' | 'grotesqueGuardians' | 'hespori' | 'kalphiteQueen' | 'kingBlackDragon' | 'kraken' | 'kreeArra' | 'krilTsutsaroth' | 'mimic' | 'nex' | 'nightmare' | 'phosanisNightmare' | 'obor' | 'phantomMuspah' | 'sarachnis' | 'scorpia' | 'skotizo' | 'spindel' | 'tempoross' | 'gauntlet' | 'corruptedGauntlet' | 'theatreOfBlood' | 'theatreOfBloodHardMode' | 'thermonuclearSmokeDevil' | 'tombsOfAmascut' | 'tombsOfAmascutExpertMode' | 'tzKalZuk' | 'tzTokJad' | 'venenatis' | 'vetion' | 'vorkath' | 'wintertodt' | 'zalcano' | 'zulrah';
24
24
  export declare type Bosses = {
25
25
  [Type in Boss]: Activity;
26
26
  };
@@ -54,3 +54,15 @@ export interface PlayerActivityRow extends Activity {
54
54
  name: string;
55
55
  dead: boolean;
56
56
  }
57
+ export interface GetStatsOptions {
58
+ /**
59
+ * Other game modes to fetch ranks for.
60
+ * @defaultvalue `['ironman', 'hardcore', 'ultimate']`
61
+ */
62
+ otherGamemodes?: Extract<Gamemode, 'ironman' | 'hardcore' | 'ultimate'>[];
63
+ /**
64
+ * If true, the formatted RSN will be fetched. Otherwise it will return the provided, unformatted RSN.
65
+ * @defaultvalue `true`
66
+ */
67
+ shouldGetFormattedRsn?: boolean;
68
+ }
@@ -69,9 +69,11 @@ exports.GAMEMODES = [
69
69
  exports.BOSSES = [
70
70
  'abyssalSire',
71
71
  'alchemicalHydra',
72
+ 'artio',
72
73
  'barrows',
73
74
  'bryophyta',
74
75
  'callisto',
76
+ 'calvarion',
75
77
  'cerberus',
76
78
  'chambersOfXeric',
77
79
  'chambersOfXericChallengeMode',
@@ -102,6 +104,7 @@ exports.BOSSES = [
102
104
  'sarachnis',
103
105
  'scorpia',
104
106
  'skotizo',
107
+ 'spindel',
105
108
  'tempoross',
106
109
  'gauntlet',
107
110
  'corruptedGauntlet',
@@ -138,9 +141,11 @@ exports.ACTIVITIES = __spreadArray([
138
141
  exports.FORMATTED_BOSS_NAMES = {
139
142
  abyssalSire: 'Abyssal Sire',
140
143
  alchemicalHydra: 'Alchemical Hydra',
144
+ artio: 'Artio',
141
145
  barrows: 'Barrows Chests',
142
146
  bryophyta: 'Bryophyta',
143
147
  callisto: 'Callisto',
148
+ calvarion: "Cal'varion",
144
149
  cerberus: 'Cerberus',
145
150
  chambersOfXeric: 'Chambers of Xeric',
146
151
  chambersOfXericChallengeMode: 'Chambers of Xeric: Challenge Mode',
@@ -171,6 +176,7 @@ exports.FORMATTED_BOSS_NAMES = {
171
176
  sarachnis: 'Sarachnis',
172
177
  scorpia: 'Scorpia',
173
178
  skotizo: 'Skotizo',
179
+ spindel: 'Spindel',
174
180
  tempoross: 'Tempoross',
175
181
  gauntlet: 'The Gauntlet',
176
182
  corruptedGauntlet: 'The Corrupted Gauntlet',
@@ -53,4 +53,10 @@ export declare const rsnFromElement: (el: Element | null) => string;
53
53
  * @param url URL to run a `GET` request against.
54
54
  * @returns Axios response.
55
55
  */
56
- export declare const httpGet: (url: string) => Promise<import("axios").AxiosResponse<any>>;
56
+ export declare const httpGet: <Response_1>(url: string) => Promise<import("axios").AxiosResponse<Response_1>>;
57
+ /**
58
+ * Validates that a provided RSN has the same username restrictions as Jagex.
59
+ * @param rsn Username to validate.
60
+ * @throws Error if the RSN fails validation.
61
+ */
62
+ export declare const validateRSN: (rsn: string) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
3
+ exports.validateRSN = exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
4
4
  var axios_1 = require("axios");
5
5
  var ua = require("useragent-generator");
6
6
  var constants_1 = require("./constants");
@@ -90,3 +90,20 @@ var httpGet = function (url) {
90
90
  });
91
91
  };
92
92
  exports.httpGet = httpGet;
93
+ /**
94
+ * Validates that a provided RSN has the same username restrictions as Jagex.
95
+ * @param rsn Username to validate.
96
+ * @throws Error if the RSN fails validation.
97
+ */
98
+ var validateRSN = function (rsn) {
99
+ if (typeof rsn !== 'string') {
100
+ throw Error('RSN must be a string');
101
+ }
102
+ else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
103
+ throw Error('RSN contains invalid character');
104
+ }
105
+ else if (rsn.length > 12 || rsn.length < 1) {
106
+ throw Error('RSN must be between 1 and 12 characters');
107
+ }
108
+ };
109
+ exports.validateRSN = validateRSN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osrs-json-hiscores",
3
- "version": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "description": "The Old School Runescape API wrapper that does more!",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -30,6 +30,9 @@
30
30
  "stats",
31
31
  "skills"
32
32
  ],
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org"
35
+ },
33
36
  "author": "maxswa",
34
37
  "license": "ISC",
35
38
  "bugs": {
@@ -106,7 +109,7 @@
106
109
  "husky": "^5.2.0",
107
110
  "jest": "^26.6.3",
108
111
  "lint-staged": "^10.5.4",
109
- "np": "6.5.0",
112
+ "np": "^7.7.0",
110
113
  "prettier": "^2.2.1",
111
114
  "ts-jest": "^26.5.4",
112
115
  "typescript": "^4.2.3"