-
Notifications
You must be signed in to change notification settings - Fork 0
/
underscore.d.ts
6496 lines (5770 loc) · 233 KB
/
underscore.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Underscore 1.10
// Project: http://underscorejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov>,
// Josh Baldwin <https://github.com/jbaldwin>,
// Christopher Currens <https://github.com/ccurrens>,
// Ard Timmerman <https://github.com/confususs>,
// Julian Gonggrijp <https://github.com/jgonggrijp>,
// Florian Keller <https://github.com/ffflorian>
// Regev Brody <https://github.com/regevbr>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Michael Ness <https://github.com/reubenrybnik>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
declare var _: _.UnderscoreStatic;
export = _;
export as namespace _;
// The DOM is not required to be present, but these definitions reference type Element for the
// isElement check. If the DOM is present, this declaration will merge.
declare global {
interface Element { }
}
declare namespace _ {
/**
* underscore.js _.throttle options.
**/
interface ThrottleSettings {
/**
* If you'd like to disable the leading-edge call, pass this as false.
**/
leading?: boolean;
/**
* If you'd like to disable the execution on the trailing-edge, pass false.
**/
trailing?: boolean;
}
/**
* underscore.js template settings, set templateSettings or pass as an argument
* to 'template()' to override defaults.
**/
interface TemplateSettings {
/**
* Default value is '/<%([\s\S]+?)%>/g'.
**/
evaluate?: RegExp;
/**
* Default value is '/<%=([\s\S]+?)%>/g'.
**/
interpolate?: RegExp;
/**
* Default value is '/<%-([\s\S]+?)%>/g'.
**/
escape?: RegExp;
/**
* By default, 'template()' places the values from your data in the local scope via the 'with' statement.
* However, you can specify a single variable name with this setting.
**/
variable?: string;
}
interface CompiledTemplate {
(data?: any): string;
source: string;
}
// Common interface between Arrays and jQuery objects
interface List<T> {
[index: number]: T;
length: number;
}
interface Dictionary<T> {
[index: string]: T;
}
type Collection<T> = List<T> | Dictionary<T>;
type EnumerableKey = string | number;
type CollectionKey<V> =
V extends never ? any
: V extends List<any> ? number
: V extends Dictionary<any> ? string
: V extends undefined ? undefined
: never;
interface Predicate<T> {
(value: T): boolean;
}
interface CollectionIterator<T extends TypeOfCollection<V, any>, TResult, V = Collection<T>> {
(element: T, key: CollectionKey<V>, collection: V): TResult;
}
interface ListIterator<T extends TypeOfList<V>, TResult, V = List<T>> extends CollectionIterator<T, TResult, V> { }
interface ObjectIterator<T extends TypeOfDictionary<V, any>, TResult, V = Dictionary<T>> extends CollectionIterator<T, TResult, V> { }
type Iteratee<V, R, T extends TypeOfCollection<V, any> = TypeOfCollection<V>> =
CollectionIterator<T, R, V> |
EnumerableKey |
EnumerableKey[] |
Partial<T> |
null |
undefined;
type IterateeResult<I, T> =
I extends (...args: any[]) => infer R ? R
: I extends keyof T ? T[I]
: I extends EnumerableKey | EnumerableKey[] ? any
: I extends object ? boolean
: I extends null | undefined ? T
: never;
type PropertyTypeOrAny<T, K> = K extends keyof T ? T[K] : any;
interface MemoCollectionIterator<T extends TypeOfCollection<V>, TResult, V = Collection<T>> {
(prev: TResult, curr: T, key: CollectionKey<V>, collection: V): TResult;
}
interface MemoIterator<T extends TypeOfList<V>, TResult, V = List<T>> extends MemoCollectionIterator<T, TResult, V> { }
interface MemoObjectIterator<T extends TypeOfDictionary<V>, TResult, V = Dictionary<T>> extends MemoCollectionIterator<T, TResult, V> { }
type TypeOfList<V> =
V extends never ? any
: V extends List<infer T> ? T
: never;
type TypeOfDictionary<V, TDefault = never> =
V extends never ? any
: V extends Dictionary<infer T> ? T
: TDefault;
type TypeOfCollection<V, TObjectDefault = never> = TypeOfList<V> | TypeOfDictionary<V, TObjectDefault>;
type ListItemOrSelf<T> = T extends List<infer TItem> ? TItem : T;
// unfortunately it's not possible to recursively collapse all possible list dimensions to T[] at this time,
// so give up after one dimension since that's likely the most common case
// '& object' prevents strings from being matched by list checks so types like string[] don't end up resulting in any
type DeepestListItemOrSelf<T> =
T extends List<infer TItem> & object
? TItem extends List<any> & object
? any
: TItem
: T;
// if T is an inferrable pair, the value type for the pair
// if T is a list, assume that it contains pairs of some type, so any
// if T isn't a list, there's no way that it can provide pairs, so never
type PairValue<T> =
T extends Readonly<[EnumerableKey, infer TValue]> ? TValue
: T extends List<infer TValue> ? TValue
: never;
type AnyFalsy = undefined | null | false | '' | 0;
type Truthy<T> = Exclude<T, AnyFalsy>;
type _Pick<V, K extends string> =
Extract<K, keyof V> extends never ? Partial<V>
: Pick<V, Extract<K, keyof V>>;
// switch to Omit when the minimum TS version moves past 3.5
type _Omit<V, K extends string> =
V extends never ? any
: Extract<K, keyof V> extends never ? Partial<V>
: Pick<V, Exclude<keyof V, K>>;
type _ChainSingle<V> = _Chain<TypeOfCollection<V>, V>;
interface Cancelable {
cancel(): void;
}
interface UnderscoreStatic {
/**
* Underscore OOP Wrapper, all Underscore functions that take an object
* as the first parameter can be invoked through this function.
* @param value First argument to Underscore object functions.
* @returns An Underscore wrapper around the supplied value.
**/
<V>(value: V): Underscore<TypeOfCollection<V>, V>;
/***************
* Collections *
***************/
/**
* Iterates over a `collection` of elements, yielding each in turn to
* an `iteratee`. The `iteratee` is bound to the context object, if one
* is passed.
* @param collection The collection of elements to iterate over.
* @param iteratee The iteratee to call for each element in
* `collection`.
* @param context 'this' object in `iteratee`, optional.
* @returns The original collection.
**/
each<V extends Collection<any>>(
collection: V,
iteratee: CollectionIterator<TypeOfCollection<V>, void, V>,
context?: any
): V;
/**
* @see each
**/
forEach: UnderscoreStatic['each'];
/**
* Produces a new array of values by mapping each value in `collection`
* through a transformation `iteratee`.
* @param collection The collection to transform.
* @param iteratee The iteratee to use to transform each item in
* `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns The mapped result.
**/
map<V extends Collection<any>, I extends Iteratee<V, any>>(
collection: V,
iteratee: I,
context?: any
): IterateeResult<I, TypeOfCollection<V>>[];
/**
* @see map
**/
collect: UnderscoreStatic['map'];
/**
* Also known as inject and foldl, reduce boils down a `collection` of
* values into a single value. `memo` is the initial state of the
* reduction, and each successive step of it should be returned by
* `iteratee`.
*
* If no memo is passed to the initial invocation of reduce, `iteratee`
* is not invoked on the first element of `collection`. The first
* element is instead passed as the memo in the invocation of
* `iteratee` on the next element in `collection`.
* @param collection The collection to reduce.
* @param iteratee The function to call on each iteration to reduce the
* collection.
* @param memo The initial reduce state or undefined to use the first
* item in `collection` as initial state.
* @param context `this` object in `iteratee`, optional.
* @returns The reduced result.
**/
reduce<V extends Collection<any>, TResult>(
collection: V,
iteratee: MemoCollectionIterator<TypeOfCollection<V>, TResult, V>,
memo: TResult,
context?: any
): TResult;
reduce<V extends Collection<any>, TResult = TypeOfCollection<V>>(
collection: V,
iteratee: MemoCollectionIterator<TypeOfCollection<V>,
TResult | TypeOfCollection<V>,
V>
): TResult | TypeOfCollection<V> | undefined;
/**
* @see reduce
**/
inject: UnderscoreStatic['reduce'];
/**
* @see reduce
**/
foldl: UnderscoreStatic['reduce'];
/**
* The right-associative version of reduce.
*
* This is not as useful in JavaScript as it would be in a language
* with lazy evaluation.
* @param collection The collection to reduce.
* @param iteratee The function to call on each iteration to reduce the
* collection.
* @param memo The initial reduce state or undefined to use the first
* item in `collection` as the initial state.
* @param context `this` object in `iteratee`, optional.
* @returns The reduced result.
**/
reduceRight<V extends Collection<any>, TResult>(
collection: V,
iteratee: MemoCollectionIterator<TypeOfCollection<V>, TResult, V>,
memo: TResult,
context?: any
): TResult;
reduceRight<V extends Collection<any>, TResult = TypeOfCollection<V>>(
collection: V,
iteratee: MemoCollectionIterator<TypeOfCollection<V>,
TResult | TypeOfCollection<V>,
V>
): TResult | TypeOfCollection<V> | undefined;
/**
* @see reduceRight
**/
foldr: UnderscoreStatic['reduceRight'];
/**
* Looks through each value in `collection`, returning the first one
* that passes a truth test (`iteratee`), or undefined if no value
* passes the test. The function returns as soon as it finds an
* acceptable element, and doesn't traverse the entire collection.
* @param collection The collection to search.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns The first element in `collection` that passes the truth
* test or undefined if no elements pass.
**/
find<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): TypeOfCollection<V> | undefined;
/**
* @see find
**/
detect: UnderscoreStatic['find'];
/**
* Looks through each value in `collection`, returning an array of
* all the values that pass a truth test (`iteratee`).
* @param collection The collection to filter.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns The set of values that pass the truth test.
**/
filter<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): TypeOfCollection<V>[];
/**
* @see filter
**/
select: UnderscoreStatic['filter'];
/**
* Looks through each value in `collection`, returning an array of all
* the elements that match the key-value pairs listed in `properties`.
* @param collection The collection in which to find elements that
* match `properties`.
* @param properties The properties to check for on the elements within
* `collection`.
* @returns The elements in `collection` that match `properties`.
**/
where<V extends Collection<any>>(
collection: V,
properties: Partial<TypeOfCollection<V>>
): TypeOfCollection<V>[];
/**
* Looks through `collection` and returns the first value that matches
* all of the key-value pairs listed in `properties`. If no match is
* found, or if list is empty, undefined will be returned.
* @param collection The collection in which to find an element that
* matches `properties`.
* @param properties The properties to check for on the elements within
* `collection`.
* @returns The first element in `collection` that matches `properties`
* or undefined if no match is found.
**/
findWhere<V extends Collection<any>>(
collection: V,
properties: Partial<TypeOfCollection<V>>
): TypeOfCollection<V> | undefined;
/**
* Returns the values in `collection` without the elements that pass a
* truth test (`iteratee`).
* The opposite of filter.
* @param collection The collection to filter.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns The set of values that fail the truth test.
**/
reject<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): TypeOfCollection<V>[];
/**
* Returns true if all of the values in `collection` pass the
* `iteratee` truth test. Short-circuits and stops traversing
* `collection` if a false element is found.
* @param collection The collection to evaluate.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns True if all elements pass the truth test, otherwise false.
**/
every<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): boolean;
/**
* @see every
**/
all: UnderscoreStatic['every'];
/**
* Returns true if any of the values in `collection` pass the
* `iteratee` truth test. Short-circuits and stops traversing
* `collection` if a true element is found.
* @param collection The collection to evaluate.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns True if any element passed the truth test, otherwise false.
**/
some<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): boolean;
/**
* @see some
**/
any: UnderscoreStatic['some'];
/**
* Returns true if the value is present in `collection`. Uses indexOf
* internally, if `collection` is a List. Use `fromIndex` to start your
* search at a given index.
* @param collection The collection to check for `value`.
* @param value The value to check `collection` for.
* @param fromIndex The index to start searching from, optional,
* default = 0, only used when `collection` is a List.
* @returns True if `value` is present in `collection` after
* `fromIndex`, otherwise false.
**/
contains<V extends Collection<any>>(
collection: V,
value: any,
fromIndex?: number
): boolean;
/**
* @see contains
**/
include: UnderscoreStatic['contains'];
/**
* @see contains
**/
includes: UnderscoreStatic['contains'];
/**
* Calls the method named by `methodName` on each value in
* `collection`. Any extra arguments passed to invoke will be forwarded
* on to the method invocation.
* @param collection The collection of elements to invoke `methodName`
* on.
* @param methodName The name of the method to call on each element in
* `collection`.
* @param args Additional arguments to pass to method `methodName`.
* @returns An array containing the result of the method call for each
* item in `collection`.
**/
invoke(
list: Collection<any>,
methodName: string,
...args: any[]
): any[];
/**
* A convenient version of what is perhaps the most common use-case for
* map: extracting a list of property values.
* @param collection The collection of items.
* @param propertyName The name of a specific property to retrieve from
* all items in `collection`.
* @returns The set of values for the specified `propertyName` for each
* item in `collection`.
**/
pluck<V extends Collection<any>, K extends EnumerableKey>(
collection: V,
propertyName: K
): PropertyTypeOrAny<TypeOfCollection<V>, K>[];
/**
* Returns the maximum value in `collection`. If an `iteratee` is
* provided, it will be used on each element to generate the criterion
* by which the element is ranked. -Infinity is returned if list is
* empty. Non-numerical values returned by `iteratee` will be ignored.
* @param collection The collection in which to find the maximum value.
* @param iteratee The iteratee that provides the criterion by which
* each element is ranked, optional if evaluating a collection of
* numbers.
* @param context `this` object in `iteratee`, optional.
* @returns The maximum element within `collection` or -Infinity if
* `collection` is empty.
**/
max<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, any>,
context?: any
): TypeOfCollection<V> | number;
/**
* Returns the minimum value in `collection`. If an `iteratee` is
* provided, it will be used on each element to generate the criterion
* by which the element is ranked. Infinity is returned if list is
* empty. Non-numerical values returned by `iteratee` will be ignored.
* @param collection The collection in which to find the minimum value.
* @param iteratee The iteratee that provides the criterion by which
* each element is ranked, optional if evaluating a collection of
* numbers.
* @param context `this` object in `iteratee`, optional.
* @returns The minimum element within `collection` or Infinity if
* `collection` is empty.
**/
min<V extends Collection<any>>(
list: V,
iteratee?: Iteratee<V, any>,
context?: any
): TypeOfCollection<V> | number;
/**
* Returns a (stably) sorted copy of `collection`, ranked in ascending
* order by the results of running each value through `iteratee`.
* @param collection The collection to sort.
* @param iteratee An iteratee that provides the value to sort by for
* each item in `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns A sorted copy of `collection`.
**/
sortBy<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, any>,
context?: any): TypeOfCollection<V>[];
/**
* Splits `collection` into sets that are grouped by the result of
* running each value through `iteratee`.
* @param collection The collection to group.
* @param iteratee An iteratee that provides the value to group by for
* each item in `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns A dictionary with the group names provided by `iteratee` as
* properties where each property contains the grouped elements from
* `collection`.
**/
groupBy<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, EnumerableKey>,
context?: any
): Dictionary<TypeOfCollection<V>[]>;
/**
* Given a `collection` and an `iteratee` function that returns a key
* for each element in `collection`, returns an object that acts as an
* index of each item. Just like `groupBy`, but for when you know your
* keys are unique.
* @param collection The collection to index.
* @param iteratee An iteratee that provides the value to index by for
* each item in `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns A dictionary where each item in `collection` is assigned to
* the property designated by `iteratee`.
**/
indexBy<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, EnumerableKey>,
context?: any): Dictionary<TypeOfCollection<V>>;
/**
* Sorts `collection` into groups and returns a count for the number of
* objects in each group. Similar to `groupBy`, but instead of
* returning a list of values, returns a count for the number of values
* in that group.
* @param collection The collection to count.
* @param iteratee An iteratee that provides the value to count by for
* each item in `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns A dictionary with the group names provided by `iteratee` as
* properties where each property contains the count of the grouped
* elements from `collection`.
**/
countBy<V extends Collection<any>>(
collection: V,
iteratee?: Iteratee<V, EnumerableKey>,
context?: any
): Dictionary<number>;
/**
* Returns a shuffled copy of `collection`, using a version of the
* Fisher-Yates shuffle.
* @param collection The collection to shuffle.
* @returns A shuffled copy of `collection`.
**/
shuffle<V extends Collection<any>>(
collection: V
): TypeOfCollection<V>[];
/**
* Produce a random sample from `collection`. Pass a number to return
* `n` random elements from `collection`. Otherwise a single random
* item will be returned.
* @param collection The collection to sample.
* @param n The number of elements to sample from `collection`.
* @returns A random sample of `n` elements from `collection` or a
* single element if `n` is not specified.
**/
sample<V extends Collection<any>>(
collection: V,
n: number
): TypeOfCollection<V>[];
sample<V extends Collection<any>>(
collection: V
): TypeOfCollection<V> | undefined;
/**
* Creates a real Array from `collection` (anything that can be
* iterated over). Useful for transmuting the arguments object.
* @param collection The collection to transform into an array.
* @returns An array containing the elements of `collection`.
**/
toArray<V extends Collection<any>>(
collection: V
): TypeOfCollection<V>[];
/**
* Determines the number of values in `collection`.
* @param collection The collection to determine the number of values
* for.
* @returns The number of values in `collection`.
**/
size(collection: Collection<any>): number;
/**
* Splits `collection` into two arrays: one whose elements all satisfy
* `iteratee` and one whose elements all do not satisfy `iteratee`.
* @param collection The collection to partition.
* @param iteratee The iteratee that defines the partitioning scheme
* for each element in `collection`.
* @param context `this` object in `iteratee`, optional.
* @returns An array composed of two elements, where the first element
* contains the elements in `collection` that satisfied the predicate
* and the second element contains the elements that did not.
**/
partition<V extends Collection<any>>(
list: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): [TypeOfCollection<V>[], TypeOfCollection<V>[]];
/**********
* Arrays *
**********/
/**
* Returns the first element of `list`. Passing `n` will return the
* first `n` elements of `list`.
* @param list The list to retrieve elements from.
* @param n The number of elements to retrieve, optional.
* @returns The first `n` elements of `list` or the first element if
* `n` is omitted.
**/
first<V extends List<any>>(
list: V
): TypeOfList<V> | undefined;
first<V extends List<any>>(
list: V,
n: number
): TypeOfList<V>[];
/**
* @see first
**/
head: UnderscoreStatic['first'];
/**
* @see first
**/
take: UnderscoreStatic['first'];
/**
* Returns everything but the last entry of `list`. Especially useful
* on the arguments object. Pass `n` to exclude the last
* `n` elements from the result.
* @param list The list to retrieve elements from.
* @param n The number of elements from the end of `list` to omit,
* optional, default = 1.
* @returns The elements of `list` with the last `n` items omitted.
**/
initial<V extends List<any>>(
list: V,
n?: number
): TypeOfList<V>[];
/**
* Returns the last element of `list`. Passing `n` will return the last
* `n` elements of `list`.
* @param list The list to retrieve elements from.
* @param n The number of elements to retrieve, optional.
* @returns The last `n` elements of `list` or the last element if `n`
* is omitted.
**/
last<V extends List<any>>(
list: V
): TypeOfList<V> | undefined;
last<V extends List<any>>(
list: V,
n: number
): TypeOfList<V>[];
/**
* Returns the rest of the elements in `list`. Pass an `index` to
* return the values of the list from that index onward.
* @param list The list to retrieve elements from.
* @param index The index to start retrieving elements from, optional,
* default = 1.
* @returns The elements of `list` from `index` to the end of the list.
**/
rest<V extends List<any>>(
list: V,
index?: number
): TypeOfList<V>[];
/**
* @see rest
**/
tail: UnderscoreStatic['rest'];
/**
* @see rest
**/
drop: UnderscoreStatic['rest'];
/**
* Returns a copy of `list` with all falsy values removed. In
* JavaScript, false, null, 0, "", undefined and NaN are all falsy.
* @param list The list to compact.
* @returns An array containing the elements of `list` without falsy
* values.
**/
compact<V extends List<any> | null | undefined>(
list: V
): Truthy<TypeOfList<V>>[];
/**
* Flattens a nested `list` (the nesting can be to any depth). If you
* pass shallow, the `list` will only be flattened a single level.
* @param list The list to flatten.
* @param shallow True to only flatten one level, optional,
* default = false.
* @returns The flattened `list`.
**/
flatten<V extends List<any>>(
list: V,
shallow?: false
): DeepestListItemOrSelf<TypeOfList<V>>[];
flatten<V extends List<any>>(
list: V,
shallow: true
): ListItemOrSelf<TypeOfList<V>>[];
/**
* Returns a copy of `list` with all instances of `values` removed.
* @param list The list to exclude `values` from.
* @param values The values to exclude from `list`.
* @returns An array that contains all elements of `list` except for
* `values`.
**/
without<V extends List<any>>(
list: V,
...values: TypeOfList<V>[]
): TypeOfList<V>[];
/**
* Computes the union of the passed-in `lists`: the list of unique
* items, examined in order from first list to last list, that are
* present in one or more of the lists.
* @param lists The lists to compute the union of.
* @returns The union of elements within `lists`.
**/
union<T>(...lists: List<T>[]): T[];
/**
* Computes the list of values that are the intersection of the
* passed-in `lists`. Each value in the result is present in each of
* the lists.
* @param lists The lists to compute the intersection of.
* @returns The intersection of elements within the `lists`.
**/
intersection<T>(...lists: List<T>[]): T[];
/**
* Similar to without, but returns the values from `list` that are not
* present in `others`.
* @param list The starting list.
* @param others The lists of values to exclude from `list`.
* @returns The contents of `list` without the values in `others`.
**/
difference<T>(
list: List<T>,
...others: List<T>[]
): T[];
/**
* Produces a duplicate-free version of `list`, using === to test
* object equality. If you know in advance that `list` is sorted,
* passing true for isSorted will run a much faster algorithm. If you
* want to compute unique items based on a transformation, pass an
* iteratee function.
* @param list The list to remove duplicates from.
* @param isSorted True if `list` is already sorted, optional,
* default = false.
* @param iteratee Transform the elements of `list` before comparisons
* for uniqueness.
* @param context 'this' object in `iteratee`, optional.
* @returns An array containing only the unique elements in `list`.
**/
uniq<V extends List<any>>(
list: V,
isSorted?: boolean,
iteratee?: Iteratee<V, any>,
context?: any
): TypeOfList<V>[];
uniq<V extends List<any>>(
list: V,
iteratee?: Iteratee<V, any>,
context?: any
): TypeOfList<V>[];
/**
* @see uniq
**/
unique: UnderscoreStatic['uniq'];
/**
* Merges together the values of each of the `lists` with the values at
* the corresponding position. Useful when you have separate data
* sources that are coordinated through matching list indexes.
* @param lists The lists to zip.
* @returns The zipped version of `lists`.
**/
zip(...lists: List<any>[]): any[][];
/**
* The opposite of zip. Given a list of lists, returns a series of new
* arrays, the first of which contains all of the first elements in the
* input lists, the second of which contains all of the second
* elements, and so on.
* @param lists The lists to unzip.
* @returns The unzipped version of `lists`.
**/
unzip(lists: List<List<any>>): any[][];
/**
* Converts lists into objects. Pass either a single `list` of
* [key, value] pairs, or a `list` of keys and a list of `values`.
* Passing by pairs is the reverse of pairs. If duplicate keys exist,
* the last value wins.
* @param list A list of [key, value] pairs or a list of keys.
* @param values If `list` is a list of keys, a list of values
* corresponding to those keys.
* @returns An object comprised of the provided keys and values.
**/
object<TList extends List<EnumerableKey>, TValue>(
list: TList,
values: List<TValue>
): Dictionary<TValue | undefined>;
object<TList extends List<List<any>>>(
list: TList
): Dictionary<PairValue<TypeOfList<TList>>>;
/**
* Returns the index at which `value` can be found in `list`, or -1 if
* `value` is not present. If you're working with a large list and you
* know that the list is already sorted, pass true for
* `isSortedOrFromIndex` to use a faster binary search...or, pass a
* number in order to look for the first matching value in the list
* after the given index.
* @param list The list to search for the index of `value`.
* @param value The value to search for within `list`.
* @param isSortedOrFromIndex True if `list` is already sorted OR the
* starting index for the search, optional.
* @returns The index of the first occurrence of `value` within `list`
* or -1 if `value` is not found.
**/
indexOf<V extends List<any>>(
list: V,
value: TypeOfList<V>,
isSortedOrFromIndex?: boolean | number
): number;
/**
* Returns the index of the last occurrence of `value` in `list`, or -1
* if `value` is not present. Pass `fromIndex` to start your search at
* a given index.
* @param list The list to search for the last occurrence of `value`.
* @param value The value to search for within `list`.
* @param fromIndex The starting index for the search, optional.
* @returns The index of the last occurrence of `value` within `list`
* or -1 if `value` is not found.
**/
lastIndexOf<V extends List<any>>(
list: V,
value: TypeOfList<V>,
fromIndex?: number
): number;
/**
* Returns the first index of an element in `list` where the `iteratee`
* truth test passes, otherwise returns -1.
* @param list The list to search for the index of the first element
* that passes the truth test.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns The index of the first element in `list` where the
* truth test passes or -1 if no elements pass.
**/
findIndex<V extends List<any>>(
list: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): number;
/**
* Returns the last index of an element in `list` where the `iteratee`
* truth test passes, otherwise returns -1.
* @param list The list to search for the index of the last element
* that passes the truth test.
* @param iteratee The truth test to apply.
* @param context `this` object in `iteratee`, optional.
* @returns The index of the last element in `list` where the
* truth test passes or -1 if no elements pass.
**/
findLastIndex<V extends List<any>>(
list: V,
iteratee?: Iteratee<V, boolean>,
context?: any
): number;
/**
* Uses a binary search to determine the lowest index at which the
* value should be inserted into `list` in order to maintain `list`'s
* sorted order. If an iteratee is provided, it will be used to compute
* the sort ranking of each value, including the value you pass.
* @param list A sorted list.
* @param value The value to determine an insert index for to mainain
* the sorting in `list`.
* @param iteratee Iteratee to compute the sort ranking of each
* element including `value`, optional.
* @param context `this` object in `iteratee`, optional.
* @returns The index where `value` should be inserted into `list`.
**/
sortedIndex<V extends List<any>>(
list: V,
value: TypeOfList<V>,
iteratee?: Iteratee<V | undefined, any>,
context?: any
): number;
/**
* A function to create flexibly-numbered lists of integers, handy for
* `each` and `map` loops. Returns a list of integers from
* `startOrStop` (inclusive) to `stop` (exclusive), incremented
* (or decremented) by `step`. Note that ranges that `stop` before they
* `start` are considered to be zero-length instead of negative - if
* you'd like a negative range, use a negative `step`.
*
* If `stop` is not specified, `startOrStop` will be the number to stop
* at and the default start of 0 will be used.
* @param startOrStop If `stop` is specified, the number to start at.
* Otherwise, this is the number to stop at and the default start of 0
* will be used.
* @param stop The number to stop at.
* @param step The number to count up by each iteration, optional,
* default = 1.
* @returns An array of numbers from start to `stop` with increments
* of `step`.
**/
range(
startOrStop: number,
stop?: number,
step?: number
): number[];
/**
* Chunks `list` into multiple arrays, each containing `length` or
* fewer items.
* @param list The list to chunk.