Skip to content

Util

Util

Utility class with various helper functions.

Kind: global class

Util.generateDiscordTimestamp(time, style) ⇒ string

Generates a Discord timestamp string based on the given time and style.

Kind: static method of Util
Returns: string - - The formatted Discord timestamp string.

ParamTypeDescription
timenumberThe Unix timestamp to format.
stylestringThe style of the timestamp. Valid values are “t” (short time), “T” (long time), “d” (short date), “D” (long date), “f” (short date/time), “F” (long date/time), “R” (relative time), “r” (relative time with seconds), “c” (calendar time), “C” (calendar time with seconds).

Util.resolveColor(color) ⇒ number

Resolves a color value to its corresponding integer representation.

Kind: static method of Util
Returns: number - - The resolved color value as an integer.

ParamTypeDescription
colorstring | numberThe color value to resolve. Can be a string representing a color name or a hexadecimal color code, or a number representing a color value.

Util.getBuffer(file) ⇒ Promise.<Buffer>

Retrieves the buffer data from the given file.

Kind: static method of Util
Returns: Promise.<Buffer> - - The buffer data of the file.

ParamTypeDescription
fileBuffer | MessageAttachment | stringThe file to retrieve the buffer data from.

Util.generateDataURI(base64) ⇒ string | undefined

Generates a data URI from a base64 string or a Buffer object.

Kind: static method of Util
Returns: string | undefined - - The data URI string or undefined if base64 is falsy.

ParamTypeDescription
base64string | BufferThe base64 string or Buffer object.

Util.generateFile(buffer, [filename]) ⇒

Generates a file with the given buffer and filename.

Kind: static method of Util
Returns: None

ParamTypeDescription
bufferBuffer | stringThe buffer or path to the file content.
[filename]stringThe name of the file to be generated. If not provided, “file.txt” will be used as the default filename.

Util.base64ToBuffer(base64) ⇒ Buffer

Converts a base64 encoded string to a buffer.

Kind: static method of Util
Returns: Buffer - - The buffer representation of the base64 string.

ParamTypeDescription
base64stringThe base64 encoded string.

Util.generateISOString([date]) ⇒ string | null

Generates an ISO string representation of the given date.

Kind: static method of Util
Returns: string | null - - The ISO string representation of the date, or null if the input is null.

ParamTypeDefaultDescription
[date]number | DateDate.now()The date to convert to an ISO string. If not provided, the current date and time will be used.