osrs-json-hiscores 2.16.1 → 2.16.2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/hiscores.js +28 -30
- package/lib/utils/constants.d.ts +17 -0
- package/lib/utils/constants.js +61 -1
- package/lib/utils/helpers.js +3 -3
- package/package.json +5 -2
package/lib/hiscores.js
CHANGED
@@ -48,6 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
48
48
|
};
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
50
50
|
exports.getActivityPage = exports.getSkillPage = exports.getStatsByGamemode = exports.getStats = exports.parseStats = exports.parseJsonStats = exports.getRSNFormat = exports.getOfficialStats = void 0;
|
51
|
+
var axios_1 = require("axios");
|
51
52
|
var jsdom_1 = require("jsdom");
|
52
53
|
var utils_1 = require("./utils");
|
53
54
|
/**
|
@@ -59,9 +60,10 @@ var utils_1 = require("./utils");
|
|
59
60
|
* @returns Official JSON stats object.
|
60
61
|
*/
|
61
62
|
function getOfficialStats(rsn, mode, config) {
|
63
|
+
var _a;
|
62
64
|
if (mode === void 0) { mode = 'main'; }
|
63
65
|
return __awaiter(this, void 0, void 0, function () {
|
64
|
-
var url, response,
|
66
|
+
var url, response, err_1;
|
65
67
|
return __generator(this, function (_b) {
|
66
68
|
switch (_b.label) {
|
67
69
|
case 0:
|
@@ -75,8 +77,12 @@ function getOfficialStats(rsn, mode, config) {
|
|
75
77
|
response = _b.sent();
|
76
78
|
return [2 /*return*/, response.data];
|
77
79
|
case 3:
|
78
|
-
|
79
|
-
|
80
|
+
err_1 = _b.sent();
|
81
|
+
if (!axios_1.default.isAxiosError(err_1))
|
82
|
+
throw err_1;
|
83
|
+
if (((_a = err_1.response) === null || _a === void 0 ? void 0 : _a.status) === 404)
|
84
|
+
throw new utils_1.PlayerNotFoundError();
|
85
|
+
throw new utils_1.HiScoresError();
|
80
86
|
case 4: return [2 /*return*/];
|
81
87
|
}
|
82
88
|
});
|
@@ -109,10 +115,10 @@ function getRSNFormat(rsn, config) {
|
|
109
115
|
if (anchor) {
|
110
116
|
return [2 /*return*/, (0, utils_1.rsnFromElement)(anchor)];
|
111
117
|
}
|
112
|
-
throw
|
118
|
+
throw new utils_1.PlayerNotFoundError();
|
113
119
|
case 3:
|
114
120
|
_a = _b.sent();
|
115
|
-
throw
|
121
|
+
throw new utils_1.HiScoresError();
|
116
122
|
case 4: return [2 /*return*/];
|
117
123
|
}
|
118
124
|
});
|
@@ -195,7 +201,7 @@ function parseStats(csv) {
|
|
195
201
|
.map(function (stat) { return stat.split(','); });
|
196
202
|
if (splitCSV.length !==
|
197
203
|
utils_1.SKILLS.length + utils_1.BH_MODES.length + utils_1.CLUES.length + utils_1.BOSSES.length + 5) {
|
198
|
-
throw
|
204
|
+
throw new utils_1.InvalidFormatError();
|
199
205
|
}
|
200
206
|
var skillObjects = splitCSV
|
201
207
|
.filter(function (stat) { return stat.length === 3; })
|
@@ -269,7 +275,7 @@ exports.parseStats = parseStats;
|
|
269
275
|
function getStats(rsn, options) {
|
270
276
|
var _a, _b, _c, _d;
|
271
277
|
return __awaiter(this, void 0, void 0, function () {
|
272
|
-
var otherGamemodes, shouldGetFormattedRsn,
|
278
|
+
var otherGamemodes, shouldGetFormattedRsn, main, getModeStats, formattedName, _e, player, iron, hc, ult;
|
273
279
|
var _this = this;
|
274
280
|
return __generator(this, function (_f) {
|
275
281
|
switch (_f.label) {
|
@@ -281,23 +287,16 @@ function getStats(rsn, options) {
|
|
281
287
|
'ultimate'
|
282
288
|
];
|
283
289
|
shouldGetFormattedRsn = (_b = options === null || options === void 0 ? void 0 : options.shouldGetFormattedRsn) !== null && _b !== void 0 ? _b : true;
|
284
|
-
return [4 /*yield*/, (
|
290
|
+
return [4 /*yield*/, getOfficialStats(rsn, 'main', (_c = options === null || options === void 0 ? void 0 : options.axiosConfigs) === null || _c === void 0 ? void 0 : _c.main)];
|
285
291
|
case 1:
|
286
|
-
|
287
|
-
if (!(mainRes.status === 200)) return [3 /*break*/, 9];
|
288
|
-
emptyResponse_1 = {
|
289
|
-
status: 404,
|
290
|
-
data: { skills: [], activities: [] },
|
291
|
-
statusText: '',
|
292
|
-
headers: {},
|
293
|
-
config: {}
|
294
|
-
};
|
292
|
+
main = _f.sent();
|
295
293
|
getModeStats = function (mode) { return __awaiter(_this, void 0, void 0, function () {
|
296
294
|
var _a;
|
297
295
|
return __generator(this, function (_b) {
|
298
296
|
return [2 /*return*/, otherGamemodes.includes(mode)
|
299
|
-
? (
|
300
|
-
|
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
|
+
: undefined];
|
301
300
|
});
|
302
301
|
}); };
|
303
302
|
if (!shouldGetFormattedRsn) return [3 /*break*/, 3];
|
@@ -317,21 +316,21 @@ function getStats(rsn, options) {
|
|
317
316
|
deulted: false,
|
318
317
|
deironed: false
|
319
318
|
};
|
320
|
-
player.main = parseJsonStats(
|
319
|
+
player.main = parseJsonStats(main);
|
321
320
|
return [4 /*yield*/, getModeStats('ironman')];
|
322
321
|
case 5:
|
323
|
-
|
324
|
-
if (!
|
325
|
-
player.ironman = parseJsonStats(
|
322
|
+
iron = _f.sent();
|
323
|
+
if (!iron) return [3 /*break*/, 8];
|
324
|
+
player.ironman = parseJsonStats(iron);
|
326
325
|
return [4 /*yield*/, getModeStats('hardcore')];
|
327
326
|
case 6:
|
328
|
-
|
327
|
+
hc = _f.sent();
|
329
328
|
return [4 /*yield*/, getModeStats('ultimate')];
|
330
329
|
case 7:
|
331
|
-
|
332
|
-
if (
|
330
|
+
ult = _f.sent();
|
331
|
+
if (hc) {
|
333
332
|
player.mode = 'hardcore';
|
334
|
-
player.hardcore = parseJsonStats(
|
333
|
+
player.hardcore = parseJsonStats(hc);
|
335
334
|
if (player.ironman.skills.overall.xp !== player.hardcore.skills.overall.xp) {
|
336
335
|
player.dead = true;
|
337
336
|
player.mode = 'ironman';
|
@@ -341,9 +340,9 @@ function getStats(rsn, options) {
|
|
341
340
|
player.mode = 'main';
|
342
341
|
}
|
343
342
|
}
|
344
|
-
else if (
|
343
|
+
else if (ult) {
|
345
344
|
player.mode = 'ultimate';
|
346
|
-
player.ultimate = parseJsonStats(
|
345
|
+
player.ultimate = parseJsonStats(ult);
|
347
346
|
if (player.ironman.skills.overall.xp !== player.ultimate.skills.overall.xp) {
|
348
347
|
player.deulted = true;
|
349
348
|
player.mode = 'ironman';
|
@@ -362,7 +361,6 @@ function getStats(rsn, options) {
|
|
362
361
|
}
|
363
362
|
_f.label = 8;
|
364
363
|
case 8: return [2 /*return*/, player];
|
365
|
-
case 9: throw Error(utils_1.PLAYER_NOT_FOUND_ERROR);
|
366
364
|
}
|
367
365
|
});
|
368
366
|
});
|
package/lib/utils/constants.d.ts
CHANGED
@@ -36,3 +36,20 @@ export declare const FORMATTED_LEAGUE_POINTS = "League Points";
|
|
36
36
|
export declare const FORMATTED_RIFTS_CLOSED = "Rifts closed";
|
37
37
|
export declare const INVALID_FORMAT_ERROR = "Invalid hiscores format";
|
38
38
|
export declare const PLAYER_NOT_FOUND_ERROR = "Player not found";
|
39
|
+
export declare const HISCORES_ERROR = "HiScores not responding";
|
40
|
+
export declare class InvalidFormatError extends Error {
|
41
|
+
__proto__: ErrorConstructor;
|
42
|
+
constructor();
|
43
|
+
}
|
44
|
+
export declare class InvalidRSNError extends Error {
|
45
|
+
__proto__: ErrorConstructor;
|
46
|
+
constructor(message: string);
|
47
|
+
}
|
48
|
+
export declare class PlayerNotFoundError extends Error {
|
49
|
+
__proto__: ErrorConstructor;
|
50
|
+
constructor();
|
51
|
+
}
|
52
|
+
export declare class HiScoresError extends Error {
|
53
|
+
__proto__: ErrorConstructor;
|
54
|
+
constructor();
|
55
|
+
}
|
package/lib/utils/constants.js
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
3
|
+
var extendStatics = function (d, b) {
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
+
return extendStatics(d, b);
|
8
|
+
};
|
9
|
+
return function (d, b) {
|
10
|
+
if (typeof b !== "function" && b !== null)
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
+
extendStatics(d, b);
|
13
|
+
function __() { this.constructor = d; }
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
+
};
|
16
|
+
})();
|
2
17
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
3
18
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4
19
|
if (ar || !(i in from)) {
|
@@ -9,7 +24,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
9
24
|
return to.concat(ar || Array.prototype.slice.call(from));
|
10
25
|
};
|
11
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
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_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;
|
13
28
|
exports.BASE_URL = 'https://secure.runescape.com/m=hiscore_oldschool';
|
14
29
|
exports.STATS_URL = 'index_lite.ws?player=';
|
15
30
|
exports.JSON_STATS_URL = 'index_lite.json?player=';
|
@@ -257,3 +272,48 @@ exports.FORMATTED_LEAGUE_POINTS = 'League Points';
|
|
257
272
|
exports.FORMATTED_RIFTS_CLOSED = 'Rifts closed';
|
258
273
|
exports.INVALID_FORMAT_ERROR = 'Invalid hiscores format';
|
259
274
|
exports.PLAYER_NOT_FOUND_ERROR = 'Player not found';
|
275
|
+
exports.HISCORES_ERROR = 'HiScores not responding';
|
276
|
+
var InvalidFormatError = /** @class */ (function (_super) {
|
277
|
+
__extends(InvalidFormatError, _super);
|
278
|
+
function InvalidFormatError() {
|
279
|
+
var _this = _super.call(this, exports.INVALID_FORMAT_ERROR) || this;
|
280
|
+
_this.__proto__ = Error;
|
281
|
+
Object.setPrototypeOf(_this, InvalidFormatError.prototype);
|
282
|
+
return _this;
|
283
|
+
}
|
284
|
+
return InvalidFormatError;
|
285
|
+
}(Error));
|
286
|
+
exports.InvalidFormatError = InvalidFormatError;
|
287
|
+
var InvalidRSNError = /** @class */ (function (_super) {
|
288
|
+
__extends(InvalidRSNError, _super);
|
289
|
+
function InvalidRSNError(message) {
|
290
|
+
var _this = _super.call(this, message) || this;
|
291
|
+
_this.__proto__ = Error;
|
292
|
+
Object.setPrototypeOf(_this, InvalidRSNError.prototype);
|
293
|
+
return _this;
|
294
|
+
}
|
295
|
+
return InvalidRSNError;
|
296
|
+
}(Error));
|
297
|
+
exports.InvalidRSNError = InvalidRSNError;
|
298
|
+
var PlayerNotFoundError = /** @class */ (function (_super) {
|
299
|
+
__extends(PlayerNotFoundError, _super);
|
300
|
+
function PlayerNotFoundError() {
|
301
|
+
var _this = _super.call(this, exports.PLAYER_NOT_FOUND_ERROR) || this;
|
302
|
+
_this.__proto__ = Error;
|
303
|
+
Object.setPrototypeOf(_this, PlayerNotFoundError.prototype);
|
304
|
+
return _this;
|
305
|
+
}
|
306
|
+
return PlayerNotFoundError;
|
307
|
+
}(Error));
|
308
|
+
exports.PlayerNotFoundError = PlayerNotFoundError;
|
309
|
+
var HiScoresError = /** @class */ (function (_super) {
|
310
|
+
__extends(HiScoresError, _super);
|
311
|
+
function HiScoresError() {
|
312
|
+
var _this = _super.call(this, exports.HISCORES_ERROR) || this;
|
313
|
+
_this.__proto__ = Error;
|
314
|
+
Object.setPrototypeOf(_this, HiScoresError.prototype);
|
315
|
+
return _this;
|
316
|
+
}
|
317
|
+
return HiScoresError;
|
318
|
+
}(Error));
|
319
|
+
exports.HiScoresError = HiScoresError;
|
package/lib/utils/helpers.js
CHANGED
@@ -109,13 +109,13 @@ exports.httpGet = httpGet;
|
|
109
109
|
*/
|
110
110
|
var validateRSN = function (rsn) {
|
111
111
|
if (typeof rsn !== 'string') {
|
112
|
-
throw
|
112
|
+
throw new constants_1.InvalidRSNError('RSN must be a string');
|
113
113
|
}
|
114
114
|
else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
|
115
|
-
throw
|
115
|
+
throw new constants_1.InvalidRSNError('RSN contains invalid character');
|
116
116
|
}
|
117
117
|
else if (rsn.length > 12 || rsn.length < 1) {
|
118
|
-
throw
|
118
|
+
throw new constants_1.InvalidRSNError('RSN must be between 1 and 12 characters');
|
119
119
|
}
|
120
120
|
};
|
121
121
|
exports.validateRSN = validateRSN;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "osrs-json-hiscores",
|
3
|
-
"version": "2.16.
|
3
|
+
"version": "2.16.2",
|
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",
|
@@ -67,7 +67,10 @@
|
|
67
67
|
],
|
68
68
|
"ignorePatterns": [
|
69
69
|
"**/@types/*"
|
70
|
-
]
|
70
|
+
],
|
71
|
+
"rules": {
|
72
|
+
"max-classes-per-file": "off"
|
73
|
+
}
|
71
74
|
},
|
72
75
|
"prettier": {
|
73
76
|
"trailingComma": "none",
|