@homedev/objector 1.3.8 → 1.3.10
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 +608 -0
- package/dist/index.d.ts +321 -27
- package/dist/index.js +23 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses and queries command-line arguments.
|
|
3
|
+
*
|
|
4
|
+
* Accepts argv-like arrays and parses only the provided tokens.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class CommandLineArgs {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a parser for the provided command-line tokens.
|
|
12
|
+
*
|
|
13
|
+
* @param args - Argument tokens to parse.
|
|
14
|
+
* @param definitions - Known argument definitions used by usage output.
|
|
15
|
+
*/
|
|
16
|
+
constructor(args: string[], definitions?: CommandLineArgumentDefinition[]);
|
|
17
|
+
/**
|
|
18
|
+
* Returns normalized parsed argument tokens.
|
|
19
|
+
*/
|
|
20
|
+
get args(): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Returns non-option positional values.
|
|
23
|
+
*/
|
|
24
|
+
get positionals(): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if a flag was provided.
|
|
27
|
+
*
|
|
28
|
+
* @param flag - Option name with or without `-`/`--` prefix.
|
|
29
|
+
*/
|
|
30
|
+
has(flag: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Returns values for a flag.
|
|
33
|
+
*
|
|
34
|
+
* @param flag - Option name with or without `-`/`--` prefix.
|
|
35
|
+
*/
|
|
36
|
+
getArgs(flag: string): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Returns true for boolean flags, first value for valued flags, or undefined.
|
|
39
|
+
*
|
|
40
|
+
* @param flag - Option name with or without `-`/`--` prefix.
|
|
41
|
+
*/
|
|
42
|
+
get(flag: string): string | true | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Returns all options as a plain object.
|
|
45
|
+
*/
|
|
46
|
+
toObject(): Record<string, string[] | true>;
|
|
47
|
+
/**
|
|
48
|
+
* Builds usage output from provided argument definitions.
|
|
49
|
+
*
|
|
50
|
+
* @param command - Command name shown in usage output.
|
|
51
|
+
*/
|
|
52
|
+
usage(command?: string): string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Defines an argument for usage output.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare interface CommandLineArgumentDefinition {
|
|
61
|
+
name: string;
|
|
62
|
+
alias?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
takesValue?: boolean;
|
|
65
|
+
multiple?: boolean;
|
|
66
|
+
valueName?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parsed representation of a single CLI option.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export declare interface CommandLineOption {
|
|
75
|
+
values: string[];
|
|
76
|
+
sawEqualsStyle: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
1
79
|
/**
|
|
2
80
|
* @public
|
|
3
81
|
*/
|
|
@@ -20,6 +98,13 @@ declare interface EncoderOptions {
|
|
|
20
98
|
|
|
21
99
|
declare type EncoderOptions_2 = ObjectorDecoratorOptions;
|
|
22
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Checks whether a file is readable.
|
|
103
|
+
*
|
|
104
|
+
* @param fileName - File path to check.
|
|
105
|
+
* @returns True when the file can be accessed for reading.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
23
108
|
export declare const exists: (fileName: string) => Promise<boolean>;
|
|
24
109
|
|
|
25
110
|
export declare interface FieldContext {
|
|
@@ -131,12 +216,32 @@ export declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcess
|
|
|
131
216
|
|
|
132
217
|
declare type FieldProcessorTypedFunc_2 = FieldProcessorFunc_2 | (FieldProcessorOptions_2 & { fn: FieldProcessorFunc_2 })
|
|
133
218
|
|
|
134
|
-
|
|
219
|
+
/**
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export declare interface FilePatternOptions {
|
|
135
223
|
cwd: string;
|
|
136
224
|
filter?: (fileName: string, index: number, array: string[]) => boolean;
|
|
137
225
|
map: (fileName: string, index: number, array: string[]) => Promise<any>;
|
|
138
226
|
}
|
|
139
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Resolves the working directory used by file utilities.
|
|
230
|
+
*
|
|
231
|
+
* @param cwd - Optional absolute or relative directory override.
|
|
232
|
+
* @returns Absolute working directory path.
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare const getCwd: (cwd?: string) => string;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Maps files matching a glob pattern (or a single path) with async projection.
|
|
239
|
+
*
|
|
240
|
+
* @param pattern - Glob pattern(s) or direct file path.
|
|
241
|
+
* @param options - Mapping options including cwd, optional filter, and map function.
|
|
242
|
+
* @returns Mapped result for a direct path, or mapped array for glob patterns.
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
140
245
|
export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
141
246
|
|
|
142
247
|
/**
|
|
@@ -174,9 +279,10 @@ export declare interface LoadContext {
|
|
|
174
279
|
|
|
175
280
|
/**
|
|
176
281
|
* @public
|
|
177
|
-
* @param fileName
|
|
178
|
-
* @param options
|
|
179
|
-
* @returns
|
|
282
|
+
* @param fileName - Name or path of the file to load.
|
|
283
|
+
* @param options - Loading options including parser selection and lookup directories.
|
|
284
|
+
* @returns Parsed file content and path metadata.
|
|
285
|
+
* @throws - When no parser is resolved or locating/reading/parsing fails.
|
|
180
286
|
*/
|
|
181
287
|
export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
|
|
182
288
|
|
|
@@ -206,27 +312,87 @@ export declare interface LoadOptions {
|
|
|
206
312
|
format?: string;
|
|
207
313
|
}
|
|
208
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Result of loading and parsing a file.
|
|
317
|
+
*
|
|
318
|
+
* @typeParam T - Parsed content type.
|
|
319
|
+
* @public
|
|
320
|
+
*/
|
|
209
321
|
export declare interface LoadResult<T> {
|
|
210
322
|
fullPath: string;
|
|
211
323
|
folderPath: string;
|
|
212
324
|
content: T;
|
|
213
325
|
}
|
|
214
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Resolves a file path by searching the provided directories.
|
|
329
|
+
*
|
|
330
|
+
* @param fileName - File name or path to locate.
|
|
331
|
+
* @param dirs - Optional directories to search when fileName is relative.
|
|
332
|
+
* @returns Absolute path to the first matching file.
|
|
333
|
+
* @throws - When no matching file is found.
|
|
334
|
+
* @public
|
|
335
|
+
*/
|
|
215
336
|
export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
216
337
|
|
|
338
|
+
/**
|
|
339
|
+
* @public
|
|
340
|
+
*/
|
|
217
341
|
export declare type LogFunction = (className: string, ...args: any[]) => void;
|
|
218
342
|
|
|
343
|
+
/**
|
|
344
|
+
* @public
|
|
345
|
+
*/
|
|
219
346
|
export declare class Logger {
|
|
220
347
|
options: LoggerOptions;
|
|
348
|
+
/**
|
|
349
|
+
* Creates a logger with optional configuration overrides.
|
|
350
|
+
*
|
|
351
|
+
* @param options - Partial logger options to merge with defaults.
|
|
352
|
+
*/
|
|
221
353
|
constructor(options?: Partial<LoggerOptions>);
|
|
354
|
+
/**
|
|
355
|
+
* Writes a log entry when the message level passes the configured filter.
|
|
356
|
+
*
|
|
357
|
+
* @param className - Log level name.
|
|
358
|
+
* @param args - Log payload values.
|
|
359
|
+
*/
|
|
222
360
|
write(className: string, ...args: any[]): void;
|
|
361
|
+
/**
|
|
362
|
+
* Writes an INFO level log entry.
|
|
363
|
+
*
|
|
364
|
+
* @param args - Log payload values.
|
|
365
|
+
*/
|
|
223
366
|
info(...args: any[]): void;
|
|
367
|
+
/**
|
|
368
|
+
* Writes an ERROR level log entry.
|
|
369
|
+
*
|
|
370
|
+
* @param args - Log payload values.
|
|
371
|
+
*/
|
|
224
372
|
error(...args: any[]): void;
|
|
373
|
+
/**
|
|
374
|
+
* Writes a WARN level log entry.
|
|
375
|
+
*
|
|
376
|
+
* @param args - Log payload values.
|
|
377
|
+
*/
|
|
225
378
|
warn(...args: any[]): void;
|
|
379
|
+
/**
|
|
380
|
+
* Writes a DEBUG level log entry.
|
|
381
|
+
*
|
|
382
|
+
* @param args - Log payload values.
|
|
383
|
+
*/
|
|
226
384
|
debug(...args: any[]): void;
|
|
385
|
+
/**
|
|
386
|
+
* Writes a VERBOSE level log entry.
|
|
387
|
+
*
|
|
388
|
+
* @param args - Log payload values.
|
|
389
|
+
*/
|
|
227
390
|
verbose(...args: any[]): void;
|
|
228
391
|
}
|
|
229
392
|
|
|
393
|
+
/**
|
|
394
|
+
* @public
|
|
395
|
+
*/
|
|
230
396
|
export declare interface LoggerOptions {
|
|
231
397
|
level: string;
|
|
232
398
|
showClass: boolean;
|
|
@@ -252,32 +418,74 @@ export declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T
|
|
|
252
418
|
keys?: (keyof T)[];
|
|
253
419
|
}) => FieldProcessorMap;
|
|
254
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Fluent markdown content builder.
|
|
423
|
+
*
|
|
424
|
+
* @public
|
|
425
|
+
*/
|
|
255
426
|
export declare class Markdown extends StringBuilder {
|
|
256
427
|
#private;
|
|
428
|
+
/**
|
|
429
|
+
* Writes a markdown heading and trailing blank line.
|
|
430
|
+
*
|
|
431
|
+
* @param text - Heading text.
|
|
432
|
+
* @param level - Heading level from 1 to 6.
|
|
433
|
+
*/
|
|
257
434
|
header(text: string, level?: number): this;
|
|
435
|
+
/**
|
|
436
|
+
* Starts a fenced code block and optionally writes code and closes it.
|
|
437
|
+
*
|
|
438
|
+
* @param code - Optional code content.
|
|
439
|
+
* @param language - Optional code language id.
|
|
440
|
+
*/
|
|
258
441
|
codeBlock(code?: string, language?: string): this;
|
|
442
|
+
/** Closes the current fenced code block. */
|
|
259
443
|
endCodeBlock(): this;
|
|
260
|
-
|
|
444
|
+
/** Writes an inline markdown link. */
|
|
445
|
+
link(text: string, url: string, title?: string): this;
|
|
446
|
+
/** Writes a markdown table from headers and rows. */
|
|
261
447
|
table(headers: string[], rows: string[][]): this;
|
|
448
|
+
/** Writes one or more quoted lines. */
|
|
262
449
|
blockquote(text: string): this;
|
|
450
|
+
/** Writes bold text. */
|
|
263
451
|
bold(text: string): this;
|
|
452
|
+
/** Writes italic text. */
|
|
264
453
|
italic(text: string): this;
|
|
454
|
+
/** Writes a bullet item line. */
|
|
265
455
|
item(text: string): this;
|
|
456
|
+
/** Writes bullet items from an array or key-value map. */
|
|
266
457
|
items(items: string[] | Record<string, any>): this;
|
|
458
|
+
/** Writes an ordered list starting from the provided number. */
|
|
267
459
|
orderedList(items: string[], start?: number): this;
|
|
460
|
+
/** Writes inline code text. */
|
|
268
461
|
code(text: string): this;
|
|
462
|
+
/** Writes a horizontal rule. */
|
|
269
463
|
horizontalRule(): this;
|
|
464
|
+
/** Writes an image markdown line. */
|
|
270
465
|
image(alt: string, url: string): this;
|
|
466
|
+
/** Writes strikethrough text. */
|
|
271
467
|
strikethrough(text: string): this;
|
|
468
|
+
/** Writes highlighted text using == syntax. */
|
|
272
469
|
highlight(text: string): this;
|
|
470
|
+
/** Writes subscript text using ~ syntax. */
|
|
273
471
|
subscript(text: string): this;
|
|
472
|
+
/** Writes superscript text using ^ syntax. */
|
|
274
473
|
superscript(text: string): this;
|
|
474
|
+
/** Writes a markdown task list. */
|
|
275
475
|
taskList(items: {
|
|
276
476
|
text: string;
|
|
277
477
|
checked: boolean;
|
|
278
478
|
}[]): this;
|
|
479
|
+
/**
|
|
480
|
+
* Starts a section heading and increments internal nesting level.
|
|
481
|
+
*
|
|
482
|
+
* @param text - Section title.
|
|
483
|
+
* @param level - Optional explicit heading level baseline.
|
|
484
|
+
*/
|
|
279
485
|
section(text: string, level?: number): this;
|
|
486
|
+
/** Decrements section nesting level by one. */
|
|
280
487
|
endSection(): this;
|
|
488
|
+
/** Sets the internal section nesting level directly. */
|
|
281
489
|
setSectionLevel(level: number): this;
|
|
282
490
|
}
|
|
283
491
|
|
|
@@ -425,6 +633,9 @@ export declare type ObjectorPluginConstructor = new (o: Objector, ...args: any[]
|
|
|
425
633
|
|
|
426
634
|
declare type ObjectorPluginFunction = (o: Objector) => void;
|
|
427
635
|
|
|
636
|
+
/**
|
|
637
|
+
* @public
|
|
638
|
+
*/
|
|
428
639
|
export declare interface Output {
|
|
429
640
|
name: string;
|
|
430
641
|
type?: 'json' | 'yaml' | 'text';
|
|
@@ -491,24 +702,74 @@ declare type SharedFunctionOptions = ObjectorDecoratorOptions;
|
|
|
491
702
|
|
|
492
703
|
declare type SourceFunc = (...args: any[]) => any;
|
|
493
704
|
|
|
705
|
+
/**
|
|
706
|
+
* @public
|
|
707
|
+
*/
|
|
494
708
|
export declare class StringBuilder {
|
|
495
709
|
#private;
|
|
496
710
|
options: StringBuilderOptions;
|
|
711
|
+
/**
|
|
712
|
+
* Creates a new StringBuilder instance.
|
|
713
|
+
*
|
|
714
|
+
* @param initial - Optional initial content.
|
|
715
|
+
* @param options - Builder formatting options.
|
|
716
|
+
*/
|
|
497
717
|
constructor(initial?: string | string[] | StringBuilder, options?: StringBuilderOptions);
|
|
718
|
+
/**
|
|
719
|
+
* Replaces current formatting options.
|
|
720
|
+
*
|
|
721
|
+
* @param options - New builder options.
|
|
722
|
+
* @returns Current builder instance.
|
|
723
|
+
*/
|
|
498
724
|
setOptions(options: StringBuilderOptions): this;
|
|
725
|
+
/** Clears all buffered blocks. */
|
|
499
726
|
clear(): this;
|
|
727
|
+
/** Returns true when no content is buffered. */
|
|
500
728
|
isEmpty(): boolean;
|
|
729
|
+
/** Returns concatenated content. */
|
|
501
730
|
toString(): string;
|
|
731
|
+
/** Increases indentation level by one. */
|
|
502
732
|
indent(): this;
|
|
733
|
+
/** Decreases indentation level by one when possible. */
|
|
503
734
|
dedent(): this;
|
|
735
|
+
/** Returns current indentation level. */
|
|
504
736
|
getCurrentIndent(): number;
|
|
737
|
+
/** Returns current content split by newline. */
|
|
505
738
|
getLines(): string[];
|
|
739
|
+
/**
|
|
740
|
+
* Formats a line according to indentation and line options.
|
|
741
|
+
*
|
|
742
|
+
* @param line - Input line to format.
|
|
743
|
+
* @returns Formatted line including line separator.
|
|
744
|
+
*/
|
|
506
745
|
formatLine(line?: string): string;
|
|
746
|
+
/**
|
|
747
|
+
* Appends one or more values to the buffer.
|
|
748
|
+
*
|
|
749
|
+
* @param args - Values to append.
|
|
750
|
+
* @returns Current builder instance.
|
|
751
|
+
*/
|
|
507
752
|
write(...args: any[]): this;
|
|
753
|
+
/**
|
|
754
|
+
* Writes one or more formatted lines.
|
|
755
|
+
*
|
|
756
|
+
* @param args - Values to write as lines.
|
|
757
|
+
* @returns Current builder instance.
|
|
758
|
+
*/
|
|
508
759
|
writeLine(...args: any[]): this;
|
|
760
|
+
/**
|
|
761
|
+
* Maps input items to writes using a callback.
|
|
762
|
+
*
|
|
763
|
+
* @param items - Source items.
|
|
764
|
+
* @param fn - Mapping callback.
|
|
765
|
+
* @returns Current builder instance.
|
|
766
|
+
*/
|
|
509
767
|
writeMap<T>(items: T[], fn: (item: T, index: number, builder: this) => string | this): this;
|
|
510
768
|
}
|
|
511
769
|
|
|
770
|
+
/**
|
|
771
|
+
* @public
|
|
772
|
+
*/
|
|
512
773
|
export declare interface StringBuilderOptions {
|
|
513
774
|
indentChar?: string;
|
|
514
775
|
indentSize?: number;
|
|
@@ -522,6 +783,16 @@ export declare const variable: (options?: VariableOptions) => (_: any, ctx: Clas
|
|
|
522
783
|
|
|
523
784
|
declare type VariableOptions = ObjectorDecoratorOptions;
|
|
524
785
|
|
|
786
|
+
/**
|
|
787
|
+
* Encodes and writes content to a file path using the selected format encoder.
|
|
788
|
+
*
|
|
789
|
+
* @param filePath - Destination file path.
|
|
790
|
+
* @param content - Data to encode and write.
|
|
791
|
+
* @param options - Encoder selection options.
|
|
792
|
+
* @returns Promise resolved when writing completes.
|
|
793
|
+
* @throws - When no encoder can be resolved.
|
|
794
|
+
* @public
|
|
795
|
+
*/
|
|
525
796
|
export declare const writeFormat: (filePath: string, content: any, options?: WriteFormatOptions) => Promise<void>;
|
|
526
797
|
|
|
527
798
|
/**
|
|
@@ -540,8 +811,20 @@ export declare interface WriteFormatOptions {
|
|
|
540
811
|
encoders?: Record<string, WriteFormatEncoder>;
|
|
541
812
|
}
|
|
542
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Writes a single output entry to disk.
|
|
816
|
+
*
|
|
817
|
+
* @param o - Output entry to write.
|
|
818
|
+
* @param options - Writing behavior configuration.
|
|
819
|
+
* @returns Promise resolved when output is processed.
|
|
820
|
+
* @throws - When class requirements fail or file operations fail.
|
|
821
|
+
* @public
|
|
822
|
+
*/
|
|
543
823
|
export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
544
824
|
|
|
825
|
+
/**
|
|
826
|
+
* @public
|
|
827
|
+
*/
|
|
545
828
|
export declare interface WriteOutputOption {
|
|
546
829
|
targetDirectory?: string;
|
|
547
830
|
writing?: (output: Output) => boolean | undefined | void;
|
|
@@ -549,8 +832,19 @@ export declare interface WriteOutputOption {
|
|
|
549
832
|
classRequired?: boolean;
|
|
550
833
|
}
|
|
551
834
|
|
|
835
|
+
/**
|
|
836
|
+
* Writes multiple outputs to disk.
|
|
837
|
+
*
|
|
838
|
+
* @param outputs - Output definitions to write.
|
|
839
|
+
* @param options - Writing behavior configuration.
|
|
840
|
+
* @returns Promise resolved when all outputs are processed.
|
|
841
|
+
* @public
|
|
842
|
+
*/
|
|
552
843
|
export declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
|
|
553
844
|
|
|
845
|
+
/**
|
|
846
|
+
* @public
|
|
847
|
+
*/
|
|
554
848
|
export declare interface WriteOutputsOption extends WriteOutputOption {
|
|
555
849
|
removeFirst?: boolean;
|
|
556
850
|
}
|
|
@@ -579,28 +873,6 @@ declare global {
|
|
|
579
873
|
}
|
|
580
874
|
}
|
|
581
875
|
|
|
582
|
-
declare global {
|
|
583
|
-
interface Array<T> {
|
|
584
|
-
mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
|
|
585
|
-
forEachAsync(callback: (value: T, index: number, array: T[]) => Promise<void>): Promise<void>;
|
|
586
|
-
sortBy<K extends keyof T>(selector: (item: T) => T[K], ascending?: boolean): T[];
|
|
587
|
-
unique(): T[];
|
|
588
|
-
uniqueBy<K extends keyof T>(selector: (item: T) => T[K]): T[];
|
|
589
|
-
groupBy<K extends keyof T>(selector: (item: T) => T[K]): Record<T[K] & (string | number | symbol), T[]>;
|
|
590
|
-
toObject<K extends keyof T, V>(keySelector: (item: T) => T[K], valueSelector?: (item: T) => V): Record<T[K] & (string | number | symbol), V>;
|
|
591
|
-
toObjectWithKey<K extends keyof T>(key: K): Record<string, T>;
|
|
592
|
-
nonNullMap<U>(callback: (value: T, index: number, array: T[]) => U | null | undefined): U[];
|
|
593
|
-
nonNullMapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U | null | undefined>): Promise<U[]>;
|
|
594
|
-
findOrFail(predicate: (value: T, index: number, array: T[]) => boolean, message?: string, thisArg?: any): T;
|
|
595
|
-
selectFor<K>(predicate: (value: T, index: number, array: T[]) => boolean, selector: (value: T) => K, message?: string, thisArg?: any): K;
|
|
596
|
-
createInstances<TTarget>(targetConstructor: new (...args: any[]) => TTarget, ...args: any[]): TTarget[];
|
|
597
|
-
mergeAll(options?: MergeOptions): any;
|
|
598
|
-
}
|
|
599
|
-
interface ArrayConstructor {
|
|
600
|
-
flat<T>(v: T | T[] | T[][]): T[];
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
876
|
declare global {
|
|
605
877
|
interface String {
|
|
606
878
|
capitalize(): string;
|
|
@@ -628,3 +900,25 @@ declare global {
|
|
|
628
900
|
}
|
|
629
901
|
}
|
|
630
902
|
|
|
903
|
+
declare global {
|
|
904
|
+
interface Array<T> {
|
|
905
|
+
mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
|
|
906
|
+
forEachAsync(callback: (value: T, index: number, array: T[]) => Promise<void>): Promise<void>;
|
|
907
|
+
sortBy<K extends keyof T>(selector: (item: T) => T[K], ascending?: boolean): T[];
|
|
908
|
+
unique(): T[];
|
|
909
|
+
uniqueBy<K extends keyof T>(selector: (item: T) => T[K]): T[];
|
|
910
|
+
groupBy<K extends keyof T>(selector: (item: T) => T[K]): Record<T[K] & (string | number | symbol), T[]>;
|
|
911
|
+
toObject<K extends keyof T, V>(keySelector: (item: T) => T[K], valueSelector?: (item: T) => V): Record<T[K] & (string | number | symbol), V>;
|
|
912
|
+
toObjectWithKey<K extends keyof T>(key: K): Record<string, T>;
|
|
913
|
+
nonNullMap<U>(callback: (value: T, index: number, array: T[]) => U | null | undefined): U[];
|
|
914
|
+
nonNullMapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U | null | undefined>): Promise<U[]>;
|
|
915
|
+
findOrFail(predicate: (value: T, index: number, array: T[]) => boolean, message?: string, thisArg?: any): T;
|
|
916
|
+
selectFor<K>(predicate: (value: T, index: number, array: T[]) => boolean, selector: (value: T) => K, message?: string, thisArg?: any): K;
|
|
917
|
+
createInstances<TTarget>(targetConstructor: new (...args: any[]) => TTarget, ...args: any[]): TTarget[];
|
|
918
|
+
mergeAll(options?: MergeOptions): any;
|
|
919
|
+
}
|
|
920
|
+
interface ArrayConstructor {
|
|
921
|
+
flat<T>(v: T | T[] | T[][]): T[];
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|