-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.d.ts
204 lines (173 loc) · 6.56 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
204
/// <reference path="./@types">
declare module 'erfevents' {
/**
* Class representing an EventEmitter for managing and emitting events.
* @typeparam T - The event registry type extending EventRegistry.
*/
class EventEmitter<T extends EventRegistry<T> = EventRegistryMap> {
private readonly _events: Map<keyof T, Set<EventCallback<Parameters<T[keyof T]>>>>;
/**
* Get the map of events being managed by the EventEmitter.
* @returns A readonly Map of event names to their corresponding Set of listeners.
*/
public readonly events: ReadonlyMap<keyof T, Set<EventCallback<Parameters<T[keyof T]>>>>;
/**
* Add a listener for the specified event.
* @param name - The name of the event.
* @param listener - The listener function to add.
* @param emitLimit - Optional. The maximum number of times the listener can be emitted.
* @returns This EventEmitter instance for chaining.
*/
public on<K extends keyof T>(name: K, listener: EventCallback<Parameters<T[K]>>, emitLimit?: number): this;
/**
* Add a one-time listener for the specified event.
* @param name - The name of the event.
* @param listener - The listener function to add.
* @returns This EventEmitter instance for chaining.
*/
public once<K extends keyof T>(name: K, listener: EventCallback<Parameters<T[K]>>): this;
/**
* Remove a listener for the specified event.
* @param name - The name of the event.
* @param listener - The listener function to remove.
* @returns This EventEmitter instance for chaining.
*/
public off<K extends keyof T>(name: K, listener: T[K]): this;
/**
* Emit an event with the given arguments.
* @param event - The name of the event to emit.
* @param args - Arguments to pass to the event listeners.
* @returns True if listeners were called, false if no listeners for the event.
*/
public emit<K extends keyof T>(event: K, ...args: Parameters<T[K]>): boolean;
/**
* Remove all listeners for a specific event, or all events if no event name is provided.
* @param name - Optional. The name of the event to remove listeners from.
* @returns This EventEmitter instance for chaining.
*/
public removeAllListeners<K extends keyof T>(name?: K): this;
/**
* Get the number of listeners for a specific event.
* @param name - The name of the event.
* @returns The number of listeners for the event.
*/
public listenerCount<K extends keyof T>(name: K): number;
/**
* Get an array of all event names this EventEmitter is handling.
* @returns An array of event names.
*/
public eventNames<K extends keyof T>(): K[];
/**
* Check if a listener has been emitted.
* @param listener - The listener function to check.
* @returns True if the listener has been emitted, false otherwise.
*/
public isEmitted(listener: any): boolean;
/**
* Decorate a listener with additional properties.
* @param listener - The listener function to decorate.
* @param values - Additional properties to set on the listener.
* @returns The decorated listener function.
*/
static decorate(listener: any, values: any): any;
}
import Shapeshift from '@sapphire/shapeshift';
/**
* Utility class for validating various data types using Sapphire's validation schemas.
*/
class Validator {
/**
* Validation schema for strings.
*/
static readonly StringValidation: Shapeshift.StringValidator<string>;
/**
* Validation schema for integers.
*/
static readonly NumberValidation: Shapeshift.NumberValidator<number>;
/**
* Validation schema for nullish values (null or undefined).
*/
static readonly NullishValidation: Shapeshift.NullishValidator;
/**
* Validation schema for any type of value.
*/
static readonly AnyValidation: Shapeshift.PassthroughValidator<any>;
/**
* Validation schema for objects.
*/
static readonly ObjectValidation: <T extends object>(shape: Shapeshift.MappedObjectValidator<T>, options?: Shapeshift.ValidatorOptions) => Shapeshift.ObjectValidator<T, Shapeshift.UndefinedToOptional<T>>;
/**
* Validation schema for URLs.
*/
static readonly URLValidation: Shapeshift.InstanceValidator<URL>;
/**
* Validation schema for functions.
*/
static readonly FunctionValidation: Shapeshift.InstanceValidator<Function>;
/**
* Validation schema for input against a list of string literals.
*/
static readonly StringInputValidation: Shapeshift.UnionValidator<any> = (...values: any[]) => any;
/**
* Validation schema for instances.
*/
static readonly InstanceValidation: <T>(expected: Shapeshift.Constructor<T>, options?: Shapeshift.ValidatorOptions) => Shapeshift.InstanceValidator<T>;
/**
* Validates a string.
* @param value The input to validate.
* @returns The validated string.
*/
static string(value: any): any;
/**
* Validates a number.
* @param value The input to validate.
* @returns The validated number.
*/
static number(value: any): any;
/**
* Validates nullish values (null or undefined).
* @param value The input to validate.
* @returns The validated nullish value.
*/
static nullish(value: any): any;
/**
* Validates any type of value.
* @param value The input to validate.
* @returns The validated value.
*/
static any(value: any): any;
/**
* Validates an object.
* @param value The input to validate.
* @returns The validated object.
*/
static object(value: any): any;
/**
* Validates a URL instance.
* @param value The input to validate.
* @returns The validated URL instance.
*/
static url(value: any): any;
/**
* Validates a function instance.
* @param value The input to validate.
* @returns The validated function instance.
*/
static function(value: any): any;
/**
* Validates input against a list of string literals.
* @param value The input to validate.
* @returns The validated input against the list of string literals.
*/
static stringInput(...value: any[]): any;
/**
* Validates an instance against a given class or constructor.
* @param i The class or constructor function.
* @param value The instance to validate.
* @returns The validated instance.
*/
static instance(i: any, value: any): any;
}
export { EventEmitter, Validator };
export default EventEmitter;
}