@otohime-site/parser 21.7.0 → 22.5.1

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.
@@ -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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
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";
@@ -1,6 +1,7 @@
1
1
  interface PlayerParseResultBase {
2
2
  card_name: string;
3
3
  rating: number;
4
+ rating_legacy: boolean;
4
5
  title: string;
5
6
  trophy: "normal" | "bronze" | "silver" | "gold" | "rainbow";
6
7
  }
package/dx_intl/player.js CHANGED
@@ -1,8 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
1
+ import { assertNonEmpty, assertBetween } from "../utils.js";
2
+ const isLegacyRating = (rating, ref) => (ref === "green" && rating < 3000) ||
3
+ (ref === "orange" && rating < 4000) ||
4
+ (ref === "red" && rating < 7000) ||
5
+ (ref === "purple" && rating < 10000) ||
6
+ (ref === "bronze" && rating < 12000) ||
7
+ (ref === "silver" && rating < 13000) ||
8
+ (ref === "gold" && rating < 14000) ||
9
+ (ref === "rainbow" && rating < 15000);
4
10
  const parsePlayer = (content) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
6
12
  const document = typeof content === "string"
7
13
  ? new DOMParser().parseFromString(content, "text/html")
8
14
  : content;
@@ -15,16 +21,19 @@ const parsePlayer = (content) => {
15
21
  ])[0].toLowerCase();
16
22
  const ratingBlock = document.querySelector(".rating_block");
17
23
  const rawRating = (_g = ratingBlock === null || ratingBlock === void 0 ? void 0 : ratingBlock.textContent) !== null && _g !== void 0 ? _g : "";
