Util
Util
Utility class with various helper functions.
Kind: global class
- Util
- .generateDiscordTimestamp(time, style) ⇒
string
- .resolveColor(color) ⇒
number
- .getBuffer(file) ⇒
Promise.<Buffer>
- .generateDataURI(base64) ⇒
string
|undefined
- .generateFile(buffer, [filename]) ⇒
- .base64ToBuffer(base64) ⇒
Buffer
- .generateISOString([date]) ⇒
string
|null
- .generateDiscordTimestamp(time, style) ⇒
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.
Param | Type | Description |
---|---|---|
time | number | The Unix timestamp to format. |
style | string | The 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.
Param | Type | Description |
---|---|---|
color | string | number | The 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.
Param | Type | Description |
---|---|---|
file | Buffer | MessageAttachment | string | The 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.
Param | Type | Description |
---|---|---|
base64 | string | Buffer | The 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
Param | Type | Description |
---|---|---|
buffer | Buffer | string | The buffer or path to the file content. |
[filename] | string | The 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.
Param | Type | Description |
---|---|---|
base64 | string | The 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.
Param | Type | Default | Description |
---|---|---|---|
[date] | number | Date | Date.now() | The date to convert to an ISO string. If not provided, the current date and time will be used. |