kol.js 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kol.js",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "main": "src/index.ts",
5
5
  "type": "module",
6
6
  "files": [
@@ -13,12 +13,12 @@
13
13
  "format": "prettier --write ."
14
14
  },
15
15
  "devDependencies": {
16
- "prettier": "^3.3.2",
17
- "typescript": "^5.5.3",
18
- "vitest": "^1.6.0"
16
+ "prettier": "^3.3.3",
17
+ "typescript": "^5.6.2",
18
+ "vitest": "^2.1.0"
19
19
  },
20
20
  "dependencies": {
21
- "@xmldom/xmldom": "^0.8.10",
21
+ "@xmldom/xmldom": "^0.9.2",
22
22
  "async-mutex": "^0.5.0",
23
23
  "date-fns": "^3.6.0",
24
24
  "got": "^14.4.2",
@@ -29,7 +29,6 @@
29
29
  "tough-cookie": "^5.0.0",
30
30
  "ts-dedent": "^2.2.0",
31
31
  "typed-emitter": "^2.1.0",
32
- "typescript-memoize": "^1.1.1",
33
32
  "xpath": "^0.0.34"
34
33
  }
35
34
  }
package/src/Client.ts CHANGED
@@ -16,7 +16,6 @@ import {
16
16
  import { PlayerCache } from "./Cache.js";
17
17
  import { CookieJar } from "tough-cookie";
18
18
  import got, { OptionsOfJSONResponseBody, OptionsOfTextResponseBody } from "got";
19
- import { Memoize } from "typescript-memoize";
20
19
 
21
20
  type TypedEmitter<T extends EventMap> = TypedEventEmitter.default<T>;
22
21
 
@@ -356,9 +355,9 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<E
356
355
  : minPrice
357
356
  : minPrice;
358
357
  const formattedMinPrice = minPrice
359
- ? (minPrice === unlimitedPrice
358
+ ? ((minPrice === unlimitedPrice
360
359
  ? unlimitedMatch?.[1]
361
- : limitedMatch?.[1]) ?? ""
360
+ : limitedMatch?.[1]) ?? "")
362
361
  : "";
363
362
  return {
364
363
  mallPrice: unlimitedPrice,
@@ -512,14 +511,18 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<E
512
511
  return familiars;
513
512
  }
514
513
 
515
- @Memoize()
514
+ static #descIdToIdCache: Map<number, number> = new Map();
515
+
516
516
  async descIdToId(descId: number): Promise<number> {
517
+ if (Client.#descIdToIdCache.has(descId)) return Client.#descIdToIdCache.get(descId)!;
517
518
  const page = await this.fetchText("desc_item.php", {
518
519
  searchParams: {
519
520
  whichitem: descId,
520
521
  },
521
522
  });
522
- return Number(page.match(/<!-- itemid: (\d+) -->/)?.[1] ?? -1);
523
+ const id = Number(page.match(/<!-- itemid: (\d+) -->/)?.[1] ?? -1);
524
+ Client.#descIdToIdCache.set(descId, id);
525
+ return id;
523
526
  }
524
527
 
525
528
  async getRaffle() {
@@ -1,5 +1,5 @@
1
1
  import xpath, { select } from "xpath";
2
- import { DOMParser } from "@xmldom/xmldom";
2
+ import { DOMParser, MIME_TYPE } from "@xmldom/xmldom";
3
3
 
4
4
  export type LeaderboardInfo = {
5
5
  name: string;
@@ -19,11 +19,8 @@ type RunInfo = {
19
19
  };
20
20
 
21
21
  const parser = new DOMParser({
22
- locator: {},
23
- errorHandler: {
24
- warning: () => {},
25
- error: () => {},
26
- fatalError: console.error,
22
+ onError: (level, message) => {
23
+ if (level === "fatalError") console.error(message);
27
24
  },
28
25
  });
29
26
 
@@ -34,8 +31,9 @@ const selectMulti = (expression: string, node: Node) => {
34
31
  };
35
32
 
36
33
  export function parseLeaderboard(page: string): LeaderboardInfo {
37
- const document = parser.parseFromString(page);
38
- const [board, ...boards] = selectMulti("//table", document);
34
+ const doc = parser.parseFromString(page, MIME_TYPE.HTML);
35
+ // @ts-expect-error see https://github.com/xmldom/xmldom/issues/724
36
+ const [board, ...boards] = selectMulti("//table", doc);
39
37
 
40
38
  return {
41
39
  name: selectMulti(".//text()", board.firstChild!)