clashofclans.js 2.2.0-dev.1030d3c → 2.2.0-dev.8fc1be4
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/dist/rest/RESTManager.js +8 -8
- package/dist/util/Util.d.ts +6 -5
- package/dist/util/Util.js +10 -9
- package/package.json +1 -1
package/dist/rest/RESTManager.js
CHANGED
|
@@ -14,38 +14,38 @@ class RESTManager {
|
|
|
14
14
|
}
|
|
15
15
|
/** Get info about a clan. */
|
|
16
16
|
getClan(clanTag, options) {
|
|
17
|
-
return this.handler.request(`/clans/${Util_1.Util.
|
|
17
|
+
return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}`, options);
|
|
18
18
|
}
|
|
19
19
|
/** Get list of clan members. */
|
|
20
20
|
getClanMembers(clanTag, options) {
|
|
21
21
|
const query = Util_1.Util.queryString(options);
|
|
22
|
-
return this.handler.request(`/clans/${Util_1.Util.
|
|
22
|
+
return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members?${query}`, options);
|
|
23
23
|
}
|
|
24
24
|
/** Get clan war log. */
|
|
25
25
|
getClanWarLog(clanTag, options) {
|
|
26
26
|
const query = Util_1.Util.queryString(options);
|
|
27
|
-
return this.handler.request(`/clans/${Util_1.Util.
|
|
27
|
+
return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog?${query}`, options);
|
|
28
28
|
}
|
|
29
29
|
/** Get info about currently running war in the clan. */
|
|
30
30
|
getCurrentWar(clanTag, options) {
|
|
31
|
-
return this.handler.request(`/clans/${Util_1.Util.
|
|
31
|
+
return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar`, options);
|
|
32
32
|
}
|
|
33
33
|
/** Get info about clan war league. */
|
|
34
34
|
getClanWarLeagueGroup(clanTag, options) {
|
|
35
|
-
return this.handler.request(`/clans/${Util_1.Util.
|
|
35
|
+
return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar/leaguegroup`, options);
|
|
36
36
|
}
|
|
37
37
|
/** Get info about a CWL round by WarTag. */
|
|
38
38
|
getClanWarLeagueRound(warTag, options) {
|
|
39
|
-
return this.handler.request(`/clanwarleagues/wars/${Util_1.Util.
|
|
39
|
+
return this.handler.request(`/clanwarleagues/wars/${Util_1.Util.encodeURI(warTag)}`, options);
|
|
40
40
|
}
|
|
41
41
|
/** Get info about a player by tag. */
|
|
42
42
|
getPlayer(playerTag, options) {
|
|
43
|
-
return this.handler.request(`/players/${Util_1.Util.
|
|
43
|
+
return this.handler.request(`/players/${Util_1.Util.encodeURI(playerTag)}`, options);
|
|
44
44
|
}
|
|
45
45
|
/** Verify Player API token that can be found from the Game settings. */
|
|
46
46
|
verifyPlayerToken(playerTag, token, options) {
|
|
47
47
|
const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
|
|
48
|
-
return this.handler.request(`/players/${Util_1.Util.
|
|
48
|
+
return this.handler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, opts);
|
|
49
49
|
}
|
|
50
50
|
/** Get list of Leagues. */
|
|
51
51
|
getLeagues(options) {
|
package/dist/util/Util.d.ts
CHANGED
|
@@ -10,22 +10,23 @@ export declare class Util extends null {
|
|
|
10
10
|
/** @internal */
|
|
11
11
|
static parseTag(tag: string): string;
|
|
12
12
|
/** Encodes a tag as a valid component of a URI. */
|
|
13
|
-
static
|
|
13
|
+
static encodeURI(tag: string): string;
|
|
14
|
+
/** Verify a tag using RegExp. (`/^#?[0289PYLQGRJCUV]$/`) */
|
|
14
15
|
static isValidTag(tag: string): boolean;
|
|
15
16
|
/**
|
|
16
17
|
* Encode tag string into 64bit unsigned integer string.
|
|
17
18
|
* ```ts
|
|
18
|
-
* Util.
|
|
19
|
+
* Util.encodeTag('#PCCVQQG0'); // '510915076'
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
static
|
|
22
|
+
static encodeTag(tag: string): string;
|
|
22
23
|
/**
|
|
23
24
|
* Decode 64bit unsigned integer string into tag string with hash.
|
|
24
25
|
* ```ts
|
|
25
|
-
* Util.
|
|
26
|
+
* Util.decodeTag('510915076'); // '#PCCVQQG0'
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
static
|
|
29
|
+
static decodeTag(id: string): string;
|
|
29
30
|
/** Converts API Date to JavaScript Date. */
|
|
30
31
|
static formatDate(date: string): Date;
|
|
31
32
|
/** Returns a string containing a query string suitable for use in a URL. */
|
package/dist/util/Util.js
CHANGED
|
@@ -18,38 +18,39 @@ class Util extends null {
|
|
|
18
18
|
return `#${tag.toUpperCase().replace(/O/g, '0').replace(/^#/g, '').replace(/\s/g, '')}`;
|
|
19
19
|
}
|
|
20
20
|
/** Encodes a tag as a valid component of a URI. */
|
|
21
|
-
static
|
|
21
|
+
static encodeURI(tag) {
|
|
22
22
|
return encodeURIComponent(this.formatTag(tag));
|
|
23
23
|
}
|
|
24
|
+
/** Verify a tag using RegExp. (`/^#?[0289PYLQGRJCUV]$/`) */
|
|
24
25
|
static isValidTag(tag) {
|
|
25
26
|
return /^#?[0289PYLQGRJCUV]{3,}$/.test(tag);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Encode tag string into 64bit unsigned integer string.
|
|
29
30
|
* ```ts
|
|
30
|
-
* Util.
|
|
31
|
+
* Util.encodeTag('#PCCVQQG0'); // '510915076'
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
|
-
static
|
|
34
|
+
static encodeTag(tag) {
|
|
34
35
|
const formatted = this.formatTag(tag).substring(1);
|
|
35
36
|
if (!this.isValidTag(formatted)) {
|
|
36
37
|
throw new Error(`Failed to encode tag ${formatted}. RegExp matching failed.`);
|
|
37
38
|
}
|
|
38
|
-
const result = formatted.split('').reduce((sum, char) => sum *
|
|
39
|
+
const result = formatted.split('').reduce((sum, char) => sum * BigInt(14) + BigInt(TAG_CHARACTERS.indexOf(char)), BigInt(0));
|
|
39
40
|
return result.toString();
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Decode 64bit unsigned integer string into tag string with hash.
|
|
43
44
|
* ```ts
|
|
44
|
-
* Util.
|
|
45
|
+
* Util.decodeTag('510915076'); // '#PCCVQQG0'
|
|
45
46
|
* ```
|
|
46
47
|
*/
|
|
47
|
-
static
|
|
48
|
+
static decodeTag(id) {
|
|
48
49
|
let [bigint, tag] = [BigInt(id), ''];
|
|
49
|
-
while (bigint !==
|
|
50
|
-
const index = Number(bigint %
|
|
50
|
+
while (bigint !== BigInt(0)) {
|
|
51
|
+
const index = Number(bigint % BigInt(14));
|
|
51
52
|
tag = TAG_CHARACTERS[index] + tag;
|
|
52
|
-
bigint /=
|
|
53
|
+
bigint /= BigInt(14);
|
|
53
54
|
}
|
|
54
55
|
return `#${tag}`;
|
|
55
56
|
}
|
package/package.json
CHANGED