This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
global.d.ts
203 lines (147 loc) · 5.81 KB
/
global.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import type * as DiscordClientTypes from '@discord/types';
import type { Collection } from 'discord.js';
type StringKeys<T> = `${Exclude<keyof T, symbol>}`;
type GetStringKey<T, K extends StringKeys<T>> = K extends keyof T ? T[K] : T[number & keyof T];
type AutoPath<O, P extends string> =
P extends `${infer A}.${infer B}`
? A extends StringKeys<O>
? `${A}.${AutoPath<GetStringKey<O, A>, B>}`
: never
: P extends StringKeys<O>
? P
| `${P}.`
: StringKeys<O>;
type GetPath<O, P extends string> =
P extends `${infer A}.${infer B}`
? A extends StringKeys<O>
? GetPath<GetStringKey<O, A>, B>
: never
: P extends StringKeys<O>
? GetStringKey<O, P>
: never;
interface CapitalizationOptions {
preserve?: boolean;
capitalizeAfterQuote?: boolean;
skipWord?: (word: string, position: number) => boolean;
}
declare global {
interface Map<K, V> {
/**
* Get an array of the map values
* @returns The values of this map as an array
*/
toArray(this: this): V[];
/**
* Get a set of this map's keys
* @returns The keys of this map as a set
*/
toSet(this: this): Set<K>;
}
interface Array<T> {
/**
* Turn this array into a map
* @param path - The path to the key value as a string
* @returns A map with the path value as the key and the array element as the value
*/
toMap<P extends string>(this: this, path: AutoPath<T, P>): Map<GetPath<T, P>, T>;
/**
* Split this array into chunks
* @param chunks - The amount of chunks
* @param balanced - Whether to make the chunks balanced. If false will have an extra element with values that did not fit equally into the chunks. If true will try to balance the chunks as equally as possible, if not possible some chunks may be larger than others. By default true.
* @returns A multidimensional array of the chunks
*/
split(this: this, chunks: number, balanced?: boolean): T[][];
/**
* Turn this array into a generator.
* This can be used to iterate over the values endlessly.
* @returns The generator of this array
*/
toGenerator(this: this): Generator<T, T, number>;
/**
* Get an array of the differences between each number in the array.
* This function can only be used on number arrays!
* @returns An array of the differences between each number, will be one less in length
*/
difference(this: number[]): number[];
/**
* Get a random element of this array
* @returns A random element from this array
*/
random(this: this): T;
/**
* A shortcut function to get the last element of this array
* @returns The last element of this array
*/
last(this: this): T;
/**
*
* A shortcut function to get the last index of this array
* @returns The last index of this array
*/
lastIndex(this: this): number;
}
interface String {
/**
* Capitalizes the first letter of a string only
* @param options - The capitalization options
* @returns The capitalized string
* @license https://github.com/grncdr/js-capitalize/blob/master/LICENSE
*/
capitalize(this: string, options?: Pick<CapitalizationOptions, "preserve">): string;
/**
* Capitalizes the first letter of each word in a string
* @param options - The capitalization options
* @returns The capitalized string
* @license https://github.com/grncdr/js-capitalize/blob/master/LICENSE
*/
capitalizeWords(this: string, options?: CapitalizationOptions): string;
}
interface Math {
/**
* Calculates the percentage of a value in a value
* @param value - The value to calculate the percentage of
* @param of_value - The value to calculate the percentage from
* @returns The percentage of `value` in `of_value`
*/
percentage(value: number, of_value: number): number;
/**
* Returns the distance between the two numbers
* @param x - The first value
* @param y - The second value
* @returns The difference between the two numbers
*/
difference(x: number, y: number): number;
}
interface Date {
/**
* A typeguard, which checks whether this is a valid date
* @returns A boolean value indicating whether this date is currently valid
*/
isValid(this: this): this is Date;
}
interface Number {
/**
* Abbreviates a value equal to or above 1000. Can only abbreviate up to trillions
* @param fractionDigits - fraction digits of the value, by default 1
* @returns The abbreviated value as a string
*/
abbreviate(this: number, fractionDigits?: number): string;
}
interface JSON {
/**
* Convert JSON to CSV format
* @param array - An array of JSON objects
* @param seperator - The seperator to use in the CSV
* @returns A string containing the formatted JSON
*/
convertToCSV(array: Array<{ [key: string]: any }>, seperator?: string): string;
}
}
declare module 'discord.js' {
interface Client {
chatCommands: Collection<string, DiscordClientTypes.SlashCommand>;
menuCommands: Collection<string, DiscordClientTypes.ContextMenu>;
components: Collection<string, DiscordClientTypes.Component>;
cooldowns: Collection<string, Collection<string, Date>>;
}
}