@otohime-site/parser 21.7.2 → 22.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dx_intl/index.d.ts +2 -4
- package/dx_intl/index.js +2 -11
- package/dx_intl/player.js +12 -14
- package/dx_intl/scores.d.ts +1 -1
- package/dx_intl/scores.js +8 -10
- package/index.d.ts +1 -2
- package/index.js +1 -3
- package/package.json +22 -18
- package/utils.js +2 -7
package/dx_intl/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { default as parsePlayer } from "./player";
|
|
2
|
-
export { default as parseScores } from "./scores";
|
|
3
|
-
declare const _default: () => void;
|
|
4
|
-
export default _default;
|
|
1
|
+
export { default as parsePlayer } from "./player.js";
|
|
2
|
+
export { default as parseScores } from "./scores.js";
|
package/dx_intl/index.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseScores = exports.parsePlayer = void 0;
|
|
7
|
-
var player_1 = require("./player");
|
|
8
|
-
Object.defineProperty(exports, "parsePlayer", { enumerable: true, get: function () { return __importDefault(player_1).default; } });
|
|
9
|
-
var scores_1 = require("./scores");
|
|
10
|
-
Object.defineProperty(exports, "parseScores", { enumerable: true, get: function () { return __importDefault(scores_1).default; } });
|
|
11
|
-
exports.default = () => { };
|
|
1
|
+
export { default as parsePlayer } from "./player.js";
|
|
2
|
+
export { default as parseScores } from "./scores.js";
|
package/dx_intl/player.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { assertNonEmpty, assertBetween } from "../utils.js";
|
|
4
2
|
const isLegacyRating = (rating, ref) => (ref === "green" && rating < 3000) ||
|
|
5
3
|
(ref === "orange" && rating < 4000) ||
|
|
6
4
|
(ref === "red" && rating < 7000) ||
|
|
@@ -31,11 +29,11 @@ const parsePlayer = (content) => {
|
|
|
31
29
|
.querySelector('img[src *= "/img/class/"]')) === null || _p === void 0 ? void 0 : _p.getAttribute("src")) === null || _q === void 0 ? void 0 : _q.match(/_([0-9]{2})/)) !== null && _r !== void 0 ? _r : ["", ""])[1];
|
|
32
30
|
const rawGrade = ((_u = (_t = (_s = document
|
|
33
31
|
.querySelector('img[src *= "/img/grade_"]')) === null || _s === void 0 ? void 0 : _s.getAttribute("src")) === null || _t === void 0 ? void 0 : _t.match(/grade_([0-9]{2})/)) !== null && _u !== void 0 ? _u : ["", ""])[1];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
assertNonEmpty(cardName, "card_name");
|
|
33
|
+
assertNonEmpty(title, "title");
|
|
34
|
+
assertNonEmpty(trophy, "trophy");
|
|
35
|
+
assertNonEmpty(rawRating, "rating");
|
|
36
|
+
assertNonEmpty(ratingImageRef, "ratingImageRef");
|
|
39
37
|
if (rawGrade.length === 0 &&
|
|
40
38
|
(rawCourseRank.length === 0 || rawClassRank.length === 0)) {
|
|
41
39
|
throw new Error("Cannot get the course/class ranks!");
|
|
@@ -52,8 +50,8 @@ const parsePlayer = (content) => {
|
|
|
52
50
|
if (rawGrade.length > 0) {
|
|
53
51
|
// old record, assert rating 14999
|
|
54
52
|
const grade = parseInt(rawGrade, 10);
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
assertBetween(rating, 0, 14999, "rating");
|
|
54
|
+
assertBetween(grade, 1, 25, "grade");
|
|
57
55
|
return {
|
|
58
56
|
card_name: cardName,
|
|
59
57
|
title,
|
|
@@ -65,9 +63,9 @@ const parsePlayer = (content) => {
|
|
|
65
63
|
}
|
|
66
64
|
const courseRank = parseInt(rawCourseRank, 10);
|
|
67
65
|
const classRank = parseInt(rawClassRank, 10);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
assertBetween(rating, 0, 17000, "rating");
|
|
67
|
+
assertBetween(courseRank, 0, 22, "courseRank");
|
|
68
|
+
assertBetween(classRank, 0, 25, "classRank");
|
|
71
69
|
if (courseRank === 11) {
|
|
72
70
|
throw new Error("11 is not a expected course rank value");
|
|
73
71
|
}
|
|
@@ -81,4 +79,4 @@ const parsePlayer = (content) => {
|
|
|
81
79
|
class_rank: classRank,
|
|
82
80
|
};
|
|
83
81
|
};
|
|
84
|
-
|
|
82
|
+
export default parsePlayer;
|
package/dx_intl/scores.d.ts
CHANGED
|
@@ -12,5 +12,5 @@ export interface ScoresParseEntryWithScore extends ScoresParseEntryWithoutScore
|
|
|
12
12
|
sync_flag: "" | "fs" | "fs+" | "fdx" | "fdx+";
|
|
13
13
|
}
|
|
14
14
|
export declare type ScoresParseEntry = ScoresParseEntryWithoutScore | ScoresParseEntryWithScore;
|
|
15
|
-
declare const parseScores: (content: string |
|
|
15
|
+
declare const parseScores: (content: string | Document, categoryTo?: number, withNoScore?: boolean) => ScoresParseEntry[];
|
|
16
16
|
export default parseScores;
|
package/dx_intl/scores.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { assertNonEmpty, assertBetween } from "../utils.js";
|
|
4
2
|
const LEVELS = [
|
|
5
3
|
"1",
|
|
6
4
|
"2",
|
|
@@ -62,11 +60,11 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
62
60
|
// If only one type: determine by .music_kind_icon (standard.png vs dx.png)
|
|
63
61
|
// Two types: determine by id (sta_xx vs dx_xx)
|
|
64
62
|
const rawDeluxe = (_l = (_k = curr.querySelector(".music_kind_icon")) === null || _k === void 0 ? void 0 : _k.getAttribute("src")) !== null && _l !== void 0 ? _l : ((_m = curr.id.match(/sta|dx/)) !== null && _m !== void 0 ? _m : [""])[0];
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
assertBetween(category, 1, categoryTo, "category");
|
|
64
|
+
assertNonEmpty(title, "title");
|
|
65
|
+
assertBetween(difficulty, 0, 4, "difficulty");
|
|
66
|
+
assertNonEmpty(rawDeluxe, "deluxe");
|
|
67
|
+
assertNonEmpty(rawLevel, "level");
|
|
70
68
|
const deluxe = rawDeluxe === "dx" || rawDeluxe.includes("dx.png");
|
|
71
69
|
const levelIndex = LEVELS.indexOf(rawLevel);
|
|
72
70
|
if (levelIndex < 0) {
|
|
@@ -89,7 +87,7 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
89
87
|
] }) : Object.assign({}, prev);
|
|
90
88
|
}
|
|
91
89
|
const score = parseFloat(rawScore);
|
|
92
|
-
|
|
90
|
+
assertBetween(score, 0, 101, "score");
|
|
93
91
|
const flagImages = [...curr.querySelectorAll("img.f_r").values()];
|
|
94
92
|
const flags = flagImages.reduce((prevFlags, currFlagImg) => {
|
|
95
93
|
var _a, _b;
|
|
@@ -139,4 +137,4 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
139
137
|
});
|
|
140
138
|
return result;
|
|
141
139
|
};
|
|
142
|
-
|
|
140
|
+
export default parseScores;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default _default;
|
|
1
|
+
export {};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otohime-site/parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.5.3",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/otohime-site/parser#readme",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./dx_intl": "./dx_intl/index.js",
|
|
11
|
+
"./dx_intl/*": "./dx_intl/*.js"
|
|
12
|
+
},
|
|
8
13
|
"scripts": {
|
|
9
14
|
"lint": "eslint",
|
|
10
15
|
"test": "jest --coverage",
|
|
11
16
|
"build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
|
|
12
17
|
},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@
|
|
15
|
-
"@typescript-eslint/
|
|
16
|
-
"
|
|
17
|
-
"eslint": "^7.18.0",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
20
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
21
|
+
"eslint": "^8.16.0",
|
|
18
22
|
"eslint-config-prettier": "^8.3.0",
|
|
19
|
-
"eslint-
|
|
20
|
-
"eslint-plugin-import": "^2.
|
|
21
|
-
"eslint-plugin-jest": "^
|
|
22
|
-
"eslint-plugin-
|
|
23
|
-
"eslint-plugin-
|
|
24
|
-
"husky": "^
|
|
25
|
-
"jest": "^
|
|
26
|
-
"jsdom": "^
|
|
27
|
-
"lint-staged": "^
|
|
28
|
-
"prettier": "^2.
|
|
29
|
-
"ts-jest": "^
|
|
30
|
-
"typescript": "^4.
|
|
23
|
+
"eslint-import-resolver-typescript": "^2.7.1",
|
|
24
|
+
"eslint-plugin-import": "^2.26.0",
|
|
25
|
+
"eslint-plugin-jest": "^26.2.2",
|
|
26
|
+
"eslint-plugin-react": "^7.30.0",
|
|
27
|
+
"eslint-plugin-react-hooks": "^4.5.0",
|
|
28
|
+
"husky": "^8.0.1",
|
|
29
|
+
"jest": "^28.1.0",
|
|
30
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
31
|
+
"lint-staged": "^12.4.1",
|
|
32
|
+
"prettier": "^2.6.2",
|
|
33
|
+
"ts-jest": "^28.0.2",
|
|
34
|
+
"typescript": "^4.7.2"
|
|
31
35
|
},
|
|
32
36
|
"lint-staged": {
|
|
33
37
|
"*.js,*.ts": "eslint --cache --fix",
|
package/utils.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertBetween = exports.assertNonEmpty = void 0;
|
|
4
|
-
function assertNonEmpty(value, varName) {
|
|
1
|
+
export function assertNonEmpty(value, varName) {
|
|
5
2
|
if (value.length === 0) {
|
|
6
3
|
throw new Error(`Cannot get the value of ${varName}`);
|
|
7
4
|
}
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
function assertBetween(value, from, to, varName) {
|
|
6
|
+
export function assertBetween(value, from, to, varName) {
|
|
11
7
|
if (Number.isNaN(value) || value < from || value > to) {
|
|
12
8
|
throw new Error(`Assert failed for ${varName}, expected: ${from} ~ ${to}, received: ${value}`);
|
|
13
9
|
}
|
|
14
10
|
}
|
|
15
|
-
exports.assertBetween = assertBetween;
|