18
- const rawCourseRank = ((_k = (_j = (_h = document
19
- .querySelector('img[src *= "/img/course/"]')) === null || _h === void 0 ? void 0 : _h.getAttribute("src")) === null || _j === void 0 ? void 0 : _j.match(/course_rank_([0-9]{2})/)) !== null && _k !== void 0 ? _k : ["", ""])[1];
20
- const rawClassRank = ((_o = (_m = (_l = document
21
- .querySelector('img[src *= "/img/class/"]')) === null || _l === void 0 ? void 0 : _l.getAttribute("src")) === null || _m === void 0 ? void 0 : _m.match(/_([0-9]{2})/)) !== null && _o !== void 0 ? _o : ["", ""])[1];
22
- const rawGrade = ((_r = (_q = (_p = document
23
- .querySelector('img[src *= "/img/grade_"]')) === null || _p === void 0 ? void 0 : _p.getAttribute("src")) === null || _q === void 0 ? void 0 : _q.match(/grade_([0-9]{2})/)) !== null && _r !== void 0 ? _r : ["", ""])[1];
24
- utils_1.assertNonEmpty(cardName, "card_name");
25
- utils_1.assertNonEmpty(title, "title");
26
- utils_1.assertNonEmpty(trophy, "trophy");
27
- utils_1.assertNonEmpty(rawRating, "rating");
24
+ const ratingImageRef = ((_k = (_j = (_h = document
25
+ .querySelector('img[src *= "/img/rating_base_"]')) === null || _h === void 0 ? void 0 : _h.getAttribute("src")) === null || _j === void 0 ? void 0 : _j.match(/_([a-z]+)\.png/)) !== null && _k !== void 0 ? _k : ["", ""])[1];
26
+ const rawCourseRank = ((_o = (_m = (_l = document
27
+ .querySelector('img[src *= "/img/course/"]')) === null || _l === void 0 ? void 0 : _l.getAttribute("src")) === null || _m === void 0 ? void 0 : _m.match(/course_rank_([0-9]{2})/)) !== null && _o !== void 0 ? _o : ["", ""])[1];
28
+ const rawClassRank = ((_r = (_q = (_p = document
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];
30
+ const rawGrade = ((_u = (_t = (_s = document
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];
32
+ assertNonEmpty(cardName, "card_name");
33
+ assertNonEmpty(title, "title");
34
+ assertNonEmpty(trophy, "trophy");
35
+ assertNonEmpty(rawRating, "rating");
36
+ assertNonEmpty(ratingImageRef, "ratingImageRef");
28
37
  if (rawGrade.length === 0 &&
29
38
  (rawCourseRank.length === 0 || rawClassRank.length === 0)) {
30
39
  throw new Error("Cannot get the course/class ranks!");
@@ -41,27 +50,33 @@ const parsePlayer = (content) => {
41
50
  if (rawGrade.length > 0) {
42
51
  // old record, assert rating 14999
43
52
  const grade = parseInt(rawGrade, 10);
44
- utils_1.assertBetween(rating, 0, 14999, "rating");
45
- utils_1.assertBetween(grade, 1, 25, "grade");
53
+ assertBetween(rating, 0, 14999, "rating");
54
+ assertBetween(grade, 1, 25, "grade");
46
55
  return {
47
56
  card_name: cardName,
48
57
  title,
49
58
  trophy,
50
59
  rating,
60
+ rating_legacy: isLegacyRating(rating, ratingImageRef),
51
61
  grade,
52
62
  };
53
63
  }
54
64
  const courseRank = parseInt(rawCourseRank, 10);
55
65
  const classRank = parseInt(rawClassRank, 10);
56
- utils_1.assertBetween(rating, 0, 17000, "rating");
57
- // We will not have assertion on the new grades until it is confirmed.
66
+ assertBetween(rating, 0, 17000, "rating");
67
+ assertBetween(courseRank, 0, 22, "courseRank");
68
+ assertBetween(classRank, 0, 25, "classRank");
69
+ if (courseRank === 11) {
70
+ throw new Error("11 is not a expected course rank value");
71
+ }
58
72
  return {
59
73
  card_name: cardName,
60
74
  title,
61
75
  trophy,
62
76
  rating,
77
+ rating_legacy: isLegacyRating(rating, ratingImageRef),
63
78
  course_rank: courseRank,
64
79
  class_rank: classRank,
65
80
  };
66
81
  };
67
- exports.default = parsePlayer;
82
+ export default parsePlayer;
@@ -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 | HTMLDocument, categoryTo?: number, withNoScore?: boolean) => ScoresParseEntry[];
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
- "use strict";
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
- utils_1.assertBetween(category, 1, categoryTo, "category");
66
- utils_1.assertNonEmpty(title, "title");
67
- utils_1.assertBetween(difficulty, 0, 4, "difficulty");
68
- utils_1.assertNonEmpty(rawDeluxe, "deluxe");
69
- utils_1.assertNonEmpty(rawLevel, "level");
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
- utils_1.assertBetween(score, 0, 101, "score");
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
- exports.default = parseScores;
140
+ export default parseScores;
package/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- declare const _default: () => void;
2
- export default _default;
1
+ export {};
package/index.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = () => { };
1
+ export {};
package/package.json CHANGED
@@ -1,33 +1,36 @@
1
1
  {
2
2
  "name": "@otohime-site/parser",
3
- "version": "21.7.0",
3
+ "version": "22.5.1",
4
4
  "license": "MIT",
5
- "main": "index.js",
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
+ },
8
12
  "scripts": {
9
13
  "lint": "eslint",
10
14
  "test": "jest --coverage",
11
15
  "build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
12
16
  },
13
17
  "devDependencies": {
14
- "@types/jest": "^26.0.20",
15
- "@typescript-eslint/eslint-plugin": "^4.14.1",
16
- "@typescript-eslint/parser": "^4.14.1",
17
- "eslint": "^7.18.0",
18
+ "@typescript-eslint/eslint-plugin": "^5.25.0",
19
+ "@typescript-eslint/parser": "^5.25.0",
20
+ "eslint": "^8.16.0",
18
21
  "eslint-config-prettier": "^8.3.0",
19
- "eslint-config-standard-with-typescript": "^20.0.0",
20
- "eslint-plugin-import": "^2.22.1",
21
- "eslint-plugin-jest": "^24.3.6",
22
- "eslint-plugin-node": "^11.1.0",
23
- "eslint-plugin-promise": "^5.1.0",
24
- "husky": "^7.0.1",
25
- "jest": "^27.0.6",
26
- "jsdom": "^16.4.0",
27
- "lint-staged": "^11.0.0",
28
- "prettier": "^2.3.0",
29
- "ts-jest": "^27.0.4",
30
- "typescript": "^4.1.3"
22
+ "eslint-import-resolver-typescript": "^2.7.1",
23
+ "eslint-plugin-import": "^2.26.0",
24
+ "eslint-plugin-jest": "^26.2.2",
25
+ "eslint-plugin-react": "^7.30.0",
26
+ "eslint-plugin-react-hooks": "^4.5.0",
27
+ "husky": "^8.0.1",
28
+ "jest": "^28.1.0",
29
+ "jest-environment-jsdom": "^28.1.0",
30
+ "lint-staged": "^12.4.1",
31
+ "prettier": "^2.6.2",
32
+ "ts-jest": "^28.0.2",
33
+ "typescript": "^4.7.2"
31
34
  },
32
35
  "lint-staged": {
33
36
  "*.js,*.ts": "eslint --cache --fix",
package/utils.js CHANGED
@@ -1,15 +1,10 @@
1
- "use strict";
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
- exports.assertNonEmpty = assertNonEmpty;
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;