-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
451 lines (386 loc) · 17.1 KB
/
index.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
declare module 'modern-linq' {
export interface LinqIterable<TValue> extends Iterable<TValue> {
/**
* Filters the iterable using predicate function typed overload
* @param predicate
*/
where<TSubValue extends TValue>(predicate: (item: TValue) => item is TSubValue): LinqIterable<TSubValue>;
/**
* Filters the iterable using predicate function
* @param predicate
*/
where(predicate: (item: TValue) => boolean): LinqIterable<TValue>;
/**
* Maps the iterable items
* @param map map function
*/
select<TOutput>(map: (item: TValue) => TOutput): LinqIterable<TOutput>;
/**
* Flat Iterable of collections
* @param innerSelector Function which returns an inner collection
*/
selectMany<TInner>(innerSelector: (item: TValue) => TInner[]): LinqIterable<TInner>;
/**
* Flat iterable of collection
* @param innerSelector Function which returns an inner collection
* @param resultCreator Function thish converts pair of outer and inner element to result.
*/
selectMany<TInner, TResult>(innerSelector: (item: TValue) => TInner[], resultCreator: (outer: TValue, inner: TInner) => TResult): LinqIterable<TResult>;
/**
* Take first N items from iterable
* @param count
*/
take(count: number): LinqIterable<TValue>;
/**
* Return items while condition return true
* @param condition
*/
takeWhile(condition: (item: TValue, index: number) => boolean): LinqIterable<TValue>;
/**
* Take last N items from iterable
* @param count
*/
takeLast(count: number): LinqIterable<TValue>;
/**
* Skip first N items from iterable
* @param count
*/
skip(count: number): LinqIterable<TValue>;
/**
* Skip items while condition return true, get the rest
* @param condition
*/
skipWhile(condition: (item: TValue, index: number) => boolean): LinqIterable<TValue>;
/**
* Skip last N items from iterable
* @param count
*/
skipLast(count: number): LinqIterable<TValue>;
/**
* Return distinct items. Can specify optional item comparer
* @param comparer function to compare elements for equality
*/
distinct(comparer?: (a: TValue, b: TValue) => boolean): LinqIterable<TValue>;
/**
* Selects all items of type string
* @param type
*/
ofType(type: 'string'): LinqIterable<string>;
/**
* Selects all items of type number
* @param type
*/
ofType(type: 'number'): LinqIterable<number>;
/**
* Selects all items of type boolean
* @param type
*/
ofType(type: 'boolean'): LinqIterable<boolean>;
/**
* Selects all items of type undefined
* @param type
*/
ofType(type: 'undefined'): LinqIterable<undefined>;
/**
* Selects all items of type function
* @param type
*/
ofType(type: 'function'): LinqIterable<Function>;
/**
* Selects all items of type object
* @param type
*/
ofType(type: 'object'): LinqIterable<object>;
/**
* Selects all items of type symbol
* @param type
*/
ofType(type: 'symbol'): LinqIterable<Symbol>;
/**
* Selects all items of base type
* @param typeCheck
*/
ofType<TOutput extends TValue>(typeCheck: (item: TValue) => item is TOutput): LinqIterable<TOutput>;
/**
* Selects all items of base type
* @param type
*/
ofClass<TOutput extends TValue>(type: { prototype: TOutput }): LinqIterable<TOutput>;
/**
* Group items
* @param keySelector group key selector
*/
groupBy<TKey>(keySelector: (item: TValue, index: number) => TKey): LinqIterable<IGrouping<TKey, TValue>>;
groupBy<TKey, TElement>(keySelector: (item: TValue, index: number) => TKey, elementSelector: (item: TValue, index: number) => TElement): LinqIterable<IGrouping<TKey, TElement>>;
groupBy<TKey, TElement, TResult>(keySelector: (item: TValue, index: number) => TKey, elementSelector: (item: TValue, index: number) => TElement,
resultCreator: (key: TKey, items: LinqIterable<TElement>) => TResult): LinqIterable<TResult>;
/**
* Order by iterable by a key
* @param keySelector
* @param comparer optional comparer.
*/
orderBy<TKey>(keySelector: (item: TValue) => TKey, comparer?: (first: TKey, second: TKey) => number): LinqIterable<TValue>;
/**
* Order by descending iterable by a key
* @param keySelector
* @param comparer optional comparer.
*/
orderByDescending<TKey>(keySelector: (item: TValue) => TKey, comparer?: (first: TKey, second: TKey) => number): LinqIterable<TValue>;
/**
* Do a group join (left join) between current and external iterable. For each item of current sequence get array of items from external sequence.
* @param joinIterable external iterable
* @param sourceKeySelector current iterable key selector
* @param joinIterableKeySelector current iterable key selector
* @param resultCreator function which accepts two arguments: first: element from current sequence and second: array of items from the external sequence.
*/
groupJoin<TInner, TKey, TResult>(joinIterable: Iterable<TInner>,
sourceKeySelector: (item: TValue) => TKey,
joinIterableKeySelector: (item: TInner, index: number) => TKey,
resultCreator: (outer: TValue, inner: TInner[]) => TResult): LinqIterable<TResult>;
/**
* Do an inner join between current and external sequence. For each item of current sequence get a item from external sequence.
* @param joinIterable external iterable
* @param sourceKeySelector current iterable key selector
* @param joinIterableKeySelector current iterable key selector
* @param resultCreator function which accepts two arguments: first: element from current sequence and second: element from the external sequence.
*/
join<TInner, TKey, TResult>(joinIterable: Iterable<TInner>,
sourceKeySelector: (item: TValue) => TKey,
joinIterableKeySelector: (item: TInner, index: number) => TKey,
resultCreator: (outer: TValue, inner: TInner) => TResult): LinqIterable<TResult>;
/**
* Concat this iterable with another
* @param secondIterable
*/
concat(secondIterable: Iterable<TValue>): LinqIterable<TValue>;
/**
* Produce a union of two iterables where the result is distinct values from both.
* @param secondIterable
*/
union(secondIterable: Iterable<TValue>): LinqIterable<TValue>;
/**
* Return an intersection of two iterables where the result is distinct values.
* @param secondIterable
* @param comparer optional predicate, if none is provided a default one (===) is used.
*/
intersect(secondIterable: Iterable<TValue>, comparer?: (first: TValue, second: TValue) => boolean): LinqIterable<TValue>;
/**
* Create a paging
* @param pageSize
*/
page(pageSize: number): LinqIterable<TValue[]>;
/**
* Reverse the sequence
*/
reverse(): LinqIterable<TValue[]>;
/**
* Creates an array from iterable
*/
toArray(): TValue[];
/**
* Creates an array from iterable, using map function which creates an array of mapped items.
*/
toArray<TResult>(map: (item: TValue) => TResult): TResult[];
/**
* Create a map object from sequence
* @param keySelector - key selector - keys should be unique, otherwise last keys will override first.
*/
toMap<TKey>(keySelector: (item: TValue) => TKey): Map<TKey, TValue>;
/**
* Create a map object from sequence
* @param keySelector key selector - keys should be unique, otherwise last keys will override first.
* @param elementSelector element selector
*/
toMap<TKey, TElement>(keySelector: (item: TValue) => TKey, elementSelector: (item: TValue) => TElement): Map<TKey, TElement>;
/**
* Creates a set from current sequence.
*/
toSet(): Set<TValue>;
/**
* Get first item of iterable
* @param predicate optional predicate for the item
*/
first(predicate?: (item: TValue) => boolean): TValue | undefined;
/**
* Get first item of iterable, if does not contain any return default
* @param def
* @param predicate
*/
firstOrDefault(def: TValue, predicate?: (item: TValue) => boolean): TValue;
/**
* Get first item of iterable, if no items throw TypeError
*/
firstOrThrow(predicate?: (item: TValue) => boolean): TValue | never;
/**
* Get index of first found item in sequence
* @param predicate predicate for the item
* @return index of item, when not found -1
*/
firstIndex(predicate: (item: TValue) => boolean): number;
/**
* Get last item of iterable
* @param predicate optional predicate for the item
*/
last(predicate?: (item: TValue) => boolean): TValue | undefined;
/**
* Get last item of iterable, if does not contain any return default
* @param def
* @param predicate optional check function
*/
lastOrDefault(def: TValue, predicate?: (item: TValue) => boolean): TValue;
/**
* Get last item of iterable, if no items throw TypeError
* @param predicate optional check function
*/
lastOrThrow(predicate?: (item: TValue) => boolean): TValue | never;
/**
* Get index of last found item in sequence
* @param predicate predicate for the item
* @return index of item, when not found -1
*/
lastIndex(predicate: (item: TValue) => boolean): number;
/**
* Checks if iterable has only one item and returns it.
* @throws TypeError when no or multiple elements
*/
single(predicate?: (item: TValue) => boolean): TValue | never;
/**
* Checks if iterable has only one item and returns it.
* If the iterable does not contain items return default value.
* @throws TypeError when multiple elements
*/
singleOrDefault(def: TValue, predicate?: (item: TValue) => boolean): TValue | never;
/**
* Returns if all items satisfy the predicate. It returns true if no items.
* @param predicate
*/
all(predicate: (item: TValue) => boolean): boolean;
/**
* Returns if all items satisfy the predicate. It returns false if no items.
* @param predicate
*/
allAndEvery(predicate: (item: TValue) => boolean): boolean;
/**
* Returns if any items satisfy the predicate.
* @param predicate
*/
any(predicate?: (item: TValue) => boolean): boolean;
/**
* Return count of items.
* @param predicate if predicate is supplied then return the count of items that return true.
*/
count(predicate?: (item: TValue) => boolean): boolean;
/**
* Produce single value form sequence values. The initial value is first element.
* @param accumulator function which produces the result.
* @throws TypeError when no elements
*/
aggregate<TResult>(accumulator: (result: TResult, item: TValue, index: number) => TResult): TResult | never;
/**
* Produce single value form sequence values. The initial value is the second argument.
* @param accumulator function which produces the result.
* @param initial initial value
*/
aggregate<TResult>(accumulator: (result: TResult, item: TValue, index: number) => TResult, initial: TResult): TResult;
/**
* Produce a sum of sequence values
* @throws {TypeError} if not items in sequence
*/
sum(): TValue | never;
/**
* Produce a product of sequence values
* @throws {TypeError} if not items in sequence
*/
product(): TValue | never;
/**
* Get min value in sequence
* @param comparer optional comparer function, which should return negative when left lower than right, positive when left greater than right or zero when equal
* @throws {TypeError} if not items in sequence
*/
min(comparer?: (left: TValue, right: TValue) => number): TValue | never;
/**
* Get max value in sequence
* @param comparer optional comparer function, which should return negative when left lower than right, positive when left greater than right or zero when equal
* @throws {TypeError} if not items in sequence
*/
max(comparer?: (left: TValue, right: TValue) => number): TValue | never;
/**
* join items of sequence in one string.
* @param separator
*/
join(separator: string): string;
/**
* Return element at specific index
* @param index index of requested element.
* @return undefined when no index out of range.
*/
elementAt(index: number): TValue | undefined;
/**
* do action over every item in the sequence
* @param action
*/
forEach(action: (item: TValue) => void): void;
/**
* Check if current sequence is equal to another sequence.
* @param iterable
*/
isEqual(iterable: Iterable<TValue>): boolean;
isEqual<TAnotherValue>(iterable: Iterable<TAnotherValue>, comparer: (a: TValue, b: TAnotherValue) => boolean): boolean;
/**
* Check if current sequence is equal to another sequence even that positions of elements are different
* @param iterable
* @example from([1, 2, 3]).isElementEqual([3, 1, 2]) === true
*/
isElementsEqual(iterable: Iterable<TValue>): boolean;
isElementsEqual<TAnotherValue>(iterable: Iterable<TAnotherValue>, comparer: (a: TValue, b: TAnotherValue) => boolean): boolean;
}
export interface IGrouping<TKey, TValue> extends LinqIterable<TValue> {
key: TKey;
}
/**
* Creates a select js iterable from iterable (arrays, map, set ...)
* @param iterable
*/
export function fromIterable<TValue>(iterable: Iterable<TValue>): LinqIterable<TValue>;
/**
* Creates a select js iterable from an object resolving keys using Object.keys(). Returns enumerable keys.
* @param value
* @return sequence of key/value object.
*/
export function fromObject<TValue extends {}, TKey extends keyof TValue>(value: TValue): LinqIterable<{ key: string, value: TValue[TKey] }>;
/**
* Creates a select js iterable from an object resolving keys using Object.keys(). Returns enumerable keys.
* @param value
* @return sequence of key/value object.
*/
export function fromObject<TValue extends {}, TKey extends keyof TValue, TResult>(value: TValue, resultCreator: (key: TKey, value: TValue[TKey]) => TResult): LinqIterable<TResult>;
/**
* Creates linq iterable from array like object
* @param arrayLike
*/
export function fromArrayLike<TValue>(arrayLike: ArrayLike<TValue>): LinqIterable<TValue>;
/**
* Creates a select js iterable containing a [from, to) range of numbers
* if from is less than to return ascending range
* if from is greater that to return descending range
* if from === to returns empty iterable
*/
export function range(from: number, to: number): LinqIterable<number>;
/**
* General from function which except various source types
* @param iterable or array like objects
*/
export function from<TValue>(iterable: Iterable<TValue>|ArrayLike<TValue>): LinqIterable<TValue>;
/**
* Alias for fromObject function.
* @param value
*/
export function from<TValue extends {}, TKey extends keyof TValue>(value: TValue): LinqIterable<{ key: string, value: TValue[TKey] }>;
/**
* Creates a select js iterable containing a [from, to) range of numbers
* if from is less than to return ascending range
* if from is greater that to return descending range
* if from === to returns empty iterable
*/
export function repeat<TValue>(value: TValue, times: number): LinqIterable<TValue>;
}