osrs-json-hiscores 2.14.1 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,119 +1,119 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.validateRSN = exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
15
- var axios_1 = require("axios");
16
- var ua = require("useragent-generator");
17
- var constants_1 = require("./constants");
18
- /**
19
- * Will generate a stats URL for the official OSRS API.
20
- *
21
- * @param gamemode Gamemode to fetch ranks for.
22
- * @param rsn Username of the player.
23
- * @returns Encoded stats URL.
24
- */
25
- var getStatsURL = function (gamemode, rsn) {
26
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.STATS_URL + encodeURIComponent(rsn);
27
- };
28
- exports.getStatsURL = getStatsURL;
29
- /**
30
- * Will generate a player table URL for the official OSRS hiscores website.
31
- *
32
- * @param gamemode Gamemode to fetch ranks for.
33
- * @param rsn Username of the player.
34
- * @returns Encoded player table URL.
35
- */
36
- var getPlayerTableURL = function (gamemode, rsn) {
37
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=0&user=" + encodeURIComponent(rsn);
38
- };
39
- exports.getPlayerTableURL = getPlayerTableURL;
40
- /**
41
- * Will generate a skill table URL for the official OSRS hiscores website.
42
- *
43
- * @param gamemode Gamemode to fetch ranks for.
44
- * @param skill Skill to fetch ranks for.
45
- * @param page Page number.
46
- * @returns
47
- */
48
- var getSkillPageURL = function (gamemode, skill, page) {
49
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=" + constants_1.SKILLS.indexOf(skill) + "&page=" + page;
50
- };
51
- exports.getSkillPageURL = getSkillPageURL;
52
- /**
53
- * Will generate an activity table URL for the official OSRS hiscores website.
54
- *
55
- * @param gamemode Gamemode to fetch ranks for.
56
- * @param activity Activity or boss to fetch ranks for.
57
- * @param page Page number.
58
- * @returns
59
- */
60
- var getActivityPageURL = function (gamemode, activity, page) {
61
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "category_type=1&table=" + constants_1.ACTIVITIES.indexOf(activity) + "&page=" + page;
62
- };
63
- exports.getActivityPageURL = getActivityPageURL;
64
- /**
65
- * Extracts a number from an OSRS hiscores table cell element.
66
- *
67
- * @param el OSRS hiscores table cell element.
68
- * @returns Number parsed from cell text.
69
- */
70
- var numberFromElement = function (el) {
71
- var _a;
72
- var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
73
- var number = (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/[\n|,]/g, '')) !== null && _a !== void 0 ? _a : '-1';
74
- return parseInt(number, 10);
75
- };
76
- exports.numberFromElement = numberFromElement;
77
- /**
78
- * Extracts a RSN from an OSRS hiscores table cell element.
79
- *
80
- * @param el OSRS hiscores table cell element.
81
- * @returns RSN parsed from cell text.
82
- */
83
- var rsnFromElement = function (el) {
84
- var _a;
85
- var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
86
- return (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/\uFFFD/g, ' ')) !== null && _a !== void 0 ? _a : '';
87
- };
88
- exports.rsnFromElement = rsnFromElement;
89
- /**
90
- * Will run an Axios `GET` request against a given URL after injecting a `User-Agent` header.
91
- *
92
- * @param url URL to run a `GET` request against.
93
- * @returns Axios response.
94
- */
95
- var httpGet = function (url, config) {
96
- if (config === void 0) { config = {}; }
97
- return axios_1.default.get(url, __assign({ headers: {
98
- // without User-Agent header requests may be rejected by DDoS protection mechanism
99
- 'User-Agent': ua.firefox(80)
100
- } }, config));
101
- };
102
- exports.httpGet = httpGet;
103
- /**
104
- * Validates that a provided RSN has the same username restrictions as Jagex.
105
- * @param rsn Username to validate.
106
- * @throws Error if the RSN fails validation.
107
- */
108
- var validateRSN = function (rsn) {
109
- if (typeof rsn !== 'string') {
110
- throw Error('RSN must be a string');
111
- }
112
- else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
113
- throw Error('RSN contains invalid character');
114
- }
115
- else if (rsn.length > 12 || rsn.length < 1) {
116
- throw Error('RSN must be between 1 and 12 characters');
117
- }
118
- };
119
- exports.validateRSN = validateRSN;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.validateRSN = exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
15
+ var axios_1 = require("axios");
16
+ var ua = require("useragent-generator");
17
+ var constants_1 = require("./constants");
18
+ /**
19
+ * Will generate a stats URL for the official OSRS API.
20
+ *
21
+ * @param gamemode Gamemode to fetch ranks for.
22
+ * @param rsn Username of the player.
23
+ * @returns Encoded stats URL.
24
+ */
25
+ var getStatsURL = function (gamemode, rsn) {
26
+ return "".concat(constants_1.GAMEMODE_URL[gamemode]).concat(constants_1.STATS_URL).concat(encodeURIComponent(rsn));
27
+ };
28
+ exports.getStatsURL = getStatsURL;
29
+ /**
30
+ * Will generate a player table URL for the official OSRS hiscores website.
31
+ *
32
+ * @param gamemode Gamemode to fetch ranks for.
33
+ * @param rsn Username of the player.
34
+ * @returns Encoded player table URL.
35
+ */
36
+ var getPlayerTableURL = function (gamemode, rsn) {
37
+ return "".concat(constants_1.GAMEMODE_URL[gamemode]).concat(constants_1.SCORES_URL, "table=0&user=").concat(encodeURIComponent(rsn));
38
+ };
39
+ exports.getPlayerTableURL = getPlayerTableURL;
40
+ /**
41
+ * Will generate a skill table URL for the official OSRS hiscores website.
42
+ *
43
+ * @param gamemode Gamemode to fetch ranks for.
44
+ * @param skill Skill to fetch ranks for.
45
+ * @param page Page number.
46
+ * @returns
47
+ */
48
+ var getSkillPageURL = function (gamemode, skill, page) {
49
+ return "".concat(constants_1.GAMEMODE_URL[gamemode]).concat(constants_1.SCORES_URL, "table=").concat(constants_1.SKILLS.indexOf(skill), "&page=").concat(page);
50
+ };
51
+ exports.getSkillPageURL = getSkillPageURL;
52
+ /**
53
+ * Will generate an activity table URL for the official OSRS hiscores website.
54
+ *
55
+ * @param gamemode Gamemode to fetch ranks for.
56
+ * @param activity Activity or boss to fetch ranks for.
57
+ * @param page Page number.
58
+ * @returns
59
+ */
60
+ var getActivityPageURL = function (gamemode, activity, page) {
61
+ return "".concat(constants_1.GAMEMODE_URL[gamemode]).concat(constants_1.SCORES_URL, "category_type=1&table=").concat(constants_1.ACTIVITIES.indexOf(activity), "&page=").concat(page);
62
+ };
63
+ exports.getActivityPageURL = getActivityPageURL;
64
+ /**
65
+ * Extracts a number from an OSRS hiscores table cell element.
66
+ *
67
+ * @param el OSRS hiscores table cell element.
68
+ * @returns Number parsed from cell text.
69
+ */
70
+ var numberFromElement = function (el) {
71
+ var _a;
72
+ var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
73
+ var number = (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/[\n|,]/g, '')) !== null && _a !== void 0 ? _a : '-1';
74
+ return parseInt(number, 10);
75
+ };
76
+ exports.numberFromElement = numberFromElement;
77
+ /**
78
+ * Extracts a RSN from an OSRS hiscores table cell element.
79
+ *
80
+ * @param el OSRS hiscores table cell element.
81
+ * @returns RSN parsed from cell text.
82
+ */
83
+ var rsnFromElement = function (el) {
84
+ var _a;
85
+ var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
86
+ return (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/\uFFFD/g, ' ')) !== null && _a !== void 0 ? _a : '';
87
+ };
88
+ exports.rsnFromElement = rsnFromElement;
89
+ /**
90
+ * Will run an Axios `GET` request against a given URL after injecting a `User-Agent` header.
91
+ *
92
+ * @param url URL to run a `GET` request against.
93
+ * @returns Axios response.
94
+ */
95
+ var httpGet = function (url, config) {
96
+ if (config === void 0) { config = {}; }
97
+ return axios_1.default.get(url, __assign({ headers: {
98
+ // without User-Agent header requests may be rejected by DDoS protection mechanism
99
+ 'User-Agent': ua.firefox(80)
100
+ } }, config));
101
+ };
102
+ exports.httpGet = httpGet;
103
+ /**
104
+ * Validates that a provided RSN has the same username restrictions as Jagex.
105
+ * @param rsn Username to validate.
106
+ * @throws Error if the RSN fails validation.
107
+ */
108
+ var validateRSN = function (rsn) {
109
+ if (typeof rsn !== 'string') {
110
+ throw Error('RSN must be a string');
111
+ }
112
+ else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
113
+ throw Error('RSN contains invalid character');
114
+ }
115
+ else if (rsn.length > 12 || rsn.length < 1) {
116
+ throw Error('RSN must be between 1 and 12 characters');
117
+ }
118
+ };
119
+ exports.validateRSN = validateRSN;
@@ -1,2 +1,2 @@
1
- export * from './constants';
2
- export * from './helpers';
1
+ export * from './constants';
2
+ export * from './helpers';
@@ -1,14 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./constants"), exports);
14
- __exportStar(require("./helpers"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./helpers"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osrs-json-hiscores",
3
- "version": "2.14.1",
3
+ "version": "2.15.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",
@@ -61,7 +61,8 @@
61
61
  "@typescript-eslint"
62
62
  ],
63
63
  "extends": [
64
- "eslint-config-airbnb-typescript",
64
+ "airbnb-base",
65
+ "airbnb-typescript/base",
65
66
  "prettier"
66
67
  ],
67
68
  "ignorePatterns": [
@@ -72,7 +73,8 @@
72
73
  "trailingComma": "none",
73
74
  "tabWidth": 2,
74
75
  "semi": true,
75
- "singleQuote": true
76
+ "singleQuote": true,
77
+ "endOfLine": "auto"
76
78
  },
77
79
  "jest": {
78
80
  "transform": {
@@ -91,27 +93,24 @@
91
93
  },
92
94
  "dependencies": {
93
95
  "axios": "^0.21.1",
94
- "jsdom": "^16.3.0",
96
+ "jsdom": "^22.1.0",
95
97
  "useragent-generator": "^1.1.0"
96
98
  },
97
99
  "devDependencies": {
98
- "@types/jest": "^26.0.21",
99
- "@types/jsdom": "^16.2.3",
100
- "@typescript-eslint/eslint-plugin": "^4.19.0",
101
- "@typescript-eslint/parser": "^4.19.0",
102
- "eslint": "^7.22.0",
103
- "eslint-config-airbnb-typescript": "^12.3.1",
104
- "eslint-config-prettier": "^8.1.0",
105
- "eslint-plugin-import": "^2.22.1",
106
- "eslint-plugin-jsx-a11y": "^6.4.1",
107
- "eslint-plugin-react": "^7.23.1",
108
- "eslint-plugin-react-hooks": "^4.2.0",
100
+ "@types/jest": "^29.5.3",
101
+ "@types/jsdom": "^21.1.1",
102
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
103
+ "@typescript-eslint/parser": "^6.0.0",
104
+ "eslint": "^8.44.0",
105
+ "eslint-config-airbnb-typescript": "^17.1.0",
106
+ "eslint-config-prettier": "^8.8.0",
107
+ "eslint-plugin-import": "^2.27.5",
109
108
  "husky": "^5.2.0",
110
- "jest": "^26.6.3",
111
- "lint-staged": "^10.5.4",
109
+ "jest": "^29.6.1",
110
+ "lint-staged": "^13.2.3",
112
111
  "np": "^7.7.0",
113
- "prettier": "^2.2.1",
114
- "ts-jest": "^26.5.4",
115
- "typescript": "^4.2.3"
112
+ "prettier": "^3.0.0",
113
+ "ts-jest": "^29.1.1",
114
+ "typescript": "^5.1.6"
116
115
  }
117
116
  }