Skip to content

Commit 90d1349

Browse files
committed
feat: jsdocs for Util.ts
1 parent fffb381 commit 90d1349

File tree

2 files changed

+82
-16
lines changed

2 files changed

+82
-16
lines changed

src/lib/GClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export class GClient<Ready extends boolean = boolean> extends Client<Ready> {
134134
});
135135
}
136136

137-
/**
138137
/**
139138
* The method that returns the database option provided in {@link GClientOptions}
140139
* @param {any} _ Used for typings
@@ -164,6 +163,7 @@ export class GClient<Ready extends boolean = boolean> extends Client<Ready> {
164163
* // returns <MongoDBProvider>
165164
* ```
166165
*/
166+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
167167
public getDatabase<Database>(_?: Database): Database {
168168
return this.options.database;
169169
}

src/lib/util/Util.ts

+81-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import type { Client } from 'discord.js';
1+
/* eslint-disable max-len */
2+
import type {
3+
Client,
4+
CommandInteractionOption,
5+
ApplicationCommandType,
6+
} from 'discord.js';
27
import { Logger } from './logger/Logger';
38
import type { GClient } from '../GClient';
49
import { Plugins } from '../managers/PluginManager';
510

11+
/**
12+
* Includes many useful functions
13+
*/
614
export class Util {
715
/**
8-
* @deprecated We don't support arguments in object/array
9-
* @link https://discord.js.org/#/docs/main/stable/class/CommandInteractionOptionResolver
16+
* Converts [CommandInteractionOptionResolveer](https://discord.js.org/#/docs/discord.js/stable/class/CommandInteractionOptionResolver) to an array
17+
* @param {import('discord.js').CommandInteractionOptionResolver[]} options The options to convert
18+
* @deprecated We don't support arguments in object
19+
* @returns {string[]}
1020
*/
11-
static argumentsToArray(options: Array<any>): Array<string> {
21+
static argumentsToArray(options: CommandInteractionOption[]): string[] {
1222
const args = [];
1323

1424
const check = options => {
@@ -26,10 +36,12 @@ export class Util {
2636
}
2737

2838
/**
29-
* @deprecated We don't support arguments in object/array
30-
* @link https://discord.js.org/#/docs/main/stable/class/CommandInteractionOptionResolver
39+
* Converts [CommandInteractionOptionResolveer](https://discord.js.org/#/docs/discord.js/stable/class/CommandInteractionOptionResolver) to an object
40+
* @param {import('discord.js').CommandInteractionOptionResolver[]} options The options to convert
41+
* @deprecated We don't support arguments in object
42+
* @returns {any}
3143
*/
32-
static argumentsToObject(options: Array<any>) {
44+
static argumentsToObject(options: CommandInteractionOption[]): any {
3345
const args = {};
3446

3547
const check = (options, object) => {
@@ -47,10 +59,12 @@ export class Util {
4759
}
4860

4961
/**
62+
* Check if the type is a sub command or sub command group
63+
* @param {ApplicationCommandType} type The type to check
5064
* @deprecated We don't support arguments in object/array
51-
* @link https://discord.js.org/#/docs/main/stable/class/CommandInteractionOptionResolver
65+
* @returns {boolean}
5266
*/
53-
static checkIfSubOrGroup(type: string) {
67+
static checkIfSubOrGroup(type: ApplicationCommandType): boolean {
5468
// Why? Because discord.js v14 (:
5569
return !![
5670
'SUB_COMMAND',
@@ -60,6 +74,11 @@ export class Util {
6074
].includes(type);
6175
}
6276

77+
/**
78+
* Check if the input is a class
79+
* @param {any} input The input to check
80+
* @returns {boolean}
81+
*/
6382
static isClass(input: any): boolean {
6483
return (
6584
typeof input === 'function' &&
@@ -68,7 +87,15 @@ export class Util {
6887
);
6988
}
7089

71-
static resolveArgumentOptions(options: any): any {
90+
/**
91+
* Converts option names from camelCase to snake_case
92+
* @param {Object<string, string>} options The options to convert
93+
* @deprecated This method is no longer used anywhere
94+
* @returns {Object<string, string>}
95+
*/
96+
static resolveArgumentOptions(
97+
options: [key: string, value: string],
98+
): [key: string, value: string] {
7299
for (const [key, value] of Object.entries(options)) {
73100
const option = key.match(/[A-Z]/g)?.[0]
74101
? key.replace(
@@ -87,6 +114,12 @@ export class Util {
87114
return options;
88115
}
89116

117+
/**
118+
* The method that resolves the file for directoryLoader
119+
* @param {any} file The file that will be resolved
120+
* @param {string} fileType The file type
121+
* @returns {any}
122+
*/
90123
static resolveFile(file: any, fileType: string): any {
91124
if (fileType === '.ts') return file.default || Object.values(file)[0];
92125
if (fileType === '.js') {
@@ -97,28 +130,55 @@ export class Util {
97130
return file;
98131
}
99132

100-
static stringToBoolean(string: string): boolean {
133+
/**
134+
* The method that converts a string to a boolean
135+
* @param {string} text The text to convert
136+
* @deprecated This method is no longer used anywhere
137+
* @returns
138+
*/
139+
static stringToBoolean(text: string): boolean {
101140
const regex = /^\s*(true|1|on)\s*$/i;
102-
return regex.test(string);
141+
return regex.test(text);
103142
}
104143

105-
static resolveValidationErrorTrace(array: Array<any>): string {
144+
/**
145+
* The method that solves the error validation trace
146+
* @param {any[]} array
147+
* @returns
148+
*/
149+
static resolveValidationErrorTrace(array: any[]): string {
106150
array = array.filter(item => typeof item === 'string');
107151
return `(${array.join(' -> ') || 'unknown'})`;
108152
}
109153

154+
/**
155+
* The method that modifies numbers and adds `0` before numbers that are less than 10
156+
* @param {number} number The number to modify
157+
* @returns {string}
158+
*/
110159
static pad(number: number): string {
111160
return (number < 10 ? '0' : '') + number;
112161
}
113162

163+
/**
164+
* The method that throws an error to the console
165+
* @param {string} error The error to throw
166+
* @param {string} name The name of the class or file path that threw the error
167+
*/
114168
static throwError(error, name): void {
115169
const trace = Util.resolveValidationErrorTrace([name]);
116170

117171
Logger.error(error, trace);
118172
}
119173

120-
static toPascalCase(input: string): string {
121-
return input
174+
/**
175+
* The method that converts case to PascalCase
176+
* @param {string} text The text to convert
177+
* @deprecated This method is no longer used anywhere
178+
* @returns {string}
179+
*/
180+
static toPascalCase(text: string): string {
181+
return text
122182
.replace(new RegExp(/[-_]+/, 'g'), ' ')
123183
.replace(new RegExp(/[^\w\s]/, 'g'), '')
124184
.replace(
@@ -128,6 +188,12 @@ export class Util {
128188
.replace(new RegExp(/\w/), s => s.toUpperCase());
129189
}
130190

191+
/**
192+
* The method that uses `@gcommands/plugin-language` to get a message in a specific language
193+
* @param {string} value The value to get
194+
* @param {{client: import('discord.js').Client | import('../GClient').GClient}} client The client to get the default response
195+
* @returns {Promise<string>}
196+
*/
131197
static async getResponse(
132198
value: string,
133199
interaction: { client: Client | GClient },

0 commit comments

Comments
 (0)