@prozilla-os/shared 1.3.0 → 1.5.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/chunks/index-PU_xBoDn.js +857 -0
- package/dist/chunks/index-PU_xBoDn.js.map +1 -0
- package/dist/chunks/object.utils-xiWGUq8N.js +15 -0
- package/dist/chunks/object.utils-xiWGUq8N.js.map +1 -0
- package/dist/logging.d.ts +711 -0
- package/dist/logging.js +17 -0
- package/dist/logging.js.map +1 -0
- package/dist/main.d.ts +785 -43
- package/dist/main.js +300 -674
- package/dist/main.js.map +1 -1
- package/dist/utils.d.ts +265 -0
- package/dist/utils.js +245 -0
- package/dist/utils.js.map +1 -0
- package/package.json +24 -9
package/dist/main.d.ts
CHANGED
|
@@ -7,47 +7,112 @@ export declare const ANSI: {
|
|
|
7
7
|
/**
|
|
8
8
|
* Foreground colors.
|
|
9
9
|
*/
|
|
10
|
-
fg: {
|
|
11
|
-
black:
|
|
12
|
-
red:
|
|
13
|
-
green:
|
|
14
|
-
yellow:
|
|
15
|
-
blue:
|
|
16
|
-
magenta:
|
|
17
|
-
cyan:
|
|
18
|
-
white:
|
|
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";
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Background colors.
|
|
22
22
|
*/
|
|
23
|
-
bg: {
|
|
24
|
-
black:
|
|
25
|
-
red:
|
|
26
|
-
green:
|
|
27
|
-
yellow:
|
|
28
|
-
blue:
|
|
29
|
-
magenta:
|
|
30
|
-
cyan:
|
|
31
|
-
white:
|
|
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
32
|
};
|
|
33
33
|
/**
|
|
34
34
|
* Screen buffer and clearing controls.
|
|
35
35
|
*/
|
|
36
|
-
screen: {
|
|
37
|
-
enterAltBuffer:
|
|
38
|
-
exitAltBuffer:
|
|
39
|
-
clear:
|
|
40
|
-
|
|
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";
|
|
42
|
+
};
|
|
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";
|
|
41
102
|
};
|
|
42
103
|
/**
|
|
43
104
|
* Decorations.
|
|
44
105
|
*/
|
|
45
|
-
decoration: {
|
|
46
|
-
dim:
|
|
47
|
-
bold:
|
|
48
|
-
|
|
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";
|
|
49
114
|
};
|
|
50
|
-
reset:
|
|
115
|
+
readonly reset: "\u001B[0m";
|
|
51
116
|
};
|
|
52
117
|
|
|
53
118
|
/**
|
|
@@ -57,7 +122,6 @@ export declare const ANSI: {
|
|
|
57
122
|
* @hideconstructor
|
|
58
123
|
*/
|
|
59
124
|
export declare class Ansi {
|
|
60
|
-
#private;
|
|
61
125
|
/**
|
|
62
126
|
* Makes text black using {@link ANSI.fg.black}.
|
|
63
127
|
*/
|
|
@@ -90,6 +154,38 @@ export declare class Ansi {
|
|
|
90
154
|
* Makes text white using {@link ANSI.fg.white}.
|
|
91
155
|
*/
|
|
92
156
|
static white(text: string): string;
|
|
157
|
+
/**
|
|
158
|
+
* Sets background to black using {@link ANSI.bg.black}.
|
|
159
|
+
*/
|
|
160
|
+
static blackBackground(text: string): string;
|
|
161
|
+
/**
|
|
162
|
+
* Sets background to red using {@link ANSI.bg.red}.
|
|
163
|
+
*/
|
|
164
|
+
static redBackground(text: string): string;
|
|
165
|
+
/**
|
|
166
|
+
* Sets background to green using {@link ANSI.bg.green}.
|
|
167
|
+
*/
|
|
168
|
+
static greenBackground(text: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Sets background to yellow using {@link ANSI.bg.yellow}.
|
|
171
|
+
*/
|
|
172
|
+
static yellowBackground(text: string): string;
|
|
173
|
+
/**
|
|
174
|
+
* Sets background to blue using {@link ANSI.bg.blue}.
|
|
175
|
+
*/
|
|
176
|
+
static blueBackground(text: string): string;
|
|
177
|
+
/**
|
|
178
|
+
* Sets background to magenta using {@link ANSI.bg.magenta}.
|
|
179
|
+
*/
|
|
180
|
+
static magentaBackground(text: string): string;
|
|
181
|
+
/**
|
|
182
|
+
* Sets background to cyan using {@link ANSI.bg.cyan}.
|
|
183
|
+
*/
|
|
184
|
+
static cyanBackground(text: string): string;
|
|
185
|
+
/**
|
|
186
|
+
* Sets background to white using {@link ANSI.bg.white}.
|
|
187
|
+
*/
|
|
188
|
+
static whiteBackground(text: string): string;
|
|
93
189
|
/**
|
|
94
190
|
* Makes text bold using {@link ANSI.decoration.bold}.
|
|
95
191
|
*/
|
|
@@ -98,6 +194,23 @@ export declare class Ansi {
|
|
|
98
194
|
* Makes text dim using {@link ANSI.decoration.dim}.
|
|
99
195
|
*/
|
|
100
196
|
static dim(text: string): string;
|
|
197
|
+
/**
|
|
198
|
+
* Makes text italic using {@link ANSI.decoration.italic}.
|
|
199
|
+
*/
|
|
200
|
+
static italic(text: string): string;
|
|
201
|
+
/**
|
|
202
|
+
* Underlines text using {@link ANSI.decoration.underline}.
|
|
203
|
+
*/
|
|
204
|
+
static underline(text: string): string;
|
|
205
|
+
/**
|
|
206
|
+
* Inverts foreground and background colors using {@link ANSI.decoration.invert}.
|
|
207
|
+
*/
|
|
208
|
+
static invert(text: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Makes text strike through using {@link ANSI.decoration.strike}.
|
|
211
|
+
*/
|
|
212
|
+
static strike(text: string): string;
|
|
213
|
+
static apply(text: string, code: string): string;
|
|
101
214
|
/**
|
|
102
215
|
* Removes all ANSI escape sequences.
|
|
103
216
|
*/
|
|
@@ -108,15 +221,72 @@ export declare class Ansi {
|
|
|
108
221
|
static stripColors(text: string): string;
|
|
109
222
|
}
|
|
110
223
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
224
|
+
export declare const BASE_URL = "https://os.prozilla.dev/";
|
|
225
|
+
|
|
226
|
+
export declare abstract class BaseResult<V, E> {
|
|
227
|
+
/**
|
|
228
|
+
* Returns `true` if this result is a {@link Result.Success}.
|
|
229
|
+
*/
|
|
230
|
+
isOk(): this is Result.Success<V, E>;
|
|
231
|
+
/**
|
|
232
|
+
* Returns `true` if this result is a {@link Result.Failure}.
|
|
233
|
+
*/
|
|
234
|
+
isError(): this is Result.Failure<V, E>;
|
|
235
|
+
/**
|
|
236
|
+
* Transforms the value of this result using the provided callback if this is a {@link Result.Success}.
|
|
237
|
+
* Does nothing if this result is a {@link Result.Failure}.
|
|
238
|
+
*/
|
|
239
|
+
abstract map<W>(callback: (value: V) => W): Result<W, E>;
|
|
240
|
+
/**
|
|
241
|
+
* Transforms the error of this result using the provided callback if this is a {@link Result.Failure}.
|
|
242
|
+
* Does nothing if this result is a {@link Result.Success}.
|
|
243
|
+
*/
|
|
244
|
+
abstract mapError<F>(callback: (error: E) => F): Result<V, F>;
|
|
245
|
+
/**
|
|
246
|
+
* Chains a new {@link Result}-returning operation to this result if this is a {@link Result.Success}.
|
|
247
|
+
* Does nothing if this result is a {@link Result.Failure}.
|
|
248
|
+
*/
|
|
249
|
+
abstract next<W, F>(callback: (value: V) => Result<W, F>): Result<W, E | F>;
|
|
250
|
+
/**
|
|
251
|
+
* Provides a recovery path for this result if this is a {@link Result.Failure} by returning a new {@link Result}.
|
|
252
|
+
* Does nothing if this result is a {@link Result.Success}.
|
|
253
|
+
*/
|
|
254
|
+
abstract orElse<W, F>(callback: (error: E) => Result<W, F>): Result<V | W, F | E>;
|
|
255
|
+
/**
|
|
256
|
+
* Returns the {@link Result.Success} value of this instance or the provided default value if this is a {@link Result.Failure}.
|
|
257
|
+
*/
|
|
258
|
+
abstract unwrapOr<W>(defaultValue: W): V | W;
|
|
259
|
+
/**
|
|
260
|
+
* Executes the `ok` callback if this is a {@link Result.Success}, or the `error` callback
|
|
261
|
+
* if this is a {@link Result.Failure}, returning the result.
|
|
262
|
+
*/
|
|
263
|
+
abstract match<A, B>(ok: (value: V) => A, error: (error: E) => B): A | B;
|
|
264
|
+
/**
|
|
265
|
+
* Executes a callback for side effects if this result is a {@link Result.Success}.
|
|
266
|
+
*/
|
|
267
|
+
ifOk(callback: (value: V) => void): this;
|
|
268
|
+
/**
|
|
269
|
+
* Executes a callback for side effects if this result is a {@link Result.Failure}.
|
|
270
|
+
*/
|
|
271
|
+
ifError(callback: (error: E) => void): this;
|
|
272
|
+
/**
|
|
273
|
+
* Validates the value of this result against a predicate.
|
|
274
|
+
* Converts to {@link Result.Failure} if the predicate returns `false`.
|
|
275
|
+
* Does nothing if this result is already a {@link Result.Failure}.
|
|
276
|
+
*/
|
|
277
|
+
abstract filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
278
|
+
abstract filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
279
|
+
}
|
|
117
280
|
|
|
118
281
|
declare function bold(text: string): string;
|
|
119
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Transforms the first character of a string to uppercase.
|
|
285
|
+
* @param string - The string to capitalize.
|
|
286
|
+
* @returns The string with the first character transformed to uppercase.
|
|
287
|
+
*/
|
|
288
|
+
export declare function capitalize<S extends string = string>(string: S): Capitalize<S>;
|
|
289
|
+
|
|
120
290
|
/**
|
|
121
291
|
* Clamps a value between an upper and lower bound.
|
|
122
292
|
* @param value - The value to clamp.
|
|
@@ -150,13 +320,6 @@ export declare class EventEmitter<T extends Record<keyof T, unknown[]>> {
|
|
|
150
320
|
* @returns The wrapped listener.
|
|
151
321
|
*/
|
|
152
322
|
once<K extends keyof T>(event: K, listener: Listener<T, K>): Listener<T, K>;
|
|
153
|
-
/**
|
|
154
|
-
* Starts listening to an event.
|
|
155
|
-
* @param event - The event to listen to.
|
|
156
|
-
* @param listener - The function to call when the event is emitted.
|
|
157
|
-
* @returns The wrapped listener.
|
|
158
|
-
*/
|
|
159
|
-
onAsync<K extends keyof T>(event: K, listener: AsyncListener<T, K>, onRejected?: Parameters<Promise<void>["catch"]>[0]): Listener<T, K>;
|
|
160
323
|
/**
|
|
161
324
|
* Removes an event listener.
|
|
162
325
|
* @param event - The event to remove the listener from.
|
|
@@ -169,8 +332,22 @@ export declare class EventEmitter<T extends Record<keyof T, unknown[]>> {
|
|
|
169
332
|
* @param args - The arguments to pass to the listeners.
|
|
170
333
|
*/
|
|
171
334
|
emit<K extends keyof T>(event: K, ...args: T[K]): void;
|
|
335
|
+
/**
|
|
336
|
+
* Emits an event and waits for all listeners to resolve.
|
|
337
|
+
* @param event - The event to emit.
|
|
338
|
+
* @param args - The arguments to pass to the listeners.
|
|
339
|
+
*/
|
|
340
|
+
emitAsync<K extends keyof T>(event: K, ...args: T[K]): Promise<void>;
|
|
172
341
|
}
|
|
173
342
|
|
|
343
|
+
export declare function fillTemplate(template: string, properties: Record<string, string>, options: {
|
|
344
|
+
join: false;
|
|
345
|
+
}): string[];
|
|
346
|
+
|
|
347
|
+
export declare function fillTemplate(template: string, properties: Record<string, string>, options?: {
|
|
348
|
+
join?: true | string;
|
|
349
|
+
}): string;
|
|
350
|
+
|
|
174
351
|
/**
|
|
175
352
|
* Formats time relative to now.
|
|
176
353
|
* @param date - The date.
|
|
@@ -211,6 +388,314 @@ declare function heading6(text: string): string;
|
|
|
211
388
|
|
|
212
389
|
declare function horizontalRule(): string;
|
|
213
390
|
|
|
391
|
+
/**
|
|
392
|
+
* Generates a human-readable string representation of a value.
|
|
393
|
+
*
|
|
394
|
+
* This is intended for debugging purposes.
|
|
395
|
+
* It is an alternative to {@link https://nodejs.org/api/util.html#utilinspectobject-options util.inspect}, that supports more customization of the output.
|
|
396
|
+
*
|
|
397
|
+
* @param value - The value to inspect.
|
|
398
|
+
* @param options - Optional inspection options.
|
|
399
|
+
* @returns The resulting string.
|
|
400
|
+
* @example
|
|
401
|
+
* **Note:** The following examples omit the `options` parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set `colors` to `false`.
|
|
402
|
+
* ```tsx
|
|
403
|
+
* // Supports primitive values.
|
|
404
|
+
* inspect(null) === "null"
|
|
405
|
+
* inspect("example") === "\"example\""
|
|
406
|
+
*
|
|
407
|
+
* // Supports objects and arrays (and other containers).
|
|
408
|
+
* inspect({ size: 2, values: [true, false] }) === "{ size: 2, values: [true, false] }"
|
|
409
|
+
*
|
|
410
|
+
* // Even supports React nodes.
|
|
411
|
+
* inspect(<h1>Example</h1>) === "<h1>Example</h1>"
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
export declare function inspect(value: unknown, options?: InspectionOptions): string;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Returns a string representation of an array.
|
|
418
|
+
* @param array - The array to inspect.
|
|
419
|
+
* @param options - Optional inspection options.
|
|
420
|
+
* @returns The resulting string.
|
|
421
|
+
* @example
|
|
422
|
+
* **Note:** The following examples omit or shorten the `options` parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set `colors` to `false`.
|
|
423
|
+
* ```ts
|
|
424
|
+
* inspect([1, 2, 3]) === "[1, 2, 3]"
|
|
425
|
+
* inspect([1, 2, 3], { spaceAfterComma: false }) === "[1,2,3]"
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
export declare function inspectArray(array: unknown[], options?: InspectionOptions): string;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Returns a string representation of an error.
|
|
432
|
+
* @param error - The error to inspect.
|
|
433
|
+
* @param options - Optional inspection options.
|
|
434
|
+
* @returns The resulting string.
|
|
435
|
+
*/
|
|
436
|
+
export declare function inspectError(error: Error, options?: InspectionOptions): string;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Returns a string representation of a function.
|
|
440
|
+
* @param func - The function to inspect.
|
|
441
|
+
* @param options - Optional inspection options.
|
|
442
|
+
* @returns The resulting string.
|
|
443
|
+
*/
|
|
444
|
+
export declare function inspectFunction(func: Function, options?: InspectionOptions): string;
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Returns a string representation of a function call, its arguments and its return value.
|
|
448
|
+
* @param func - The function to inspect.
|
|
449
|
+
* @param args - The arguments of the function call.
|
|
450
|
+
* @param returnValue - The return value of the function call.
|
|
451
|
+
* @param options - Optional inspection options.
|
|
452
|
+
* @returns The resulting string.
|
|
453
|
+
*/
|
|
454
|
+
export declare function inspectFunctionCall<A extends unknown[] = [], R = undefined>(func: (...args: A) => R, args: A, returnValue: R, options?: InspectionOptions): string;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Configuration options for the inspection utilities.
|
|
458
|
+
* @see {@link inspect}
|
|
459
|
+
*/
|
|
460
|
+
export declare interface InspectionOptions {
|
|
461
|
+
/**
|
|
462
|
+
* The maximum depth for representations of container values (e.g., objects, arrays).
|
|
463
|
+
* @default 2
|
|
464
|
+
*/
|
|
465
|
+
depth?: number;
|
|
466
|
+
/**
|
|
467
|
+
* The maximum number of array elements to represent before truncating.
|
|
468
|
+
* @default 100
|
|
469
|
+
*/
|
|
470
|
+
maxArrayLength?: number;
|
|
471
|
+
/**
|
|
472
|
+
* The maximum amount of characters of a string to represent, before replacing the remainder with an ellipsis.
|
|
473
|
+
* @default 80
|
|
474
|
+
*/
|
|
475
|
+
maxStringLength?: number;
|
|
476
|
+
/**
|
|
477
|
+
* The maximum line length before wrapping to a new line.
|
|
478
|
+
*
|
|
479
|
+
* This option is ignored when {@link compact} is set to `true`.
|
|
480
|
+
* @default 60
|
|
481
|
+
*/
|
|
482
|
+
breakLength?: number;
|
|
483
|
+
/**
|
|
484
|
+
* `true` keeps container values on a single line when possible.
|
|
485
|
+
* @default true
|
|
486
|
+
*/
|
|
487
|
+
compact?: boolean;
|
|
488
|
+
/**
|
|
489
|
+
* `true` enables the sorting of keys in object representations.
|
|
490
|
+
* @default false
|
|
491
|
+
*/
|
|
492
|
+
sortKeys?: boolean;
|
|
493
|
+
/**
|
|
494
|
+
* `true` uses single quotes instead of double quotes.
|
|
495
|
+
* @default false
|
|
496
|
+
*/
|
|
497
|
+
singleQuotes?: boolean;
|
|
498
|
+
/**
|
|
499
|
+
* `true` places a space after every comma.
|
|
500
|
+
* @default true
|
|
501
|
+
*/
|
|
502
|
+
spaceAfterComma?: boolean;
|
|
503
|
+
/**
|
|
504
|
+
* Plugins to extend, override or configure the inspection process.
|
|
505
|
+
*/
|
|
506
|
+
plugins?: InspectionPlugin[];
|
|
507
|
+
/**
|
|
508
|
+
* The {@link ANSI} color codes for different symbols.
|
|
509
|
+
*
|
|
510
|
+
* Set to `false` to disable ANSI colors.
|
|
511
|
+
*/
|
|
512
|
+
colors?: false | {
|
|
513
|
+
/**
|
|
514
|
+
* The color to apply to strings.
|
|
515
|
+
* @default ANSI.fg.green
|
|
516
|
+
*/
|
|
517
|
+
string?: string | null;
|
|
518
|
+
/**
|
|
519
|
+
* The color to apply to numbers.
|
|
520
|
+
* @default ANSI.fg.yellow
|
|
521
|
+
*/
|
|
522
|
+
number?: string | null;
|
|
523
|
+
/**
|
|
524
|
+
* The color to apply to booleans.
|
|
525
|
+
* @default ANSI.fg.yellow
|
|
526
|
+
*/
|
|
527
|
+
boolean?: string | null;
|
|
528
|
+
/**
|
|
529
|
+
* The color to apply to `null` keywords.
|
|
530
|
+
* @default ANSI.decoration.dim + ANSI.fg.yellow
|
|
531
|
+
*/
|
|
532
|
+
null?: string | null;
|
|
533
|
+
/**
|
|
534
|
+
* The color to apply to `undefined` keywords.
|
|
535
|
+
* @default ANSI.decoration.dim + ANSI.fg.yellow
|
|
536
|
+
*/
|
|
537
|
+
undefined?: string | null;
|
|
538
|
+
/**
|
|
539
|
+
* The color to apply to bigints.
|
|
540
|
+
* @default ANSI.fg.yellow
|
|
541
|
+
*/
|
|
542
|
+
bigint?: string | null;
|
|
543
|
+
/**
|
|
544
|
+
* The color to apply to symbols.
|
|
545
|
+
* @default ANSI.fg.green
|
|
546
|
+
*/
|
|
547
|
+
symbol?: string | null;
|
|
548
|
+
/**
|
|
549
|
+
* The color to apply to functions.
|
|
550
|
+
* @default ANSI.fg.blue
|
|
551
|
+
*/
|
|
552
|
+
function?: string | null;
|
|
553
|
+
/**
|
|
554
|
+
* The color to apply to keys.
|
|
555
|
+
* @default ANSI.fg.white
|
|
556
|
+
*/
|
|
557
|
+
key?: string | null;
|
|
558
|
+
/**
|
|
559
|
+
* The color to apply to dates.
|
|
560
|
+
* @default ANSI.fg.magenta
|
|
561
|
+
*/
|
|
562
|
+
date?: string | null;
|
|
563
|
+
/**
|
|
564
|
+
* The color to apply to {@link RegExp}s.
|
|
565
|
+
* @default ANSI.fg.cyan
|
|
566
|
+
*/
|
|
567
|
+
regExp?: string | null;
|
|
568
|
+
/**
|
|
569
|
+
* The color to apply to errors.
|
|
570
|
+
* @default ANSI.fg.red
|
|
571
|
+
*/
|
|
572
|
+
error?: string | null;
|
|
573
|
+
/**
|
|
574
|
+
* The color to apply to HTML tags.
|
|
575
|
+
* @default ANSI.fg.red
|
|
576
|
+
*/
|
|
577
|
+
htmlTag?: string | null;
|
|
578
|
+
/**
|
|
579
|
+
* The color to apply to React components.
|
|
580
|
+
* @default ANSI.fg.yellow
|
|
581
|
+
*/
|
|
582
|
+
reactComponent?: string | null;
|
|
583
|
+
/**
|
|
584
|
+
* The color to apply to delimiters.
|
|
585
|
+
* @default ANSI.fg.cyan
|
|
586
|
+
*/
|
|
587
|
+
delimiter?: string | null;
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* A plugin for the inspection utilities.
|
|
593
|
+
*
|
|
594
|
+
* Can be used to extend, override or configure the inspection process.
|
|
595
|
+
* Hook methods are called at different stages of the process and can seamlessly interact with it.
|
|
596
|
+
*
|
|
597
|
+
* This is heavily inspired by [Vite's plugin API](https://vite.dev/guide/api-plugin) and follows a similar pattern.
|
|
598
|
+
*
|
|
599
|
+
* @see {@link inspect}
|
|
600
|
+
*/
|
|
601
|
+
export declare interface InspectionPlugin {
|
|
602
|
+
/** The name of this plugin. */
|
|
603
|
+
name: string;
|
|
604
|
+
/**
|
|
605
|
+
* A hook that configures the inspection options before any values are inspected.
|
|
606
|
+
* @param options - The current inspection options.
|
|
607
|
+
*/
|
|
608
|
+
config?: (options: ResolvedInspectionOptions) => void;
|
|
609
|
+
/**
|
|
610
|
+
* A hook that is called before a value is inspected.
|
|
611
|
+
* @param input - The input value.
|
|
612
|
+
* @param context - The inspection context.
|
|
613
|
+
*/
|
|
614
|
+
first?: (input: unknown, context: ResolvedInspectionOptions) => string | undefined;
|
|
615
|
+
/**
|
|
616
|
+
* A hook that is called if a value could not be inspected.
|
|
617
|
+
* @param input - The input value.
|
|
618
|
+
* @param context - The inspection context.
|
|
619
|
+
*/
|
|
620
|
+
fallback?: (input: unknown, context: ResolvedInspectionOptions) => string | undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Returns a string representation of a map.
|
|
625
|
+
* @param map - The map to inspect.
|
|
626
|
+
* @param options - Optional inspection options.
|
|
627
|
+
* @returns The resulting string.
|
|
628
|
+
*/
|
|
629
|
+
export declare function inspectMap(map: Map<unknown, unknown>, options?: InspectionOptions): string;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Returns a string representation of an object.
|
|
633
|
+
* @param object - The object to inspect.
|
|
634
|
+
* @param options - Optional inspection options.
|
|
635
|
+
* @returns The resulting string.
|
|
636
|
+
* @example
|
|
637
|
+
* **Note:** The following example omits the `options` parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set `colors` to `false`.
|
|
638
|
+
* ```ts
|
|
639
|
+
* inspect({ first: true, second: false }) === "{ first: true, second: false }"
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
export declare function inspectObject(object: Record<PropertyKey, unknown>, options?: InspectionOptions): string;
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Returns a string representation of a React element.
|
|
646
|
+
* @param element - The React element to inspect.
|
|
647
|
+
* @param options - Optional inspection options.
|
|
648
|
+
* @returns The resulting string.
|
|
649
|
+
* @example
|
|
650
|
+
* **Note:** The following example omits the `options` parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set `colors` to `false`.
|
|
651
|
+
* ```tsx
|
|
652
|
+
* inspect(<h1>Example</h1>) === "<h1>Example</h1>"
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
export declare function inspectReactElement(element: ReactElementLike, options?: InspectionOptions): string;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Returns a string representation of a set.
|
|
659
|
+
* @param set - The set to inspect.
|
|
660
|
+
* @param options - Optional inspection options.
|
|
661
|
+
* @returns The resulting string.
|
|
662
|
+
*/
|
|
663
|
+
export declare function inspectSet(set: Set<unknown>, options?: InspectionOptions): string;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Generates a literal string representation of a string.
|
|
667
|
+
* @param string - The string to inspect.
|
|
668
|
+
* @param options - Optional inspection options.
|
|
669
|
+
* @returns The resulting string.
|
|
670
|
+
* @example
|
|
671
|
+
* **Note:** The following examples omit or shorten the `options` parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set `colors` to `false`.
|
|
672
|
+
* ```ts
|
|
673
|
+
* inspect("Example") === "\"Example\""
|
|
674
|
+
* inspect("Example", { singleQuotes: true }) === "'Example'"
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
677
|
+
export declare function inspectString(string: string, options?: InspectionOptions): string;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Inserts an item in between every item in an array.
|
|
681
|
+
* @param item - The item to insert.
|
|
682
|
+
* @param array - The array to insert into.
|
|
683
|
+
*/
|
|
684
|
+
export declare function interleave<Type>(item: Type, array: Type[]): Type[];
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Determines whether {@link arg} is an object.
|
|
688
|
+
*/
|
|
689
|
+
export declare function isObject(arg: unknown): arg is Record<PropertyKey, unknown>;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Splits a string into an array of substrings where all substrings matching {@link searchValue} are separate items.
|
|
693
|
+
* @param string - The string to split.
|
|
694
|
+
* @param searchValue - The value to isolate from other substrings.
|
|
695
|
+
* @returns An array of substrings matching {@link searchValue} and the rest of the string.
|
|
696
|
+
*/
|
|
697
|
+
export declare function isolateSubstring(string: string, searchValue: string): string[];
|
|
698
|
+
|
|
214
699
|
/**
|
|
215
700
|
* Checks if `input` is a valid integer.
|
|
216
701
|
*/
|
|
@@ -221,8 +706,20 @@ export declare function isValidInteger(input: number | string): boolean;
|
|
|
221
706
|
*/
|
|
222
707
|
export declare function isValidNumber(input: number | string): boolean;
|
|
223
708
|
|
|
709
|
+
/**
|
|
710
|
+
* Checks whether a string is a valid URL.
|
|
711
|
+
* @param string - The string to check.
|
|
712
|
+
* @returns `true` if {@link string} is a URL.
|
|
713
|
+
*/
|
|
714
|
+
export declare function isValidUrl(string: string): boolean;
|
|
715
|
+
|
|
224
716
|
declare function italic(text: string): string;
|
|
225
717
|
|
|
718
|
+
/**
|
|
719
|
+
* Converts a kebab-case string to camelCase.
|
|
720
|
+
*/
|
|
721
|
+
export declare function kebabToCamelCase(value: string): string;
|
|
722
|
+
|
|
226
723
|
declare function link(label: string, url: string): string;
|
|
227
724
|
|
|
228
725
|
/**
|
|
@@ -230,7 +727,7 @@ declare function link(label: string, url: string): string;
|
|
|
230
727
|
* @typeParam T - A record of all events.
|
|
231
728
|
* @typeParam K - The event this function handles.
|
|
232
729
|
*/
|
|
233
|
-
export declare type Listener<T extends Record<keyof T, unknown[]>, K extends keyof T> = (...args: T[K]) => void
|
|
730
|
+
export declare type Listener<T extends Record<keyof T, unknown[]>, K extends keyof T> = (...args: T[K]) => void | Promise<void>;
|
|
234
731
|
|
|
235
732
|
/**
|
|
236
733
|
* A simple wrapper for {@link console} that logs formatted text and supports log levels.
|
|
@@ -278,6 +775,16 @@ export declare class Logger {
|
|
|
278
775
|
prefix: {
|
|
279
776
|
[key in LogLevel | "global"]?: string;
|
|
280
777
|
};
|
|
778
|
+
/**
|
|
779
|
+
* The function to use to turn values into strings.
|
|
780
|
+
* @see {@link createStringifier}
|
|
781
|
+
* @default Logger.createStringifier("pretty")
|
|
782
|
+
*/
|
|
783
|
+
stringify: (value: unknown) => string;
|
|
784
|
+
get errorCount(): number;
|
|
785
|
+
set errorCount(value: number);
|
|
786
|
+
get warningCount(): number;
|
|
787
|
+
set warningCount(value: number);
|
|
281
788
|
constructor(options?: {
|
|
282
789
|
/** {@inheritDoc Logger.level}. */
|
|
283
790
|
level?: Logger["level"];
|
|
@@ -474,6 +981,17 @@ export declare class Logger {
|
|
|
474
981
|
* @param level - The log level.
|
|
475
982
|
*/
|
|
476
983
|
applyPrefix(text: string, level?: LogLevel): string;
|
|
984
|
+
/**
|
|
985
|
+
* Creates a stringify function that uses the {@link String} constructor.
|
|
986
|
+
* @param type - The type of stringify function to use.
|
|
987
|
+
*/
|
|
988
|
+
static createStringifier(type?: "basic"): Logger["stringify"];
|
|
989
|
+
/**
|
|
990
|
+
* Creates a stringify function that uses {@link inspect} for any non-string value.
|
|
991
|
+
* @param type - The type of stringify function to use.
|
|
992
|
+
* @param options - The options for {@link inspect}.
|
|
993
|
+
*/
|
|
994
|
+
static createStringifier(type: "pretty", options?: InspectionOptions): Logger["stringify"];
|
|
477
995
|
}
|
|
478
996
|
|
|
479
997
|
export declare enum LogLevel {
|
|
@@ -503,6 +1021,52 @@ export declare namespace Markdown {
|
|
|
503
1021
|
}
|
|
504
1022
|
}
|
|
505
1023
|
|
|
1024
|
+
/**
|
|
1025
|
+
* Merges the type of the target with one or more types of sources.
|
|
1026
|
+
* @typeParam Target - The target type to merge with.
|
|
1027
|
+
* @typeParam Sources - The source types to merge into the target type.
|
|
1028
|
+
*/
|
|
1029
|
+
export declare type Merge<Target, Sources extends unknown[]> = Sources extends [] ? Target : Sources extends [infer FirstSource, ...infer OtherSources] ? Merge<MergeValues<Target, FirstSource>, OtherSources> : Sources extends (infer Source)[] ? Target | MergeValues<Target, Source> : never;
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Merges the types of two arrays by concatenating them.
|
|
1033
|
+
*/
|
|
1034
|
+
export declare type MergeArrays<Target extends unknown[], Source extends unknown[]> = [...Target, ...Source];
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Recursively merges two or more objects.
|
|
1038
|
+
*
|
|
1039
|
+
* If a property is defined in two objects and the values are both objects, they are merged recursively,
|
|
1040
|
+
* if they are both arrays, they are concatenated, otherwise the value of the second object overrides the value of the first.
|
|
1041
|
+
* @param target - The target object to merge the other objects with.
|
|
1042
|
+
* @param sources - The objects to merge with the target object.
|
|
1043
|
+
* @returns The merged object.
|
|
1044
|
+
*/
|
|
1045
|
+
export declare function mergeDeep<Target extends Record<PropertyKey, unknown>, Sources extends Record<PropertyKey, unknown>[] = Target[]>(target: Target, ...sources: Sources): Merge<Target, Sources>;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Merges the types of two objects recursively.
|
|
1049
|
+
*
|
|
1050
|
+
* Properties are merged using {@link MergeValues}.
|
|
1051
|
+
*/
|
|
1052
|
+
export declare type MergeObjects<Target extends Record<PropertyKey, unknown>, Source extends Record<PropertyKey, unknown>> = {
|
|
1053
|
+
[Key in keyof Target | keyof Source]: Key extends keyof Source ? Key extends keyof Target ? MergeValues<Target[Key], Source[Key]> : Source[Key] : Target[Key & keyof Target];
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Merges the types of two primitive values.
|
|
1058
|
+
*/
|
|
1059
|
+
export declare type MergePrimitive<Target, Source> = undefined extends Source ? Exclude<Source, undefined> extends never ? Target : Exclude<Source, undefined> : Source;
|
|
1060
|
+
|
|
1061
|
+
/**
|
|
1062
|
+
* Merges the types of two values recursively.
|
|
1063
|
+
*
|
|
1064
|
+
* Delegates to {@link MergePrimitive}, {@link MergeObjects} or {@link MergeArrays} if the two values are primitives, objects or arrays respectively.
|
|
1065
|
+
*/
|
|
1066
|
+
export declare type MergeValues<Target, Source> = Target extends Record<PropertyKey, unknown> ? Source extends Record<PropertyKey, unknown> ? [Target, Source] extends [Source, Target] ? Target : MergeObjects<Target, Source> : Source : Target extends unknown[] ? Source extends unknown[] ? MergeArrays<Target, Source> : Source : MergePrimitive<Target, Source>;
|
|
1067
|
+
|
|
1068
|
+
export declare type NestedArray<T> = Array<T | NestedArray<T>>;
|
|
1069
|
+
|
|
506
1070
|
/**
|
|
507
1071
|
* Converts a string to a boolean.
|
|
508
1072
|
* @param input - The string to parse.
|
|
@@ -520,6 +1084,19 @@ declare function quote(text: string): string;
|
|
|
520
1084
|
*/
|
|
521
1085
|
export declare function randomFromArray<Type>(array: Type[]): Type;
|
|
522
1086
|
|
|
1087
|
+
/**
|
|
1088
|
+
* Returns a random index within the bounds of an array.
|
|
1089
|
+
* @returns A random index.
|
|
1090
|
+
*/
|
|
1091
|
+
export declare function randomIndex(array: unknown[]): number;
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Returns a random integer inside a range.
|
|
1095
|
+
* @param min - The lower bound (inclusive).
|
|
1096
|
+
* @param max - The upper bound (exclusive).
|
|
1097
|
+
*/
|
|
1098
|
+
export declare function randomInt(min: number, max: number): number;
|
|
1099
|
+
|
|
523
1100
|
/**
|
|
524
1101
|
* Returns a random value inside a range.
|
|
525
1102
|
* @param min - The lower bound.
|
|
@@ -527,6 +1104,21 @@ export declare function randomFromArray<Type>(array: Type[]): Type;
|
|
|
527
1104
|
*/
|
|
528
1105
|
export declare function randomRange(min: number, max: number): number;
|
|
529
1106
|
|
|
1107
|
+
export declare interface ReactElementLike {
|
|
1108
|
+
type: unknown;
|
|
1109
|
+
props?: unknown;
|
|
1110
|
+
key?: string | null;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* Removes the origin/base from a URL string.
|
|
1115
|
+
* @param url - The URL string.
|
|
1116
|
+
* @returns The URL string without its origin.
|
|
1117
|
+
* @example
|
|
1118
|
+
* removeBaseUrl("https://example.com/foo/bar") === "/foo/bar"
|
|
1119
|
+
*/
|
|
1120
|
+
export declare function removeBaseUrl(url: string): string;
|
|
1121
|
+
|
|
530
1122
|
/**
|
|
531
1123
|
* Removes all duplicate items from an array.
|
|
532
1124
|
*/
|
|
@@ -538,6 +1130,147 @@ export declare function removeDuplicatesFromArray<Type>(array: Type[]): Type[];
|
|
|
538
1130
|
*/
|
|
539
1131
|
export declare function removeFromArray<Type>(item: Type, array: Type[]): void;
|
|
540
1132
|
|
|
1133
|
+
/**
|
|
1134
|
+
* Removes the URL protocol from a URL string.
|
|
1135
|
+
* @param url - The URL string.
|
|
1136
|
+
* @returns The URL string without its protocol.
|
|
1137
|
+
* @example
|
|
1138
|
+
* removeUrlProtocol("https://example.com/foo/bar") === "example.com/foo/bar"
|
|
1139
|
+
*/
|
|
1140
|
+
export declare function removeUrlProtocol(url: string): string;
|
|
1141
|
+
|
|
1142
|
+
export declare function replaceAll<Type>(array: Type[], searchItem: Type, replaceItem: Type): Type[];
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* The resolved inspection options combined with some utility functions for generating string representations.
|
|
1146
|
+
*
|
|
1147
|
+
* Used internally by the inspection utilities and {@link InspectionPlugin}s.
|
|
1148
|
+
* @see {@link inspect}
|
|
1149
|
+
*/
|
|
1150
|
+
export declare interface ResolvedInspectionOptions extends Required<InspectionOptions> {
|
|
1151
|
+
/**
|
|
1152
|
+
* Returns a formatted delimiter string.
|
|
1153
|
+
* @param delimiter - The raw delimiter.
|
|
1154
|
+
*/
|
|
1155
|
+
delimiter: (delimiter: string) => string;
|
|
1156
|
+
/** Returns a formatted separator string. */
|
|
1157
|
+
separator: () => string;
|
|
1158
|
+
/**
|
|
1159
|
+
* Applies color to the given string, if {@link ResolvedInspectionOptions.colors} is `true`.
|
|
1160
|
+
* @param text - The raw text.
|
|
1161
|
+
* @param colorCode - The ANSI color code to apply.
|
|
1162
|
+
*/
|
|
1163
|
+
color: (text: string, colorCode: string | undefined | null) => string;
|
|
1164
|
+
/**
|
|
1165
|
+
* Applies the appropriate formatting to the given token.
|
|
1166
|
+
* @param token - The raw token.
|
|
1167
|
+
* @param type - The type of token.
|
|
1168
|
+
*/
|
|
1169
|
+
token: (token: string, type?: keyof Exclude<InspectionOptions["colors"], false | undefined>) => string;
|
|
1170
|
+
/** Creates a new inspection context and increments the current depth. */
|
|
1171
|
+
fork: () => ResolvedInspectionOptions;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Combines an array of URL segments into a URL string.
|
|
1176
|
+
* @param segments - The segments of the URL.
|
|
1177
|
+
* @returns The combined URL.
|
|
1178
|
+
*/
|
|
1179
|
+
export declare function resolveUrl(...segments: string[]): string;
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Represents either a success or a failure.
|
|
1183
|
+
*
|
|
1184
|
+
* Can be used as the return value of a function instead of throwing errors.
|
|
1185
|
+
* This improves type-safety and helps you control the flow of your function.
|
|
1186
|
+
*
|
|
1187
|
+
* This is inspired by [neverthrow by supermacro](https://github.com/supermacro/neverthrow).
|
|
1188
|
+
*
|
|
1189
|
+
* A success can be created using {@link Result.ok} and a failure using {@link Result.error}.
|
|
1190
|
+
*/
|
|
1191
|
+
export declare type Result<T, E> = Result.Success<T, E> | Result.Failure<T, E>;
|
|
1192
|
+
|
|
1193
|
+
export declare namespace Result {
|
|
1194
|
+
/**
|
|
1195
|
+
* Represents the result of a successful operation.
|
|
1196
|
+
*/
|
|
1197
|
+
export class Success<V, E> extends BaseResult<V, E> {
|
|
1198
|
+
readonly value: V;
|
|
1199
|
+
constructor(value: V);
|
|
1200
|
+
isOk(): this is Success<V, E>;
|
|
1201
|
+
map<W>(callback: (value: V) => W): Result<W, E>;
|
|
1202
|
+
mapError<F>(_callback: (error: E) => F): Result<V, F>;
|
|
1203
|
+
next<W, F>(callback: (value: V) => Result<W, F>): Result<W, E | F>;
|
|
1204
|
+
orElse<W, F>(_callback: (error: E) => Result<W, F>): Result<V, E>;
|
|
1205
|
+
unwrapOr<W>(_defaultValue: W): V;
|
|
1206
|
+
match<A, B>(ok: (value: V) => A, _error: (error: E) => B): A;
|
|
1207
|
+
filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
1208
|
+
filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Represents the result of a failed operation.
|
|
1212
|
+
*/
|
|
1213
|
+
export class Failure<V, E> extends BaseResult<V, E> {
|
|
1214
|
+
readonly error: E;
|
|
1215
|
+
constructor(error: E);
|
|
1216
|
+
isError(): this is Failure<V, E>;
|
|
1217
|
+
map<W>(_callback: (value: V) => W): Result<W, E>;
|
|
1218
|
+
mapError<F>(callback: (error: E) => F): Result<V, F>;
|
|
1219
|
+
next<W, F>(_callback: (value: V) => Result<W, F>): Failure<W, E>;
|
|
1220
|
+
orElse<W, F>(callback: (error: E) => Result<W, F>): Result<W, F>;
|
|
1221
|
+
unwrapOr<W>(defaultValue: W): W;
|
|
1222
|
+
match<A, B>(_ok: (value: V) => A, error: (error: E) => B): B;
|
|
1223
|
+
filter<U extends V, F>(predicate: (value: V) => value is U, createError: (value: V) => F): Result<U, E | F>;
|
|
1224
|
+
filter<F>(predicate: (value: V) => boolean, createError: (value: V) => F): Result<V, E | F>;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Creates a {@link Result.Success} instance.
|
|
1228
|
+
*/
|
|
1229
|
+
export function ok<T, E = never>(value: T): Success<T, E>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Creates a {@link Result.Failure} instance.
|
|
1232
|
+
*/
|
|
1233
|
+
export function error<E, T = never>(error: E): Failure<T, E>;
|
|
1234
|
+
/**
|
|
1235
|
+
* Wraps a synchronous operation that might throw in a {@link Result}.
|
|
1236
|
+
*/
|
|
1237
|
+
export function wrap<V, E = Error>(callback: () => V, catcher?: (err: unknown) => E): Result<V, E>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Converts a nullable value into a {@link Result}.
|
|
1240
|
+
* Returns {@link Result.Failure} if the value is `null` or `undefined`.
|
|
1241
|
+
*/
|
|
1242
|
+
export function nonNullOr<V, E>(nullable: V | null | undefined, err: E): Result<NonNullable<V>, E>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Converts a nullable value into a {@link Result} or executes a fallback {@link Result}-returning function.
|
|
1245
|
+
*/
|
|
1246
|
+
export function nonNullOrElse<V, W, E>(nullable: V | null | undefined, orElse: () => Result<W, E>): Result<NonNullable<V> | W, E>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Repeatedly executes a {@link Result}-returning body while a condition is met.
|
|
1249
|
+
*/
|
|
1250
|
+
export function repeat<V, E>(initialValue: V, condition: (value: V) => boolean, body: (value: V) => Result<V, E>): Result<V, E>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Reduces a collection into a {@link Result} by executing a {@link Result}-returning
|
|
1253
|
+
* reducer for each item.
|
|
1254
|
+
*/
|
|
1255
|
+
export function reduce<T, V, E>(items: T[], reducer: (accumulator: V, item: T) => Result<V, E>, initialValue: V): Result<V, E>;
|
|
1256
|
+
/**
|
|
1257
|
+
* Collapses an array of {@link Result}s into a single {@link Result} containing an array of values.
|
|
1258
|
+
* Returns the first {@link Result.Failure} encountered.
|
|
1259
|
+
* Similar to {@link Promise.all}, but for synchronous {@link Result} collections.
|
|
1260
|
+
*/
|
|
1261
|
+
export function all<V, E>(results: Result<V, E>[]): Result<V[], E>;
|
|
1262
|
+
/**
|
|
1263
|
+
* Returns the first {@link Result.Success} produced by the callback for any item
|
|
1264
|
+
* in the collection. If no success is found, it returns the provided default error {@link Result}.
|
|
1265
|
+
* Similar to {@link Promise.any}, but for synchronous {@link Result} collections.
|
|
1266
|
+
*/
|
|
1267
|
+
export function any<T, V, E>(items: T[], callback: (item: T) => Result<V, E>, fallback: Result<V, E>): Result<V, E>;
|
|
1268
|
+
/**
|
|
1269
|
+
* Validates a subject against a type guard, producing a {@link Result}.
|
|
1270
|
+
*/
|
|
1271
|
+
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>;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
541
1274
|
/**
|
|
542
1275
|
* Rounds a value.
|
|
543
1276
|
* @param value - The value to round.
|
|
@@ -545,11 +1278,20 @@ export declare function removeFromArray<Type>(item: Type, array: Type[]): void;
|
|
|
545
1278
|
*/
|
|
546
1279
|
export declare function round(value: number, precision?: number): number;
|
|
547
1280
|
|
|
1281
|
+
/**
|
|
1282
|
+
* Splits a string into two strings at a given index.
|
|
1283
|
+
* @param string - The string to split.
|
|
1284
|
+
* @param index - The index to split at.
|
|
1285
|
+
* @returns The parts of the string before and after the character at the given index.
|
|
1286
|
+
*/
|
|
1287
|
+
export declare function splitAt(string: string, index: number): [string, string];
|
|
1288
|
+
|
|
548
1289
|
declare function strikethrough(text: string): string;
|
|
549
1290
|
|
|
550
1291
|
export declare class Vector2 {
|
|
551
1292
|
x: number;
|
|
552
1293
|
y: number;
|
|
1294
|
+
constructor();
|
|
553
1295
|
constructor(xy: number);
|
|
554
1296
|
constructor(x: number, y?: number);
|
|
555
1297
|
static get ZERO(): Vector2;
|