clashofclans.js 3.3.24-dev.4a30349 → 3.3.24-dev.a67ca30

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.
@@ -43,9 +43,22 @@ export declare class Util extends null {
43
43
  * @param {boolean} forward - Whether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.
44
44
  */
45
45
  static getSeason(timestamp?: Date, forward?: boolean): {
46
- startTime: Date;
47
46
  endTime: Date;
47
+ startTime: Date;
48
48
  };
49
49
  static allSettled<T>(values: Promise<T>[]): Promise<T[]>;
50
50
  static delay(ms: number): Promise<unknown>;
51
+ /** Parse in-game army link into troops and spells count with respective Id's. */
52
+ static parseArmyLink(link: string): {
53
+ units: {
54
+ name: string | null;
55
+ count: number;
56
+ id: number;
57
+ }[];
58
+ spells: {
59
+ name: string | null;
60
+ count: number;
61
+ id: number;
62
+ }[];
63
+ };
51
64
  }
package/dist/util/Util.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Util = exports.timeoutSignal = void 0;
4
+ const Constants_1 = require("../util/Constants");
4
5
  const TAG_CHARACTERS = '0289PYLQGRJCUV';
5
6
  const params = [
6
7
  'name',
@@ -96,9 +97,6 @@ class Util extends null {
96
97
  return query.length ? `?${query}` : query;
97
98
  }
98
99
  static getSeasonStart(inputDate) {
99
- if (inputDate >= new Date('2025-08-25T05:00:00.000Z') && inputDate <= new Date('2025-10-06T05:00:00.000Z')) {
100
- return new Date('2025-08-25T05:00:00.000Z');
101
- }
102
100
  const lastMonthLastDay = new Date(Date.UTC(inputDate.getUTCFullYear(), inputDate.getUTCMonth(), 0));
103
101
  const lastMonthLastMonday = new Date(lastMonthLastDay);
104
102
  lastMonthLastMonday.setUTCDate(lastMonthLastMonday.getUTCDate() - ((lastMonthLastDay.getUTCDay() + 6) % 7));
@@ -106,9 +104,6 @@ class Util extends null {
106
104
  return lastMonthLastMonday;
107
105
  }
108
106
  static getSeasonEnd(inputDate, forward = true) {
109
- if (inputDate >= new Date('2025-08-25T05:00:00.000Z') && inputDate <= new Date('2025-10-06T05:00:00.000Z')) {
110
- return forward ? new Date('2025-10-06T05:00:00.000Z') : new Date('2025-08-25T05:00:00.000Z');
111
- }
112
107
  const lastDayOfMonth = new Date(Date.UTC(inputDate.getUTCFullYear(), inputDate.getUTCMonth() + 1, 0));
113
108
  const lastMonday = new Date(lastDayOfMonth);
114
109
  lastMonday.setUTCDate(lastMonday.getUTCDate() - ((lastDayOfMonth.getUTCDay() + 6) % 7));
@@ -135,10 +130,6 @@ class Util extends null {
135
130
  * @param {boolean} forward - Whether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.
136
131
  */
137
132
  static getSeason(timestamp, forward = true) {
138
- const inputDate = timestamp ?? new Date();
139
- if (inputDate >= new Date('2025-08-25T05:00:00.000Z') && inputDate <= new Date('2025-10-06T05:00:00.000Z')) {
140
- return { startTime: new Date('2025-08-25T05:00:00.000Z'), endTime: new Date('2025-10-06T05:00:00.000Z') };
141
- }
142
133
  const endTime = this.getSeasonEnd(timestamp ?? new Date(), forward);
143
134
  const startTime = this.getSeasonStart(endTime);
144
135
  return { endTime, startTime };
@@ -151,5 +142,34 @@ class Util extends null {
151
142
  static async delay(ms) {
152
143
  return new Promise((res) => setTimeout(res, ms));
153
144
  }
145
+ /** Parse in-game army link into troops and spells count with respective Id's. */
146
+ static parseArmyLink(link) {
147
+ const unitsMatches = /u(?<units>[\d+x-]+)/.exec(link);
148
+ const spellsMatches = /s(?<spells>[\d+x-]+)/.exec(link);
149
+ const unitsPart = unitsMatches?.groups?.units?.split('-') ?? [];
150
+ const spellParts = spellsMatches?.groups?.spells?.split('-') ?? [];
151
+ const units = unitsPart
152
+ .map((parts) => parts.split(/x/))
153
+ .map((parts) => ({
154
+ id: Number(parts[1]),
155
+ total: Number(parts[0])
156
+ }));
157
+ const spells = spellParts
158
+ .map((parts) => parts.split(/x/))
159
+ .map((parts) => ({
160
+ id: Number(parts[1]),
161
+ total: Number(parts[0])
162
+ }));
163
+ return {
164
+ units: units.map((unit) => {
165
+ const _unit = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'troop' && raw.id === unit.id);
166
+ return { name: _unit?.name ?? null, count: unit.total, id: unit.id };
167
+ }),
168
+ spells: spells.map((spell) => {
169
+ const _spell = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'spell' && raw.id === spell.id);
170
+ return { name: _spell?.name ?? null, count: spell.total, id: spell.id };
171
+ })
172
+ };
173
+ }
154
174
  }
155
175
  exports.Util = Util;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.3.24-dev.4a30349",
3
+ "version": "3.3.24-dev.a67ca30",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",