Skip to content

Commit

Permalink
add some jsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TiltedToast committed Mar 23, 2024
1 parent 65788c7 commit d0bf59c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ import type {
UpdateEmbedOptions,
} from "./types.ts";

/**
* Formats a table from an array of objects
* @param rows An array of objects to format into a table
* @returns A string containing the formatted table
* @throws {Error} Must have at least one row and one column
* @example
* ```ts
* const rows = [
* { name: "John", age: 25 },
* { name: "Jane", age: 30 },
* ];
* console.log(formatTable(rows));
* ```
*/
export function formatTable<K extends string | number | symbol, V>(rows: Record<K, V>[]): string {
const MIN_WRAP_LENGTH = 30;

Expand Down Expand Up @@ -283,6 +297,7 @@ export async function getUserObjectPingId(message: Message): Promise<User | unde
* Takes an array and returns a random element from it.
* @param array The input array
* @returns a random element from the array
* @throws {Error} Array must have at least one element
*/
export function randomElementFromArray<T>(array: T[]): T {
assert(array.length > 0, "Array must have at least one element");
Expand Down Expand Up @@ -422,6 +437,12 @@ export async function downloadURL(url: string, saveLocation: string) {
* Takes an image URL and returns the file extension
* @param url The URL to whatever image you want to get the extension of
* @returns The file extension of the image
* @throws {Error} URL must not be empty
* @example
* ```ts
* const url = "https://example.com/image.png";
* console.log(getImgType(url)); // "png"
* ```
*/
export function getImgType(url: string): SupportedStaticImgExts | "gif" | undefined {
assert(url.length > 0, "URL must have at least one character");
Expand Down

0 comments on commit d0bf59c

Please sign in to comment.