2024-02-28 03:25:11 -08:00
|
|
|
export default class Utilities {
|
2024-03-03 00:23:29 -08:00
|
|
|
/**
|
|
|
|
*
|
2024-03-12 01:50:54 -07:00
|
|
|
* @param time (s)
|
2024-03-03 00:23:29 -08:00
|
|
|
* @returns
|
|
|
|
*/
|
2024-02-28 03:25:11 -08:00
|
|
|
public static delay(time: number): Promise<any> {
|
2024-03-12 01:50:54 -07:00
|
|
|
return new Promise((resolve) => setTimeout(resolve, time * 1000));
|
2024-02-28 03:25:11 -08:00
|
|
|
}
|
|
|
|
|
2024-03-07 09:45:13 -08:00
|
|
|
/**
|
|
|
|
*@param predicate
|
2024-03-12 01:50:54 -07:00
|
|
|
* @param time (s)
|
2024-03-07 09:45:13 -08:00
|
|
|
* @returns
|
|
|
|
*/
|
2024-03-12 01:50:54 -07:00
|
|
|
public static async waitUntil(predicate: () => boolean, timeCheck = 0.01) {
|
2024-03-07 09:45:13 -08:00
|
|
|
while (!predicate()) {
|
|
|
|
await this.delay(timeCheck);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 03:25:11 -08:00
|
|
|
public static getJson(json: string): any {
|
|
|
|
try {
|
|
|
|
return JSON.parse(json);
|
|
|
|
} catch (error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|