@prozilla-os/shared 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/main.d.ts +819 -34
- package/dist/main.js +1000 -85
- package/dist/main.js.map +1 -1
- package/package.json +11 -9
package/dist/main.d.ts
CHANGED
|
@@ -1,71 +1,856 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ANSI escape codes.
|
|
3
|
+
*
|
|
4
|
+
* @see [ANSI escape code - Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code).
|
|
5
|
+
*/
|
|
1
6
|
export declare const ANSI: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Foreground colors.
|
|
9
|
+
*/
|
|
10
|
+
readonly fg: {
|
|
11
|
+
readonly black: "\u001B[30m";
|
|
12
|
+
readonly red: "\u001B[31m";
|
|
13
|
+
readonly green: "\u001B[32m";
|
|
14
|
+
readonly yellow: "\u001B[33m";
|
|
15
|
+
readonly blue: "\u001B[34m";
|
|
16
|
+
readonly magenta: "\u001B[35m";
|
|
17
|
+
readonly cyan: "\u001B[36m";
|
|
18
|
+
readonly white: "\u001B[37m";
|
|
11
19
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Background colors.
|
|
22
|
+
*/
|
|
23
|
+
readonly bg: {
|
|
24
|
+
readonly black: "\u001B[40m";
|
|
25
|
+
readonly red: "\u001B[41m";
|
|
26
|
+
readonly green: "\u001B[42m";
|
|
27
|
+
readonly yellow: "\u001B[43m";
|
|
28
|
+
readonly blue: "\u001B[44m";
|
|
29
|
+
readonly magenta: "\u001B[45m";
|
|
30
|
+
readonly cyan: "\u001B[46m";
|
|
31
|
+
readonly white: "\u001B[47m";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Screen buffer and clearing controls.
|
|
35
|
+
*/
|
|
36
|
+
readonly screen: {
|
|
37
|
+
readonly enterAltBuffer: "\u001B[?1049h";
|
|
38
|
+
readonly exitAltBuffer: "\u001B[?1049l";
|
|
39
|
+
readonly clear: "\u001B[2J";
|
|
40
|
+
readonly clearLine: "\u001B[2K";
|
|
41
|
+
readonly home: "\u001B[H";
|
|
16
42
|
};
|
|
17
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Cursor controls.
|
|
45
|
+
*/
|
|
46
|
+
readonly cursor: {
|
|
47
|
+
/** Changes the position of the cursor. */
|
|
48
|
+
readonly position: (row: number, column: number) => string;
|
|
49
|
+
readonly hide: "\u001B[?25l";
|
|
50
|
+
readonly show: "\u001B[?25h";
|
|
51
|
+
readonly save: "\u001B[s";
|
|
52
|
+
readonly restore: "\u001B[u";
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Terminal input.
|
|
56
|
+
*/
|
|
57
|
+
readonly input: {
|
|
58
|
+
/** Move cursor up. */
|
|
59
|
+
readonly arrowUp: "\u001B[A";
|
|
60
|
+
/** Move cursor down. */
|
|
61
|
+
readonly arrowDown: "\u001B[B";
|
|
62
|
+
/** Move cursor right. */
|
|
63
|
+
readonly arrowRight: "\u001B[C";
|
|
64
|
+
/** Move cursor left. */
|
|
65
|
+
readonly arrowLeft: "\u001B[D";
|
|
66
|
+
readonly horizontalTab: "\t";
|
|
67
|
+
readonly lineFeed: "\n";
|
|
68
|
+
readonly verticalTab: "\v";
|
|
69
|
+
readonly formFeed: "\f";
|
|
70
|
+
readonly carriageReturn: "\r";
|
|
71
|
+
readonly backspace: "\b";
|
|
72
|
+
readonly delete: "";
|
|
73
|
+
readonly escape: "\u001B";
|
|
74
|
+
readonly pageUp: "\u001B[5~";
|
|
75
|
+
readonly pageDown: "\u001B[6~";
|
|
76
|
+
readonly ctrlA: "\u0001";
|
|
77
|
+
readonly ctrlB: "\u0002";
|
|
78
|
+
readonly ctrlC: "\u0003";
|
|
79
|
+
readonly ctrlD: "\u0004";
|
|
80
|
+
readonly ctrlE: "\u0005";
|
|
81
|
+
readonly ctrlF: "\u0006";
|
|
82
|
+
readonly ctrlG: "\u0007";
|
|
83
|
+
readonly ctrlH: "\b";
|
|
84
|
+
readonly ctrlI: "\t";
|
|
85
|
+
readonly ctrlJ: "\n";
|
|
86
|
+
readonly ctrlK: "\v";
|
|
87
|
+
readonly ctrlL: "\f";
|
|
88
|
+
readonly ctrlM: "\r";
|
|
89
|
+
readonly ctrlN: "\u000E";
|
|
90
|
+
readonly ctrlO: "\u000F";
|
|
91
|
+
readonly ctrlP: "\u0010";
|
|
92
|
+
readonly ctrlQ: "\u0011";
|
|
93
|
+
readonly ctrlR: "\u0012";
|
|
94
|
+
readonly ctrlS: "\u0013";
|
|
95
|
+
readonly ctrlT: "\u0014";
|
|
96
|
+
readonly ctrlU: "\u0015";
|
|
97
|
+
readonly ctrlV: "\u0016";
|
|
98
|
+
readonly ctrlW: "\u0017";
|
|
99
|
+
readonly ctrlX: "\u0018";
|
|
100
|
+
readonly ctrlY: "\u0019";
|
|
101
|
+
readonly ctrlZ: "\u001A";
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Decorations.
|
|
105
|
+
*/
|
|
106
|
+
readonly decoration: {
|
|
107
|
+
readonly dim: "\u001B[2m";
|
|
108
|
+
readonly bold: "\u001B[1m";
|
|
109
|
+
readonly italic: "\u001B[3m";
|
|
110
|
+
readonly underline: "\u001B[4m";
|
|
111
|
+
readonly blink: "\u001B[5m";
|
|
112
|
+
readonly invert: "\u001B[7m";
|
|
113
|
+
readonly strike: "\u001B[9m";
|
|
114
|
+
};
|
|
115
|
+
readonly reset: "\u001B[0m";
|
|
18
116
|
};
|
|
19
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Provides utility functions for wrapping text in ANSI escape codes.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link ANSI}
|
|
122
|
+
* @hideconstructor
|
|
123
|
+
*/
|
|
124
|
+
export declare class Ansi {
|
|
125
|
+
#private;
|
|
126
|
+
/**
|
|
127
|
+
* Makes text black using {@link ANSI.fg.black}.
|
|
128
|
+
*/
|
|
129
|
+
static black(text: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* Makes text red using {@link ANSI.fg.red}.
|
|
132
|
+
*/
|
|
133
|
+
static red(text: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Makes text green using {@link ANSI.fg.green}.
|
|
136
|
+
*/
|
|
137
|
+
static green(text: string): string;
|
|
138
|
+
/**
|
|
139
|
+
* Makes text yellow using {@link ANSI.fg.yellow}.
|
|
140
|
+
*/
|
|
141
|
+
static yellow(text: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Makes text blue using {@link ANSI.fg.blue}.
|
|
144
|
+
*/
|
|
145
|
+
static blue(text: string): string;
|
|
146
|
+
/**
|
|
147
|
+
* Makes text magenta using {@link ANSI.fg.magenta}.
|
|
148
|
+
*/
|
|
149
|
+
static magenta(text: string): string;
|
|
150
|
+
/**
|
|
151
|
+
* Makes text cyan using {@link ANSI.fg.cyan}.
|
|
152
|
+
*/
|
|
153
|
+
static cyan(text: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Makes text white using {@link ANSI.fg.white}.
|
|
156
|
+
*/
|
|
157
|
+
static white(text: string): string;
|
|
158
|
+
/**
|
|
159
|
+
* Sets background to black using {@link ANSI.bg.black}.
|
|
160
|
+
*/
|
|
161
|
+
static blackBackground(text: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Sets background to red using {@link ANSI.bg.red}.
|
|
164
|
+
*/
|
|
165
|
+
static redBackground(text: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Sets background to green using {@link ANSI.bg.green}.
|
|
168
|
+
*/
|
|
169
|
+
static greenBackground(text: string): string;
|
|
170
|
+
/**
|
|
171
|
+
* Sets background to yellow using {@link ANSI.bg.yellow}.
|
|
172
|
+
*/
|
|
173
|
+
static yellowBackground(text: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* Sets background to blue using {@link ANSI.bg.blue}.
|
|
176
|
+
*/
|
|
177
|
+
static blueBackground(text: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* Sets background to magenta using {@link ANSI.bg.magenta}.
|
|
180
|
+
*/
|
|
181
|
+
static magentaBackground(text: string): string;
|
|
182
|
+
/**
|
|
183
|
+
* Sets background to cyan using {@link ANSI.bg.cyan}.
|
|
184
|
+
*/
|
|
185
|
+
static cyanBackground(text: string): string;
|
|
186
|
+
/**
|
|
187
|
+
* Sets background to white using {@link ANSI.bg.white}.
|
|
188
|
+
*/
|
|
189
|
+
static whiteBackground(text: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* Makes text bold using {@link ANSI.decoration.bold}.
|
|
192
|
+
*/
|
|
193
|
+
static bold(text: string): string;
|
|
194
|
+
/**
|
|
195
|
+
* Makes text dim using {@link ANSI.decoration.dim}.
|
|
196
|
+
*/
|
|
197
|
+
static dim(text: string): string;
|
|
198
|
+
/**
|
|
199
|
+
* Makes text italic using {@link ANSI.decoration.italic}.
|
|
200
|
+
*/
|
|
201
|
+
static italic(text: string): string;
|
|
202
|
+
/**
|
|
203
|
+
* Underlines text using {@link ANSI.decoration.underline}.
|
|
204
|
+
*/
|
|
205
|
+
static underline(text: string): string;
|
|
206
|
+
/**
|
|
207
|
+
* Inverts foreground and background colors using {@link ANSI.decoration.invert}.
|
|
208
|
+
*/
|
|
209
|
+
static invert(text: string): string;
|
|
210
|
+
/**
|
|
211
|
+
* Makes text strike through using {@link ANSI.decoration.strike}.
|
|
212
|
+
*/
|
|
213
|
+
static strike(text: string): string;
|
|
214
|
+
/**
|
|
215
|
+
* Removes all ANSI escape sequences.
|
|
216
|
+
*/
|
|
217
|
+
static strip(text: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* Removes ANSI escape sequences for colors and background colors (SGR).
|
|
220
|
+
*/
|
|
221
|
+
static stripColors(text: string): string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare abstract class BaseResult<V, E> {
|
|
225
|
+
/**
|
|
226
|
+
* Returns `true` if this result is a {@link Result.Success}.
|
|
227
|
+
*/
|
|
228
|
+
isOk(): this is Result.Success<V, E>;
|
|
229
|
+
/**
|
|
230
|
+
* Returns `true` if this result is a {@link Result.Failure}.
|
|
231
|
+
*/
|
|
232
|
+
isError(): this is Result.Failure<V, E>;
|
|
233
|
+
/**
|
|
234
|
+
* Transforms the value of this result using the provided callback if this is a {@link Result.Success}.
|
|
235
|
+
* Does nothing if this result is a {@link Result.Failure}.
|
|
236
|
+
*/
|
|
237
|
+
abstract map<W>(callback: (value: V) => W): Result<W, E>;
|
|
238
|
+
/**
|
|
239
|
+
* Transforms the error of this result using the provided callback if this is a {@link Result.Failure}.
|
|
240
|
+
* Does nothing if this result is a {@link Result.Success}.
|
|
241
|
+
*/
|
|
242
|
+
abstract mapError<F>(callback: (error: E) => F): Result<V, F>;
|
|
243
|
+
/**
|
|
244
|
+
* Chains a new {@link Result}-returning operation to this result if this is a {@link Result.Success}.
|
|
245
|
+
* Does nothing if this result is a {@link Result.Failure}.
|
|
246
|
+
*/
|
|
247
|
+
abstract next<W, F>(callback: (value: V) => Result<W, F>): Result<W, E | F>;
|
|
248
|
+
/**
|
|
249
|
+
* Provides a recovery path for this result if this is a {@link Result.Failure} by returning a new {@link Result}.
|
|
250
|
+
* Does nothing if this result is a {@link Result.Success}.
|
|
251
|
+
*/
|
|
252
|
+
abstract orElse<W, F>(callback: (error: E) => Result<W, F>): Result<V | W, F | E>;
|
|
253
|
+
/**
|
|
254
|
+
* Returns the {@link Result.Success} value of this instance or the provided default value if this is a {@link Result.Failure}.
|
|
255
|
+
*/
|
|
256
|
+
abstract unwrapOr<W>(defaultValue: W): V | W;
|
|
257
|
+
/**
|
|
258
|
+
* Executes the `ok` callback if this is a {@link Result.Success}, or the `error` callback
|
|
259
|
+
* if this is a {@link Result.Failure}, returning the result.
|
|
260
|
+
*/
|
|
261
|
+
abstract match<A, B>(ok: (value: V) => A, error: (error: E) => B): A | B;
|
|
262
|
+
/**
|
|
263
|
+
* Executes a callback for side effects if this result is a {@link Result.Success}.
|
|
264
|
+
*/
|
|
265
|
+
ifOk(callback: (value: V) => void): this;
|
|
266
|
+
/**
|
|
267
|
+
* Executes a callback for side effects if this result is a {@link Result.Failure}.
|
|
268
|
+
*/
|
|
269
|
+
ifError(callback: (error: E) => void): this;
|
|
270
|
+
/**
|
|
271
|
+
* Validates the value of this result against a predicate.
|
|
272
|
+
* Converts to {@link Result.Failure} if the predicate returns `false`.
|
|
273
|
+
* Does nothing if this result is already a {@link Result.Failure}.
|
|
274
|
+
*/
|
|
275
|
+
abstract filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
276
|
+
abstract filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare function bold(text: string): string;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Clamps a value between an upper and lower bound.
|
|
283
|
+
* @param value - The value to clamp.
|
|
284
|
+
* @param min - The lower bound.
|
|
285
|
+
* @param max - The upper bound.
|
|
286
|
+
* @returns The clamped value.
|
|
287
|
+
*/
|
|
20
288
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
21
289
|
|
|
22
|
-
|
|
290
|
+
declare function code(text: string): string;
|
|
291
|
+
|
|
292
|
+
declare function codeBlock(text: string): string;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* A simple event emitter.
|
|
296
|
+
* @typeParam T - A record of all events.
|
|
297
|
+
*/
|
|
298
|
+
export declare class EventEmitter<T extends Record<keyof T, unknown[]>> {
|
|
23
299
|
#private;
|
|
24
|
-
static EVENT_NAMES: EventNamesMap;
|
|
25
300
|
/**
|
|
26
|
-
*
|
|
301
|
+
* Starts listening to an event.
|
|
302
|
+
* @param event - The event to listen to.
|
|
303
|
+
* @param listener - The function to call when the event is emitted.
|
|
304
|
+
* @returns The listener.
|
|
305
|
+
*/
|
|
306
|
+
on<K extends keyof T>(event: K, listener: Listener<T, K>): Listener<T, K>;
|
|
307
|
+
/**
|
|
308
|
+
* Registers an event listener that is automatically removed when called.
|
|
309
|
+
* @param event - The event to listen to.
|
|
310
|
+
* @param listener - The function to call once the event is emitted.
|
|
311
|
+
* @returns The wrapped listener.
|
|
312
|
+
*/
|
|
313
|
+
once<K extends keyof T>(event: K, listener: Listener<T, K>): Listener<T, K>;
|
|
314
|
+
/**
|
|
315
|
+
* Removes an event listener.
|
|
316
|
+
* @param event - The event to remove the listener from.
|
|
317
|
+
* @param listener - The listener to remove.
|
|
27
318
|
*/
|
|
28
|
-
|
|
319
|
+
off<K extends keyof T>(event: K, listener: Listener<T, K>): void;
|
|
29
320
|
/**
|
|
30
|
-
*
|
|
321
|
+
* Emits an event to all its listeners.
|
|
322
|
+
* @param event - The event to emit.
|
|
323
|
+
* @param args - The arguments to pass to the listeners.
|
|
31
324
|
*/
|
|
32
|
-
|
|
325
|
+
emit<K extends keyof T>(event: K, ...args: T[K]): void;
|
|
33
326
|
/**
|
|
34
|
-
*
|
|
327
|
+
* Emits an event and waits for all listeners to resolve.
|
|
328
|
+
* @param event - The event to emit.
|
|
329
|
+
* @param args - The arguments to pass to the listeners.
|
|
35
330
|
*/
|
|
36
|
-
|
|
331
|
+
emitAsync<K extends keyof T>(event: K, ...args: T[K]): Promise<void>;
|
|
37
332
|
}
|
|
38
333
|
|
|
39
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Formats time relative to now.
|
|
336
|
+
* @param date - The date.
|
|
337
|
+
* @param maxLength - The maximum amount of units, e.g.: 3 => years, months, days.
|
|
338
|
+
*/
|
|
339
|
+
export declare function formatRelativeTime(date: Date, maxLength?: number, allowAffixes?: boolean): string;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Applies a format to a string.
|
|
343
|
+
* @param text - The text to format.
|
|
344
|
+
* @returns The formatted text.
|
|
345
|
+
*/
|
|
346
|
+
export declare type Formatter = (text: string) => string;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Formats time in a human-readable format.
|
|
350
|
+
* @param time - Time in milliseconds.
|
|
351
|
+
* @param maxLength - The maximum amount of units, e.g.: 3 => years, months, days.
|
|
352
|
+
*/
|
|
353
|
+
export declare function formatTime(time: number, maxLength?: number, allowAffixes?: boolean): string;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Returns the longest common prefix from a list of strings.
|
|
357
|
+
*/
|
|
358
|
+
export declare function getLongestCommonPrefix(strings: string[]): string;
|
|
359
|
+
|
|
360
|
+
declare function heading1(text: string): string;
|
|
361
|
+
|
|
362
|
+
declare function heading2(text: string): string;
|
|
363
|
+
|
|
364
|
+
declare function heading3(text: string): string;
|
|
365
|
+
|
|
366
|
+
declare function heading4(text: string): string;
|
|
367
|
+
|
|
368
|
+
declare function heading5(text: string): string;
|
|
369
|
+
|
|
370
|
+
declare function heading6(text: string): string;
|
|
371
|
+
|
|
372
|
+
declare function horizontalRule(): string;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Checks if `input` is a valid integer.
|
|
376
|
+
*/
|
|
377
|
+
export declare function isValidInteger(input: number | string): boolean;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Checks if `input` is a valid number.
|
|
381
|
+
*/
|
|
382
|
+
export declare function isValidNumber(input: number | string): boolean;
|
|
383
|
+
|
|
384
|
+
declare function italic(text: string): string;
|
|
40
385
|
|
|
41
386
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param date - The date
|
|
44
|
-
* @param maxLength - The maximum amount of units, e.g.: 3 => years, months, days
|
|
387
|
+
* Converts a kebab-case string to camelCase.
|
|
45
388
|
*/
|
|
46
|
-
export declare function
|
|
389
|
+
export declare function kebabToCamelCase(value: string): string;
|
|
390
|
+
|
|
391
|
+
declare function link(label: string, url: string): string;
|
|
47
392
|
|
|
48
393
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @
|
|
51
|
-
* @
|
|
394
|
+
* A function that handles an event.
|
|
395
|
+
* @typeParam T - A record of all events.
|
|
396
|
+
* @typeParam K - The event this function handles.
|
|
52
397
|
*/
|
|
53
|
-
export declare
|
|
398
|
+
export declare type Listener<T extends Record<keyof T, unknown[]>, K extends keyof T> = (...args: T[K]) => void | Promise<void>;
|
|
54
399
|
|
|
55
|
-
|
|
400
|
+
/**
|
|
401
|
+
* A simple wrapper for {@link console} that logs formatted text and supports log levels.
|
|
402
|
+
*/
|
|
403
|
+
export declare class Logger {
|
|
404
|
+
#private;
|
|
405
|
+
/**
|
|
406
|
+
* The minimum log level or an array of log levels to enable.
|
|
407
|
+
*
|
|
408
|
+
* `undefined` enables all log levels. An array enables all log levels in that array. A single level enables that log level and the ones above.
|
|
409
|
+
* @default LogLevel.Debug
|
|
410
|
+
*/
|
|
411
|
+
level?: LogLevel | LogLevel[];
|
|
412
|
+
/**
|
|
413
|
+
* The current level of indentation.
|
|
414
|
+
* @default 0
|
|
415
|
+
*/
|
|
416
|
+
indent: number;
|
|
417
|
+
/**
|
|
418
|
+
* The string to use for indentation.
|
|
419
|
+
* @default "\t"
|
|
420
|
+
*/
|
|
421
|
+
indentString?: string;
|
|
422
|
+
/**
|
|
423
|
+
* The function to use when highlighting text.
|
|
424
|
+
* @default Ansi.cyan
|
|
425
|
+
* @see {@link Ansi.cyan}
|
|
426
|
+
*/
|
|
427
|
+
highlight: Formatter;
|
|
428
|
+
/**
|
|
429
|
+
* The function to use when emphasizing text.
|
|
430
|
+
* @default Ansi.bold
|
|
431
|
+
* @see {@link Ansi.bold}
|
|
432
|
+
*/
|
|
433
|
+
emphasize: Formatter;
|
|
434
|
+
/**
|
|
435
|
+
* The prefixes to prepend to logs.
|
|
436
|
+
* @default {
|
|
437
|
+
[LogLevel.Info]: Ansi.cyan("[info]"),
|
|
438
|
+
[LogLevel.Success]: Ansi.green("[success]"),
|
|
439
|
+
[LogLevel.Warning]: Ansi.yellow("[warning]"),
|
|
440
|
+
[LogLevel.Error]: Ansi.red("[error]"),
|
|
441
|
+
}
|
|
442
|
+
*/
|
|
443
|
+
prefix: {
|
|
444
|
+
[key in LogLevel | "global"]?: string;
|
|
445
|
+
};
|
|
446
|
+
get errorCount(): number;
|
|
447
|
+
set errorCount(value: number);
|
|
448
|
+
get warningCount(): number;
|
|
449
|
+
set warningCount(value: number);
|
|
450
|
+
constructor(options?: {
|
|
451
|
+
/** {@inheritDoc Logger.level}. */
|
|
452
|
+
level?: Logger["level"];
|
|
453
|
+
/**
|
|
454
|
+
* The prefix(es) to prepend to logs.
|
|
455
|
+
*
|
|
456
|
+
* Does not override default prefixes unless specified.
|
|
457
|
+
*/
|
|
458
|
+
prefix?: Logger["prefix"] | string;
|
|
459
|
+
});
|
|
460
|
+
/**
|
|
461
|
+
* @param level - The minimum log level.
|
|
462
|
+
*/
|
|
463
|
+
constructor(level: LogLevel);
|
|
464
|
+
/**
|
|
465
|
+
* @param levels - The log levels to enable.
|
|
466
|
+
*/
|
|
467
|
+
constructor(levels: LogLevel[]);
|
|
468
|
+
/**
|
|
469
|
+
* Resets all properties to their default values.
|
|
470
|
+
*/
|
|
471
|
+
reset(): this;
|
|
472
|
+
/**
|
|
473
|
+
* Calls a function while the level of indentation is increased.
|
|
474
|
+
*
|
|
475
|
+
* Increases the level of indentation, then calls the function and finally restores the indentation.
|
|
476
|
+
* @param callback - The function to call.
|
|
477
|
+
* @param indentation - The amount of indentation to use.
|
|
478
|
+
*/
|
|
479
|
+
indented(callback: (this: undefined) => void, indentation?: number): this;
|
|
480
|
+
/**
|
|
481
|
+
* Logs every line while the level of indentation is increased.
|
|
482
|
+
*
|
|
483
|
+
* Increases the level of indentation, then logs every line and finally restores the indentation.
|
|
484
|
+
* @param lines - The lines to log.
|
|
485
|
+
* @param indentation - The amount of indentation to use.
|
|
486
|
+
* @param level - The log level.
|
|
487
|
+
*/
|
|
488
|
+
indented(lines: unknown[], indentation?: number, level?: LogLevel): this;
|
|
489
|
+
/**
|
|
490
|
+
* Logs a message while the level of indentation is increased.
|
|
491
|
+
*
|
|
492
|
+
* Increases the level of indentation, then logs the message and finally restores the indentation.
|
|
493
|
+
* @param message - The message to log.
|
|
494
|
+
* @param indentation - The amount of indentation to use.
|
|
495
|
+
* @param level - The log level.
|
|
496
|
+
*/
|
|
497
|
+
indented(message: unknown, indentation?: number, level?: LogLevel): this;
|
|
498
|
+
/**
|
|
499
|
+
* Increases the level of indentation.
|
|
500
|
+
* @param amount - The amount to increase the level of indentation with.
|
|
501
|
+
*/
|
|
502
|
+
tab(amount?: number): this;
|
|
503
|
+
/**
|
|
504
|
+
* Decreases the level of indentation.
|
|
505
|
+
* @param amount - The amount to decrease the level of indentation with.
|
|
506
|
+
*/
|
|
507
|
+
shiftTab(amount?: number): this;
|
|
508
|
+
/**
|
|
509
|
+
* Sets the prefix to prepend to all logs.
|
|
510
|
+
* @param prefix - The prefix to use.
|
|
511
|
+
*/
|
|
512
|
+
setPrefix(prefix: string): this;
|
|
513
|
+
/**
|
|
514
|
+
* Sets the prefixes to prepend to logs.
|
|
515
|
+
*
|
|
516
|
+
* Will override any existing prefixes.
|
|
517
|
+
* @param prefixes - The prefixes to use.
|
|
518
|
+
*/
|
|
519
|
+
setPrefix(prefixes: Logger["prefix"]): this;
|
|
520
|
+
/**
|
|
521
|
+
* Sets the prefix to prepend to logs at a given log level.
|
|
522
|
+
* @param level - The log level.
|
|
523
|
+
* @param prefix - The prefix to use.
|
|
524
|
+
*/
|
|
525
|
+
setPrefix(level: LogLevel, prefix: string): this;
|
|
526
|
+
/**
|
|
527
|
+
* Logs an info message about a URL being fetched.
|
|
528
|
+
* @param url - The URL being fetched.
|
|
529
|
+
*/
|
|
530
|
+
fetching(url: string): this;
|
|
531
|
+
/**
|
|
532
|
+
* Logs an info message that implies a pending state.
|
|
533
|
+
* @param message - The status message.
|
|
534
|
+
*/
|
|
535
|
+
pending(message: string): this;
|
|
536
|
+
/**
|
|
537
|
+
* Logs an error message.
|
|
538
|
+
* @param message - The error message or reason.
|
|
539
|
+
* @param details - The details of the error message.
|
|
540
|
+
*/
|
|
541
|
+
error(message: unknown, ...details: unknown[]): this;
|
|
542
|
+
/**
|
|
543
|
+
* Logs a warning message.
|
|
544
|
+
* @param message - The warning message.
|
|
545
|
+
* @param details - The details of the warning message.
|
|
546
|
+
*/
|
|
547
|
+
warn(message: string, ...details: unknown[]): this;
|
|
548
|
+
/**
|
|
549
|
+
* Logs a success message.
|
|
550
|
+
* @param message - The success message.
|
|
551
|
+
* @param details - The details of the success message.
|
|
552
|
+
*/
|
|
553
|
+
success(message: string, ...details: unknown[]): this;
|
|
554
|
+
/**
|
|
555
|
+
* Logs an info message.
|
|
556
|
+
* @param message - The info message.
|
|
557
|
+
* @param details - The details of the info message.
|
|
558
|
+
*/
|
|
559
|
+
info(message: string, ...details: unknown[]): this;
|
|
560
|
+
/**
|
|
561
|
+
* Logs a status message.
|
|
562
|
+
* @param message - The status message.
|
|
563
|
+
* @param details - The details of the status message.
|
|
564
|
+
* @param level - The log level.
|
|
565
|
+
*/
|
|
566
|
+
statusMessage(message: string, details: unknown[], level?: LogLevel): this;
|
|
567
|
+
/**
|
|
568
|
+
* Logs the amount of errors and warnings that have been logged since the previous call to this function or the creation of this logger.
|
|
569
|
+
*/
|
|
570
|
+
summary(): this;
|
|
571
|
+
/**
|
|
572
|
+
* Logs a labeled parameter.
|
|
573
|
+
*
|
|
574
|
+
* The value is emphasized using {@link emphasize}.
|
|
575
|
+
* @param label - The label of the parameter.
|
|
576
|
+
* @param value - The value of the parameter.
|
|
577
|
+
* @param level - The log level.
|
|
578
|
+
*/
|
|
579
|
+
parameter(label: string, value: unknown, level?: LogLevel): this;
|
|
580
|
+
/**
|
|
581
|
+
* Logs properties as a list of key-value pairs.
|
|
582
|
+
* @param properties - The properties to log.
|
|
583
|
+
* @param level - The log level.
|
|
584
|
+
* @see {@link value()}
|
|
585
|
+
*/
|
|
586
|
+
properties(properties: Record<string, unknown>, level?: LogLevel): this;
|
|
587
|
+
/**
|
|
588
|
+
* Logs a labeled value.
|
|
589
|
+
*
|
|
590
|
+
* The value is highlighted using {@link highlight}.
|
|
591
|
+
* @param label - The label of the value.
|
|
592
|
+
* @param value - The value.
|
|
593
|
+
* @param level - The log level.
|
|
594
|
+
*/
|
|
595
|
+
value(label: string, value: unknown, level?: LogLevel): this;
|
|
596
|
+
/**
|
|
597
|
+
* Logs emphasized text.
|
|
598
|
+
* @param text - The text to log.
|
|
599
|
+
* @param level - The log level.
|
|
600
|
+
*/
|
|
601
|
+
emphasized(text: string, level?: LogLevel): this;
|
|
602
|
+
/**
|
|
603
|
+
* Logs highlighted text.
|
|
604
|
+
* @param text - The text to log.
|
|
605
|
+
* @param level - The log level.
|
|
606
|
+
*/
|
|
607
|
+
highlighted(text: string, level?: LogLevel): this;
|
|
608
|
+
/**
|
|
609
|
+
* Logs each item on a new line.
|
|
610
|
+
* @param lines - The items to log.
|
|
611
|
+
* @param level - The log level.
|
|
612
|
+
*/
|
|
613
|
+
lines(lines: unknown[], level?: LogLevel): this;
|
|
614
|
+
/**
|
|
615
|
+
* Logs a message.
|
|
616
|
+
* @param message - The message to log.
|
|
617
|
+
* @param level - The log level.
|
|
618
|
+
*/
|
|
619
|
+
log(message: unknown, level?: LogLevel): this;
|
|
620
|
+
/**
|
|
621
|
+
* Logs text using this logger's format.
|
|
622
|
+
* @param text - The text to log.
|
|
623
|
+
* @param level - The log level.
|
|
624
|
+
*/
|
|
625
|
+
text(text: string, level?: LogLevel): this;
|
|
626
|
+
/**
|
|
627
|
+
* Logs an newline character.
|
|
628
|
+
*/
|
|
629
|
+
newLine(): this;
|
|
630
|
+
/**
|
|
631
|
+
* Checks if the given log level is enabled.
|
|
632
|
+
* @param level - The log level to check.
|
|
633
|
+
*/
|
|
634
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
635
|
+
/**
|
|
636
|
+
* Formats text using this logger's formatting properties.
|
|
637
|
+
* @param text - The text to format.
|
|
638
|
+
*/
|
|
639
|
+
format(text: string): string;
|
|
640
|
+
/**
|
|
641
|
+
* Prepends a prefix to text.
|
|
642
|
+
* @param text - The text to apply the prefix to.
|
|
643
|
+
* @param level - The log level.
|
|
644
|
+
*/
|
|
645
|
+
applyPrefix(text: string, level?: LogLevel): string;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export declare enum LogLevel {
|
|
649
|
+
Debug = 0,
|
|
650
|
+
Info = 1,
|
|
651
|
+
Success = 2,
|
|
652
|
+
Warning = 3,
|
|
653
|
+
Error = 4
|
|
654
|
+
}
|
|
56
655
|
|
|
57
|
-
export declare
|
|
656
|
+
export declare namespace Markdown {
|
|
657
|
+
export {
|
|
658
|
+
heading1,
|
|
659
|
+
heading2,
|
|
660
|
+
heading3,
|
|
661
|
+
heading4,
|
|
662
|
+
heading5,
|
|
663
|
+
heading6,
|
|
664
|
+
bold,
|
|
665
|
+
italic,
|
|
666
|
+
code,
|
|
667
|
+
codeBlock,
|
|
668
|
+
strikethrough,
|
|
669
|
+
link,
|
|
670
|
+
quote,
|
|
671
|
+
horizontalRule
|
|
672
|
+
}
|
|
673
|
+
}
|
|
58
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Converts a string to a boolean.
|
|
677
|
+
* @param input - The string to parse.
|
|
678
|
+
*/
|
|
59
679
|
export declare function parseBool(input: string): boolean;
|
|
60
680
|
|
|
681
|
+
export declare function parseOptionalFloat(input?: string, defaultValue?: number): number;
|
|
682
|
+
|
|
683
|
+
export declare function parseOptionalInteger(input?: string, defaultValue?: number): number;
|
|
684
|
+
|
|
685
|
+
declare function quote(text: string): string;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Returns a random item from an array.
|
|
689
|
+
*/
|
|
61
690
|
export declare function randomFromArray<Type>(array: Type[]): Type;
|
|
62
691
|
|
|
692
|
+
/**
|
|
693
|
+
* Returns a random value inside a range.
|
|
694
|
+
* @param min - The lower bound.
|
|
695
|
+
* @param max - The upper bound.
|
|
696
|
+
*/
|
|
63
697
|
export declare function randomRange(min: number, max: number): number;
|
|
64
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Removes all duplicate items from an array.
|
|
701
|
+
*/
|
|
65
702
|
export declare function removeDuplicatesFromArray<Type>(array: Type[]): Type[];
|
|
66
703
|
|
|
704
|
+
/**
|
|
705
|
+
* Removes an item from an array.
|
|
706
|
+
* @param item - The item to remove.
|
|
707
|
+
*/
|
|
67
708
|
export declare function removeFromArray<Type>(item: Type, array: Type[]): void;
|
|
68
709
|
|
|
69
|
-
|
|
710
|
+
/**
|
|
711
|
+
* Represents either a success or a failure.
|
|
712
|
+
*
|
|
713
|
+
* Can be used as the return value of a function instead of throwing errors.
|
|
714
|
+
* This improves type-safety and helps you control the flow of your function.
|
|
715
|
+
*
|
|
716
|
+
* This is inspired by [neverthrow by supermacro](https://github.com/supermacro/neverthrow).
|
|
717
|
+
*
|
|
718
|
+
* A success can be created using {@link Result.ok} and a failure using {@link Result.error}.
|
|
719
|
+
*/
|
|
720
|
+
export declare type Result<T, E> = Result.Success<T, E> | Result.Failure<T, E>;
|
|
721
|
+
|
|
722
|
+
export declare namespace Result {
|
|
723
|
+
/**
|
|
724
|
+
* Represents the result of a successful operation.
|
|
725
|
+
*/
|
|
726
|
+
export class Success<V, E> extends BaseResult<V, E> {
|
|
727
|
+
readonly value: V;
|
|
728
|
+
constructor(value: V);
|
|
729
|
+
isOk(): this is Success<V, E>;
|
|
730
|
+
map<W>(callback: (value: V) => W): Result<W, E>;
|
|
731
|
+
mapError<F>(_callback: (error: E) => F): Result<V, F>;
|
|
732
|
+
next<W, F>(callback: (value: V) => Result<W, F>): Result<W, E | F>;
|
|
733
|
+
orElse<W, F>(_callback: (error: E) => Result<W, F>): Result<V, E>;
|
|
734
|
+
unwrapOr<W>(_defaultValue: W): V;
|
|
735
|
+
match<A, B>(ok: (value: V) => A, _error: (error: E) => B): A;
|
|
736
|
+
filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
737
|
+
filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Represents the result of a failed operation.
|
|
741
|
+
*/
|
|
742
|
+
export class Failure<V, E> extends BaseResult<V, E> {
|
|
743
|
+
readonly error: E;
|
|
744
|
+
constructor(error: E);
|
|
745
|
+
isError(): this is Failure<V, E>;
|
|
746
|
+
map<W>(_callback: (value: V) => W): Result<W, E>;
|
|
747
|
+
mapError<F>(callback: (error: E) => F): Result<V, F>;
|
|
748
|
+
next<W, F>(_callback: (value: V) => Result<W, F>): Failure<W, E>;
|
|
749
|
+
orElse<W, F>(callback: (error: E) => Result<W, F>): Result<W, F>;
|
|
750
|
+
unwrapOr<W>(defaultValue: W): W;
|
|
751
|
+
match<A, B>(_ok: (value: V) => A, error: (error: E) => B): B;
|
|
752
|
+
filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
753
|
+
filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Creates a {@link Result.Success} instance.
|
|
757
|
+
*/
|
|
758
|
+
export function ok<T, E = never>(value: T): Success<T, E>;
|
|
759
|
+
/**
|
|
760
|
+
* Creates a {@link Result.Failure} instance.
|
|
761
|
+
*/
|
|
762
|
+
export function error<E, T = never>(error: E): Failure<T, E>;
|
|
763
|
+
/**
|
|
764
|
+
* Wraps a synchronous operation that might throw in a {@link Result}.
|
|
765
|
+
*/
|
|
766
|
+
export function wrap<V, E = Error>(callback: () => V, catcher?: (err: unknown) => E): Result<V, E>;
|
|
767
|
+
/**
|
|
768
|
+
* Converts a nullable value into a {@link Result}.
|
|
769
|
+
* Returns {@link Result.Failure} if the value is `null` or `undefined`.
|
|
770
|
+
*/
|
|
771
|
+
export function nonNullOr<V, E>(nullable: V | null | undefined, err: E): Result<NonNullable<V>, E>;
|
|
772
|
+
/**
|
|
773
|
+
* Converts a nullable value into a {@link Result} or executes a fallback {@link Result}-returning function.
|
|
774
|
+
*/
|
|
775
|
+
export function nonNullOrElse<V, W, E>(nullable: V | null | undefined, orElse: () => Result<W, E>): Result<NonNullable<V> | W, E>;
|
|
776
|
+
/**
|
|
777
|
+
* Repeatedly executes a {@link Result}-returning body while a condition is met.
|
|
778
|
+
*/
|
|
779
|
+
export function repeat<V, E>(initialValue: V, condition: (value: V) => boolean, body: (value: V) => Result<V, E>): Result<V, E>;
|
|
780
|
+
/**
|
|
781
|
+
* Reduces a collection into a {@link Result} by executing a {@link Result}-returning
|
|
782
|
+
* reducer for each item.
|
|
783
|
+
*/
|
|
784
|
+
export function reduce<T, V, E>(items: T[], reducer: (accumulator: V, item: T) => Result<V, E>, initialValue: V): Result<V, E>;
|
|
785
|
+
/**
|
|
786
|
+
* Collapses an array of {@link Result}s into a single {@link Result} containing an array of values.
|
|
787
|
+
* Returns the first {@link Result.Failure} encountered.
|
|
788
|
+
* Similar to {@link Promise.all}, but for synchronous {@link Result} collections.
|
|
789
|
+
*/
|
|
790
|
+
export function all<V, E>(results: Result<V, E>[]): Result<V[], E>;
|
|
791
|
+
/**
|
|
792
|
+
* Returns the first {@link Result.Success} produced by the callback for any item
|
|
793
|
+
* in the collection. If no success is found, it returns the provided default error {@link Result}.
|
|
794
|
+
* Similar to {@link Promise.any}, but for synchronous {@link Result} collections.
|
|
795
|
+
*/
|
|
796
|
+
export function any<T, V, E>(items: T[], callback: (item: T) => Result<V, E>, fallback: Result<V, E>): Result<V, E>;
|
|
797
|
+
/**
|
|
798
|
+
* Validates a subject against a type guard, producing a {@link Result}.
|
|
799
|
+
*/
|
|
800
|
+
export function require<T, U extends T, V, E>(subject: T, condition: (subject: T) => subject is U, createValue: (subject: U) => V, createError: (subject: T) => E): Result<V, E>;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Rounds a value.
|
|
805
|
+
* @param value - The value to round.
|
|
806
|
+
* @param precision - The precision to round with.
|
|
807
|
+
*/
|
|
808
|
+
export declare function round(value: number, precision?: number): number;
|
|
809
|
+
|
|
810
|
+
declare function strikethrough(text: string): string;
|
|
811
|
+
|
|
812
|
+
export declare class Vector2 {
|
|
813
|
+
x: number;
|
|
814
|
+
y: number;
|
|
815
|
+
constructor(xy: number);
|
|
816
|
+
constructor(x: number, y?: number);
|
|
817
|
+
static get ZERO(): Vector2;
|
|
818
|
+
get clone(): Vector2;
|
|
819
|
+
get magnitude(): number;
|
|
820
|
+
setX(x: number): this;
|
|
821
|
+
setY(y: number): this;
|
|
822
|
+
set(x: number, y: number): this;
|
|
823
|
+
round(): this;
|
|
824
|
+
normalize(): this;
|
|
825
|
+
scale(scalar: number): this;
|
|
826
|
+
getDistanceSquared(x: number, y?: number): number;
|
|
827
|
+
getDistanceSquared(vector2: Vector2): number;
|
|
828
|
+
getDistance(x: number, y?: number): number;
|
|
829
|
+
getDistance(vector2: Vector2): number;
|
|
830
|
+
add(x: number, y?: number): this;
|
|
831
|
+
add(vector2: Vector2): this;
|
|
832
|
+
subtract(x: number, y?: number): this;
|
|
833
|
+
subtract(vector2: Vector2): this;
|
|
834
|
+
multiply(x: number, y?: number): this;
|
|
835
|
+
multiply(vector2: Vector2): this;
|
|
836
|
+
divide(x: number, y?: number): this;
|
|
837
|
+
divide(vector2: Vector2): this;
|
|
838
|
+
lerp(vector2: Vector2, t: number): this;
|
|
839
|
+
static sum(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
840
|
+
static difference(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
841
|
+
static product(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
842
|
+
static division(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
843
|
+
static scale(vector2: Vector2, scalar: number): Vector2;
|
|
844
|
+
static normalize(vector2: Vector2): Vector2;
|
|
845
|
+
static lerp(vector2A: Vector2, vector2B: Vector2, t: number): Vector2;
|
|
846
|
+
static from({ x, y }: {
|
|
847
|
+
x: number;
|
|
848
|
+
y: number;
|
|
849
|
+
}): Vector2;
|
|
850
|
+
static parseVector(x: number | Vector2, y?: number): {
|
|
851
|
+
x: number;
|
|
852
|
+
y: number;
|
|
853
|
+
};
|
|
854
|
+
}
|
|
70
855
|
|
|
71
856
|
export { }
|