osrs-json-hiscores 2.12.0 → 2.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,92 +1,109 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
4
- var axios_1 = require("axios");
5
- var ua = require("useragent-generator");
6
- var constants_1 = require("./constants");
7
- /**
8
- * Will generate a stats URL for the official OSRS API.
9
- *
10
- * @param gamemode Gamemode to fetch ranks for.
11
- * @param rsn Username of the player.
12
- * @returns Encoded stats URL.
13
- */
14
- var getStatsURL = function (gamemode, rsn) {
15
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.STATS_URL + encodeURIComponent(rsn);
16
- };
17
- exports.getStatsURL = getStatsURL;
18
- /**
19
- * Will generate a player table URL for the official OSRS hiscores website.
20
- *
21
- * @param gamemode Gamemode to fetch ranks for.
22
- * @param rsn Username of the player.
23
- * @returns Encoded player table URL.
24
- */
25
- var getPlayerTableURL = function (gamemode, rsn) {
26
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=0&user=" + encodeURIComponent(rsn);
27
- };
28
- exports.getPlayerTableURL = getPlayerTableURL;
29
- /**
30
- * Will generate a skill table URL for the official OSRS hiscores website.
31
- *
32
- * @param gamemode Gamemode to fetch ranks for.
33
- * @param skill Skill to fetch ranks for.
34
- * @param page Page number.
35
- * @returns
36
- */
37
- var getSkillPageURL = function (gamemode, skill, page) {
38
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=" + constants_1.SKILLS.indexOf(skill) + "&page=" + page;
39
- };
40
- exports.getSkillPageURL = getSkillPageURL;
41
- /**
42
- * Will generate an activity table URL for the official OSRS hiscores website.
43
- *
44
- * @param gamemode Gamemode to fetch ranks for.
45
- * @param activity Activity or boss to fetch ranks for.
46
- * @param page Page number.
47
- * @returns
48
- */
49
- var getActivityPageURL = function (gamemode, activity, page) {
50
- return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "category_type=1&table=" + constants_1.ACTIVITIES.indexOf(activity) + "&page=" + page;
51
- };
52
- exports.getActivityPageURL = getActivityPageURL;
53
- /**
54
- * Extracts a number from an OSRS hiscores table cell element.
55
- *
56
- * @param el OSRS hiscores table cell element.
57
- * @returns Number parsed from cell text.
58
- */
59
- var numberFromElement = function (el) {
60
- var _a;
61
- var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
62
- var number = (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/[\n|,]/g, '')) !== null && _a !== void 0 ? _a : '-1';
63
- return parseInt(number, 10);
64
- };
65
- exports.numberFromElement = numberFromElement;
66
- /**
67
- * Extracts a RSN from an OSRS hiscores table cell element.
68
- *
69
- * @param el OSRS hiscores table cell element.
70
- * @returns RSN parsed from cell text.
71
- */
72
- var rsnFromElement = function (el) {
73
- var _a;
74
- var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
75
- return (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/\uFFFD/g, ' ')) !== null && _a !== void 0 ? _a : '';
76
- };
77
- exports.rsnFromElement = rsnFromElement;
78
- /**
79
- * Will run an Axios `GET` request against a given URL after injecting a `User-Agent` header.
80
- *
81
- * @param url URL to run a `GET` request against.
82
- * @returns Axios response.
83
- */
84
- var httpGet = function (url) {
85
- return axios_1.default.get(url, {
86
- headers: {
87
- // without User-Agent header requests may be rejected by DDoS protection mechanism
88
- 'User-Agent': ua.firefox(80)
89
- }
90
- });
91
- };
92
- exports.httpGet = httpGet;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRSN = exports.httpGet = exports.rsnFromElement = exports.numberFromElement = exports.getActivityPageURL = exports.getSkillPageURL = exports.getPlayerTableURL = exports.getStatsURL = void 0;
4
+ var axios_1 = require("axios");
5
+ var ua = require("useragent-generator");
6
+ var constants_1 = require("./constants");
7
+ /**
8
+ * Will generate a stats URL for the official OSRS API.
9
+ *
10
+ * @param gamemode Gamemode to fetch ranks for.
11
+ * @param rsn Username of the player.
12
+ * @returns Encoded stats URL.
13
+ */
14
+ var getStatsURL = function (gamemode, rsn) {
15
+ return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.STATS_URL + encodeURIComponent(rsn);
16
+ };
17
+ exports.getStatsURL = getStatsURL;
18
+ /**
19
+ * Will generate a player table URL for the official OSRS hiscores website.
20
+ *
21
+ * @param gamemode Gamemode to fetch ranks for.
22
+ * @param rsn Username of the player.
23
+ * @returns Encoded player table URL.
24
+ */
25
+ var getPlayerTableURL = function (gamemode, rsn) {
26
+ return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=0&user=" + encodeURIComponent(rsn);
27
+ };
28
+ exports.getPlayerTableURL = getPlayerTableURL;
29
+ /**
30
+ * Will generate a skill table URL for the official OSRS hiscores website.
31
+ *
32
+ * @param gamemode Gamemode to fetch ranks for.
33
+ * @param skill Skill to fetch ranks for.
34
+ * @param page Page number.
35
+ * @returns
36
+ */
37
+ var getSkillPageURL = function (gamemode, skill, page) {
38
+ return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "table=" + constants_1.SKILLS.indexOf(skill) + "&page=" + page;
39
+ };
40
+ exports.getSkillPageURL = getSkillPageURL;
41
+ /**
42
+ * Will generate an activity table URL for the official OSRS hiscores website.
43
+ *
44
+ * @param gamemode Gamemode to fetch ranks for.
45
+ * @param activity Activity or boss to fetch ranks for.
46
+ * @param page Page number.
47
+ * @returns
48
+ */
49
+ var getActivityPageURL = function (gamemode, activity, page) {
50
+ return "" + constants_1.GAMEMODE_URL[gamemode] + constants_1.SCORES_URL + "category_type=1&table=" + constants_1.ACTIVITIES.indexOf(activity) + "&page=" + page;
51
+ };
52
+ exports.getActivityPageURL = getActivityPageURL;
53
+ /**
54
+ * Extracts a number from an OSRS hiscores table cell element.
55
+ *
56
+ * @param el OSRS hiscores table cell element.
57
+ * @returns Number parsed from cell text.
58
+ */
59
+ var numberFromElement = function (el) {
60
+ var _a;
61
+ var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
62
+ var number = (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/[\n|,]/g, '')) !== null && _a !== void 0 ? _a : '-1';
63
+ return parseInt(number, 10);
64
+ };
65
+ exports.numberFromElement = numberFromElement;
66
+ /**
67
+ * Extracts a RSN from an OSRS hiscores table cell element.
68
+ *
69
+ * @param el OSRS hiscores table cell element.
70
+ * @returns RSN parsed from cell text.
71
+ */
72
+ var rsnFromElement = function (el) {
73
+ var _a;
74
+ var innerHTML = (el !== null && el !== void 0 ? el : {}).innerHTML;
75
+ return (_a = innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.replace(/\uFFFD/g, ' ')) !== null && _a !== void 0 ? _a : '';
76
+ };
77
+ exports.rsnFromElement = rsnFromElement;
78
+ /**
79
+ * Will run an Axios `GET` request against a given URL after injecting a `User-Agent` header.
80
+ *
81
+ * @param url URL to run a `GET` request against.
82
+ * @returns Axios response.
83
+ */
84
+ var httpGet = function (url) {
85
+ return axios_1.default.get(url, {
86
+ headers: {
87
+ // without User-Agent header requests may be rejected by DDoS protection mechanism
88
+ 'User-Agent': ua.firefox(80)
89
+ }
90
+ });
91
+ };
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;
@@ -1,2 +1,2 @@
1
- export * from './constants';
2
- export * from './helpers';
1
+ export * from './constants';
2
+ export * from './helpers';
@@ -1,14 +1,14 @@
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
+ 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);
package/package.json CHANGED
@@ -1,114 +1,117 @@
1
- {
2
- "name": "osrs-json-hiscores",
3
- "version": "2.12.0",
4
- "description": "The Old School Runescape API wrapper that does more!",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": [
8
- "lib/**/*"
9
- ],
10
- "scripts": {
11
- "dev": "yarn build --watch",
12
- "build": "tsc",
13
- "format": "prettier --write \"src/**/*.ts\"",
14
- "lint": "eslint --fix \"src/**/*.ts\"",
15
- "test": "jest",
16
- "prepublish": "yarn run build",
17
- "release": "np"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/maxswa/osrs-json-hiscores.git"
22
- },
23
- "keywords": [
24
- "oldschool",
25
- "runescape",
26
- "osrs",
27
- "api",
28
- "json",
29
- "hiscores",
30
- "stats",
31
- "skills"
32
- ],
33
- "author": "maxswa",
34
- "license": "ISC",
35
- "bugs": {
36
- "url": "https://github.com/maxswa/osrs-json-hiscores/issues"
37
- },
38
- "homepage": "https://github.com/maxswa/osrs-json-hiscores#readme",
39
- "husky": {
40
- "hooks": {
41
- "pre-commit": "lint-staged"
42
- }
43
- },
44
- "lint-staged": {
45
- "*.{ts}": [
46
- "eslint --fix",
47
- "prettier --write",
48
- "git add"
49
- ]
50
- },
51
- "eslintConfig": {
52
- "root": true,
53
- "parser": "@typescript-eslint/parser",
54
- "parserOptions": {
55
- "project": "./tsconfig.eslint.json"
56
- },
57
- "plugins": [
58
- "@typescript-eslint"
59
- ],
60
- "extends": [
61
- "eslint-config-airbnb-typescript",
62
- "prettier"
63
- ],
64
- "ignorePatterns": [
65
- "**/@types/*"
66
- ]
67
- },
68
- "prettier": {
69
- "trailingComma": "none",
70
- "tabWidth": 2,
71
- "semi": true,
72
- "singleQuote": true
73
- },
74
- "jest": {
75
- "transform": {
76
- "^.+\\.(t|j)sx?$": "ts-jest"
77
- },
78
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
79
- "moduleFileExtensions": [
80
- "ts",
81
- "tsx",
82
- "js",
83
- "jsx",
84
- "json",
85
- "node"
86
- ],
87
- "testEnvironment": "node"
88
- },
89
- "dependencies": {
90
- "axios": "^0.21.1",
91
- "jsdom": "^16.3.0",
92
- "useragent-generator": "^1.1.0"
93
- },
94
- "devDependencies": {
95
- "@types/jest": "^26.0.21",
96
- "@types/jsdom": "^16.2.3",
97
- "@typescript-eslint/eslint-plugin": "^4.19.0",
98
- "@typescript-eslint/parser": "^4.19.0",
99
- "eslint": "^7.22.0",
100
- "eslint-config-airbnb-typescript": "^12.3.1",
101
- "eslint-config-prettier": "^8.1.0",
102
- "eslint-plugin-import": "^2.22.1",
103
- "eslint-plugin-jsx-a11y": "^6.4.1",
104
- "eslint-plugin-react": "^7.23.1",
105
- "eslint-plugin-react-hooks": "^4.2.0",
106
- "husky": "^5.2.0",
107
- "jest": "^26.6.3",
108
- "lint-staged": "^10.5.4",
109
- "np": "6.5.0",
110
- "prettier": "^2.2.1",
111
- "ts-jest": "^26.5.4",
112
- "typescript": "^4.2.3"
113
- }
114
- }
1
+ {
2
+ "name": "osrs-json-hiscores",
3
+ "version": "2.12.1",
4
+ "description": "The Old School Runescape API wrapper that does more!",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "dev": "yarn build --watch",
12
+ "build": "tsc",
13
+ "format": "prettier --write \"src/**/*.ts\"",
14
+ "lint": "eslint --fix \"src/**/*.ts\"",
15
+ "test": "jest",
16
+ "prepublish": "yarn run build",
17
+ "release": "np"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/maxswa/osrs-json-hiscores.git"
22
+ },
23
+ "keywords": [
24
+ "oldschool",
25
+ "runescape",
26
+ "osrs",
27
+ "api",
28
+ "json",
29
+ "hiscores",
30
+ "stats",
31
+ "skills"
32
+ ],
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org"
35
+ },
36
+ "author": "maxswa",
37
+ "license": "ISC",
38
+ "bugs": {
39
+ "url": "https://github.com/maxswa/osrs-json-hiscores/issues"
40
+ },
41
+ "homepage": "https://github.com/maxswa/osrs-json-hiscores#readme",
42
+ "husky": {
43
+ "hooks": {
44
+ "pre-commit": "lint-staged"
45
+ }
46
+ },
47
+ "lint-staged": {
48
+ "*.{ts}": [
49
+ "eslint --fix",
50
+ "prettier --write",
51
+ "git add"
52
+ ]
53
+ },
54
+ "eslintConfig": {
55
+ "root": true,
56
+ "parser": "@typescript-eslint/parser",
57
+ "parserOptions": {
58
+ "project": "./tsconfig.eslint.json"
59
+ },
60
+ "plugins": [
61
+ "@typescript-eslint"
62
+ ],
63
+ "extends": [
64
+ "eslint-config-airbnb-typescript",
65
+ "prettier"
66
+ ],
67
+ "ignorePatterns": [
68
+ "**/@types/*"
69
+ ]
70
+ },
71
+ "prettier": {
72
+ "trailingComma": "none",
73
+ "tabWidth": 2,
74
+ "semi": true,
75
+ "singleQuote": true
76
+ },
77
+ "jest": {
78
+ "transform": {
79
+ "^.+\\.(t|j)sx?$": "ts-jest"
80
+ },
81
+ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
82
+ "moduleFileExtensions": [
83
+ "ts",
84
+ "tsx",
85
+ "js",
86
+ "jsx",
87
+ "json",
88
+ "node"
89
+ ],
90
+ "testEnvironment": "node"
91
+ },
92
+ "dependencies": {
93
+ "axios": "^0.21.1",
94
+ "jsdom": "^16.3.0",
95
+ "useragent-generator": "^1.1.0"
96
+ },
97
+ "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",
109
+ "husky": "^5.2.0",
110
+ "jest": "^26.6.3",
111
+ "lint-staged": "^10.5.4",
112
+ "np": "6.5.0",
113
+ "prettier": "^2.2.1",
114
+ "ts-jest": "^26.5.4",
115
+ "typescript": "^4.2.3"
116
+ }
117
+ }