docs(builders): Add some basic documentation (#9359)

This commit is contained in:
Jiralite
2023-04-10 21:09:51 +01:00
committed by GitHub
parent c0f2dd7131
commit 8073561824
36 changed files with 690 additions and 300 deletions

View File

@@ -1,5 +1,10 @@
import type { APIEmbed } from 'discord-api-types/v10';
/**
* Calculates the length of the embed.
*
* @param data - The embed data to check
*/
export function embedLength(data: APIEmbed) {
return (
(data.title?.length ?? 0) +

View File

@@ -1,6 +1,19 @@
/**
* Normalizes data that is a rest parameter or an array into an array with a depth of 1.
*
* @typeParam T - The data that must satisfy {@link RestOrArray}.
* @param arr - The (possibly variadic) data to normalize
*/
export function normalizeArray<T>(arr: RestOrArray<T>): T[] {
if (Array.isArray(arr[0])) return arr[0];
return arr as T[];
}
/**
* Represents data that may be an array or came from a rest parameter.
*
* @remarks
* This type is used throughout builders to ensure both an array and variadic arguments
* may be used. It is normalized with {@link normalizeArray}.
*/
export type RestOrArray<T> = T[] | [T[]];

View File

@@ -1,5 +1,26 @@
let validate = true;
export const enableValidators = () => (validate = true);
export const disableValidators = () => (validate = false);
export const isValidationEnabled = () => validate;
/**
* Enables validators.
*
* @returns Whether validation is occurring.
*/
export function enableValidators() {
return (validate = true);
}
/**
* Disables validators.
*
* @returns Whether validation is occurring.
*/
export function disableValidators() {
return (validate = false);
}
/**
* Checks whether validation is occurring.
*/
export function isValidationEnabled() {
return validate;
}