Utils
This page explains how to work with the internal Utils API. It covers the most important utility functions.
Utils API
To fetch the utility manager, add the following snippet:
const utils = this.heart.core.util.util;Functions
secureEval(string)
Securely evaluate a string by removing non-numeric characters.
const equation = parseInt(eval(this.heart.core.util.util.secureEval('1 * 2 + 5')));ms(string)
Convert a time string to milliseconds. The format is 12h 2m 15s 262ms.
const time = this.heart.core.util.util.ms('2m 6s');ms(number)
Convert milliseconds to a time string.
const time = this.heart.core.util.util.ms(60000);resolveTime(string)
Resolve a time string to milliseconds. This supports a wide range of formats.
sleep(number)
Sleep for a specified amount of time in milliseconds.
getRandomElement(array)
Get a random element from an array.
upperCase(string)
Convert the first letter of a string to uppercase.
generateRandom(number, number, array)
Generate a random string.
isNumber(string)
Check whether a string is a number.
isEquation(string)
Check whether a string is an equation.
validateHex(string)
Validate a hex color code.
isPicture(string)
Check whether a file is a picture based on its extension.
validateURL(string)
Validate a URL.
Last updated