Skip to main content

Class: Util

Contains various general-purpose utility methods.

Hierarchy

  • any

    Util

Constructors

constructor

new Util()

Inherited from

null.constructor

Methods

formatTag

Static formatTag(tag): string

Corrects malformed tags to match how they are formatted.

Util.formatTag("PccVqqGO"); // #PCCVQQG0

Parameters

NameType
tagstring

Returns

string

Defined in

util/Util.ts:45


encodeURI

Static encodeURI(tag): string

Encodes a tag as a valid component of a URI.

Parameters

NameType
tagstring

Returns

string

Defined in

util/Util.ts:58


isValidTag

Static isValidTag(tag): boolean

Verify a tag using RegExp. (/^#?[0289PYLQGRJCUV]$/)

Parameters

NameType
tagstring

Returns

boolean

Defined in

util/Util.ts:63


encodeTag

Static encodeTag(tag): string

Encode tag string into 64bit unsigned integer string.

Util.encodeTag('#PCCVQQG0'); // '510915076'

Parameters

NameType
tagstring

Returns

string

Defined in

util/Util.ts:73


decodeTag

Static decodeTag(id): string

Decode 64bit unsigned integer string into tag string with hash.

Util.decodeTag('510915076'); // '#PCCVQQG0'

Parameters

NameType
idstring

Returns

string

Defined in

util/Util.ts:89


formatDate

Static formatDate(date): Date

Converts API Date to JavaScript Date.

Parameters

NameType
datestring

Returns

Date

Defined in

util/Util.ts:101


queryString

Static queryString(options?): string

Returns a string containing a query string suitable for use in a URL.

Parameters

NameType
optionsSearchOptions | ClanSearchOptions

Returns

string

Defined in

util/Util.ts:108


getSeasonStart

Static getSeasonStart(inputDate): Date

Parameters

NameType
inputDateDate

Returns

Date

Defined in

util/Util.ts:113


getSeasonEnd

Static getSeasonEnd(inputDate, forward?): Date

Parameters

NameTypeDefault value
inputDateDateundefined
forwardbooleantrue

Returns

Date

Defined in

util/Util.ts:122


getSeasonId

Static getSeasonId(): string

Get the current season ID.

Returns

string

Defined in

util/Util.ts:146


getSeason

Static getSeason(timestamp?, forward?): Object

Get the season start and end timestamp.

Parameters

NameTypeDefault valueDescription
timestamp?DateundefinedThe reference date. Defaults to the current date if not provided.
forwardbooleantrueWhether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.

Returns

Object

NameType
endTimeDate
startTimeDate

Defined in

util/Util.ts:155


allSettled

Static allSettled<T>(values): Promise<T[]>

Type parameters

Name
T

Parameters

NameType
valuesPromise<T>[]

Returns

Promise<T[]>

Defined in

util/Util.ts:161


delay

Static delay(ms): Promise<unknown>

Parameters

NameType
msnumber

Returns

Promise<unknown>

Defined in

util/Util.ts:167


Static parseArmyLink(link): Object

Parse in-game army link into troops and spells count with respective Id's.

Parameters

NameType
linkstring

Returns

Object

NameType
units{ name: null | string ; count: number = unit.total; id: number = unit.id }[]
spells{ name: null | string ; count: number = spell.total; id: number = spell.id }[]

Defined in

util/Util.ts:172