clashofclans.js 3.3.24-dev.8f08e9a → 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.
@@ -48,4 +48,17 @@ export declare class Util extends null {
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',
@@ -141,5 +142,34 @@ class Util extends null {
141
142
  static async delay(ms) {
142
143
  return new Promise((res) => setTimeout(res, ms));
143
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
+ }
144
174
  }
145
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.8f08e9a",
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",