@otohime-site/parser 21.7.2 → 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";
package/dx_intl/player.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 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
- utils_1.assertNonEmpty(cardName, "card_name");
35
- utils_1.assertNonEmpty(title, "title");
36
- utils_1.assertNonEmpty(trophy, "trophy");
37
- utils_1.assertNonEmpty(rawRating, "rating");
38
- utils_1.assertNonEmpty(ratingImageRef, "ratingImageRef");
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
- utils_1.assertBetween(rating, 0, 14999, "rating");
56
- utils_1.assertBetween(grade, 1, 25, "grade");
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
- utils_1.assertBetween(rating, 0, 17000, "rating");
69
- utils_1.assertBetween(courseRank, 0, 22, "courseRank");
70
- utils_1.assertBetween(classRank, 0, 25, "classRank");
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
- 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.2",
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;