@daiso-tech/core 0.0.1
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/sweet-peas-beg.md +5 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +50 -0
- package/.gitattributes +6 -0
- package/.github/workflows/main.yaml +54 -0
- package/.github/workflows/release.yaml +31 -0
- package/.prettierignore +4 -0
- package/.prettierrc.json +4 -0
- package/.vscode/settings.json +46 -0
- package/LICENSE.md +194 -0
- package/docs-api/.nojekyll +1 -0
- package/docs-api/assets/highlight.css +92 -0
- package/docs-api/assets/icons.js +18 -0
- package/docs-api/assets/icons.svg +1 -0
- package/docs-api/assets/main.js +60 -0
- package/docs-api/assets/navigation.js +1 -0
- package/docs-api/assets/search.js +1 -0
- package/docs-api/assets/style.css +1448 -0
- package/docs-api/classes/AsyncIterableCollection.html +437 -0
- package/docs-api/classes/CollectionError.html +12 -0
- package/docs-api/classes/IndexOverflowError.html +12 -0
- package/docs-api/classes/ItemNotFoundError.html +12 -0
- package/docs-api/classes/IterableCollection.html +434 -0
- package/docs-api/classes/ListCollection.html +434 -0
- package/docs-api/classes/MultipleItemsFoundError.html +12 -0
- package/docs-api/classes/UnexpectedCollectionError.html +12 -0
- package/docs-api/functions/isAsyncIterable.html +1 -0
- package/docs-api/functions/isIterable.html +1 -0
- package/docs-api/functions/range.html +4 -0
- package/docs-api/hierarchy.html +1 -0
- package/docs-api/index.html +1 -0
- package/docs-api/modules.html +60 -0
- package/docs-api/types/AsyncCollapse.html +1 -0
- package/docs-api/types/AsyncFilter.html +1 -0
- package/docs-api/types/AsyncFilter_.html +1 -0
- package/docs-api/types/AsyncFindOrSettings.html +1 -0
- package/docs-api/types/AsyncFindSettings.html +1 -0
- package/docs-api/types/AsyncForEach.html +1 -0
- package/docs-api/types/AsyncForEach_.html +1 -0
- package/docs-api/types/AsyncGroupBySettings.html +1 -0
- package/docs-api/types/AsyncIterableValue.html +1 -0
- package/docs-api/types/AsyncLazyable.html +1 -0
- package/docs-api/types/AsyncLazyable_.html +1 -0
- package/docs-api/types/AsyncMap.html +1 -0
- package/docs-api/types/AsyncMap_.html +1 -0
- package/docs-api/types/AsyncModifier.html +1 -0
- package/docs-api/types/AsyncModifier_.html +1 -0
- package/docs-api/types/AsyncReduce.html +1 -0
- package/docs-api/types/AsyncReduceSettings.html +1 -0
- package/docs-api/types/AsyncReduce_.html +1 -0
- package/docs-api/types/AsyncTap.html +1 -0
- package/docs-api/types/AsyncTap_.html +1 -0
- package/docs-api/types/AsyncTransform.html +1 -0
- package/docs-api/types/AsyncTransform_.html +1 -0
- package/docs-api/types/Collapse.html +1 -0
- package/docs-api/types/Comparator.html +1 -0
- package/docs-api/types/EnsureType.html +1 -0
- package/docs-api/types/Filter.html +1 -0
- package/docs-api/types/FilterGuard.html +1 -0
- package/docs-api/types/Filter_.html +1 -0
- package/docs-api/types/FindOrSettings.html +1 -0
- package/docs-api/types/FindSettings.html +1 -0
- package/docs-api/types/ForEach.html +1 -0
- package/docs-api/types/GroupBySettings.html +1 -0
- package/docs-api/types/IAsyncCollection.html +357 -0
- package/docs-api/types/ICollection.html +357 -0
- package/docs-api/types/JoinSettings.html +1 -0
- package/docs-api/types/Lazyable.html +1 -0
- package/docs-api/types/Map.html +1 -0
- package/docs-api/types/Modifier.html +1 -0
- package/docs-api/types/PageSettings.html +1 -0
- package/docs-api/types/RecordItem.html +1 -0
- package/docs-api/types/Reduce.html +1 -0
- package/docs-api/types/ReduceSettings.html +1 -0
- package/docs-api/types/ReverseSettings.html +1 -0
- package/docs-api/types/SliceSettings.html +1 -0
- package/docs-api/types/SlidingSettings.html +1 -0
- package/docs-api/types/Tap.html +1 -0
- package/docs-api/types/Transform.html +1 -0
- package/docs-api/types/UpdatedItem.html +1 -0
- package/package.json +47 -0
- package/src/_module.ts +2 -0
- package/src/collection/_module.ts +4 -0
- package/src/collection/_shared.ts +45 -0
- package/src/collection/async-iterable-collection/_module.ts +1 -0
- package/src/collection/async-iterable-collection/async-iterable-collection.test.ts +3195 -0
- package/src/collection/async-iterable-collection/async-iterable-collection.ts +1276 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/_module.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.ts +25 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.ts +54 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.ts +58 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.ts +69 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.ts +19 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.ts +28 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.ts +42 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.ts +44 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.ts +48 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.ts +63 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.ts +23 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.ts +55 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.ts +33 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.ts +54 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.ts +18 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.ts +64 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.ts +34 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.ts +20 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.ts +49 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.ts +64 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.ts +43 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.ts +45 -0
- package/src/collection/iterable-collection/_module.ts +1 -0
- package/src/collection/iterable-collection/iterable-collection.test.ts +2379 -0
- package/src/collection/iterable-collection/iterable-collection.ts +1317 -0
- package/src/collection/iterable-collection/iterable-helpers/_module.ts +32 -0
- package/src/collection/iterable-collection/iterable-helpers/chunk-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.ts +51 -0
- package/src/collection/iterable-collection/iterable-helpers/collapse-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/count-by-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/cross-join-iterable.ts +57 -0
- package/src/collection/iterable-collection/iterable-helpers/entries-iterable.ts +42 -0
- package/src/collection/iterable-collection/iterable-helpers/filter-iterable.ts +39 -0
- package/src/collection/iterable-collection/iterable-helpers/flat-map-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/group-by-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/insert-after-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/insert-before-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/map-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/merge-iterable.ts +31 -0
- package/src/collection/iterable-collection/iterable-helpers/pad-end-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/pad-start-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/partion-iterable.ts +46 -0
- package/src/collection/iterable-collection/iterable-helpers/repeat-iterable.ts +36 -0
- package/src/collection/iterable-collection/iterable-helpers/reverse-iterable.ts +46 -0
- package/src/collection/iterable-collection/iterable-helpers/shuffle-iterable.ts +36 -0
- package/src/collection/iterable-collection/iterable-helpers/skip-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/skip-until-iterable.ts +41 -0
- package/src/collection/iterable-collection/iterable-helpers/slice-iterable.ts +47 -0
- package/src/collection/iterable-collection/iterable-helpers/sliding-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/sort-iterable.ts +29 -0
- package/src/collection/iterable-collection/iterable-helpers/split-iterable.ts +58 -0
- package/src/collection/iterable-collection/iterable-helpers/take-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/take-until-iterable.ts +38 -0
- package/src/collection/iterable-collection/iterable-helpers/tap-iterable.ts +31 -0
- package/src/collection/iterable-collection/iterable-helpers/unique-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/update-iterable.ts +50 -0
- package/src/collection/iterable-collection/iterable-helpers/when-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/zip-iterable.ts +41 -0
- package/src/collection/list-collection/_module.ts +1 -0
- package/src/collection/list-collection/list-collection.test.ts +2280 -0
- package/src/collection/list-collection/list-collection.ts +1883 -0
- package/src/contracts/_module.ts +1 -0
- package/src/contracts/collection/_module.ts +3 -0
- package/src/contracts/collection/_shared.ts +346 -0
- package/src/contracts/collection/async-collection.contract.ts +1028 -0
- package/src/contracts/collection/collection.contract.ts +978 -0
- package/src/types.ts +2 -0
- package/tsconfig.base.json +31 -0
- package/tsconfig.cjs.json +12 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +10 -0
- package/tsconfig.types.json +12 -0
- package/vite.config.ts +6 -0
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SliceSettings,
|
|
3
|
+
type SlidingSettings,
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
type CollectionError,
|
|
6
|
+
type Comparator,
|
|
7
|
+
type Filter,
|
|
8
|
+
type FindOrSettings,
|
|
9
|
+
type FindSettings,
|
|
10
|
+
type ForEach,
|
|
11
|
+
type GroupBySettings,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
+
type ItemNotFoundError,
|
|
14
|
+
type JoinSettings,
|
|
15
|
+
type Lazyable,
|
|
16
|
+
type Map,
|
|
17
|
+
type Modifier,
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
type MultipleItemsFoundError,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
type IndexOverflowError,
|
|
22
|
+
type PageSettings,
|
|
23
|
+
type RecordItem,
|
|
24
|
+
type ReduceSettings,
|
|
25
|
+
type ReverseSettings,
|
|
26
|
+
type Tap,
|
|
27
|
+
type Transform,
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
type UnexpectedCollectionError,
|
|
30
|
+
type UpdatedItem,
|
|
31
|
+
} from "@/contracts/collection/_shared";
|
|
32
|
+
import { type EnsureType } from "@/types";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @group Collections
|
|
36
|
+
*/
|
|
37
|
+
export type Collapse<TValue> = TValue extends
|
|
38
|
+
| Array<infer TItem>
|
|
39
|
+
| Iterable<infer TItem>
|
|
40
|
+
| ICollection<infer TItem>
|
|
41
|
+
? TItem
|
|
42
|
+
: TValue;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ICollection is immutable and all the methods return new copies
|
|
46
|
+
* @throws {CollectionError}
|
|
47
|
+
* @throws {UnexpectedCollectionError}
|
|
48
|
+
* @throws {IndexOverflowError}
|
|
49
|
+
* @throws {ItemNotFoundError}
|
|
50
|
+
* @throws {MultipleItemsFoundError}
|
|
51
|
+
* @throws {TypeError}
|
|
52
|
+
* @group Collections
|
|
53
|
+
*/
|
|
54
|
+
export type ICollection<TInput> = Iterable<TInput> & {
|
|
55
|
+
iterator(): Iterator<TInput, void>;
|
|
56
|
+
|
|
57
|
+
entries(
|
|
58
|
+
throwOnNumberLimit?: boolean,
|
|
59
|
+
): ICollection<RecordItem<number, TInput>>;
|
|
60
|
+
|
|
61
|
+
keys(throwOnNumberLimit?: boolean): ICollection<number>;
|
|
62
|
+
|
|
63
|
+
values(): ICollection<TInput>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The filter method filters the collection using the given callback, keeping only those items that pass a given truth test:
|
|
67
|
+
* @example
|
|
68
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6]);
|
|
69
|
+
* const filtered = collection.filter(item => 2 < item && item < 5);
|
|
70
|
+
* filtered.toArray();
|
|
71
|
+
* // [3, 4]
|
|
72
|
+
*/
|
|
73
|
+
filter<TOutput extends TInput>(
|
|
74
|
+
filter: Filter<TInput, ICollection<TInput>, TOutput>,
|
|
75
|
+
throwOnNumberLimit?: boolean,
|
|
76
|
+
): ICollection<TOutput>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The map method iterates through the collection and passes each value to the given callback.
|
|
80
|
+
* The mapFunction is free to modify the item and return it, thus forming a new collection of modified items:
|
|
81
|
+
* @example
|
|
82
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
83
|
+
* const mapped = collection.map(item => item * 2);
|
|
84
|
+
* mapped.toArray();
|
|
85
|
+
* // [2, 4, 6, 8, 10]
|
|
86
|
+
*/
|
|
87
|
+
map<TOutput>(
|
|
88
|
+
map: Map<TInput, ICollection<TInput>, TOutput>,
|
|
89
|
+
throwOnNumberLimit?: boolean,
|
|
90
|
+
): ICollection<TOutput>;
|
|
91
|
+
|
|
92
|
+
reduce<TOutput = TInput>(
|
|
93
|
+
settings: ReduceSettings<TInput, ICollection<TInput>, TOutput>,
|
|
94
|
+
): TOutput;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @throws {TypeError}
|
|
98
|
+
*/
|
|
99
|
+
join(settings?: JoinSettings): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The collapse method collapses a collection of arrays into a single, flat collection:
|
|
103
|
+
* @example
|
|
104
|
+
* const collection = new ListCollection([[1, 2], [3, 4]]);
|
|
105
|
+
* const collapsed = collection.collapse();
|
|
106
|
+
* collapsed.toArray();
|
|
107
|
+
* // [1, 2, 3, 4]
|
|
108
|
+
*/
|
|
109
|
+
collapse(): ICollection<Collapse<TInput>>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The flatMap method returns a new array formed by applying a given callback function to each element of the array, and then collapses the result by one level.
|
|
113
|
+
* It is identical to a map() followed by a collapse()
|
|
114
|
+
* @example
|
|
115
|
+
* const collection = new ListCollection([["a", "b"], ["c", "d"]]).flatMap(item => [item.length, ...item]);
|
|
116
|
+
* collection.toArray();
|
|
117
|
+
* // [2, "a", "b", 2, "c", "d"]
|
|
118
|
+
*/
|
|
119
|
+
flatMap<TOutput>(
|
|
120
|
+
map: Map<TInput, ICollection<TInput>, Iterable<TOutput>>,
|
|
121
|
+
throwOnNumberLimit?: boolean,
|
|
122
|
+
): ICollection<TOutput>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The update method filters the collection using the given callback, keeping only those items that pass a given truth test and thereafter updates the filtered items:
|
|
126
|
+
* @example
|
|
127
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
128
|
+
* const updateCollection = collection.update(item => item % 2 === 0, item => item * 2);
|
|
129
|
+
* updateCollection.toArray();
|
|
130
|
+
* // [1, 4, 3, 8, 5]
|
|
131
|
+
*/
|
|
132
|
+
update<TFilterOutput extends TInput, TMapOutput>(
|
|
133
|
+
filter: Filter<TInput, ICollection<TInput>, TFilterOutput>,
|
|
134
|
+
map: Map<TFilterOutput, ICollection<TInput>, TMapOutput>,
|
|
135
|
+
throwOnNumberLimit?: boolean,
|
|
136
|
+
): ICollection<UpdatedItem<TInput, TFilterOutput, TMapOutput>>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The page method returns a new collection containing the items that would be present on a given page number.
|
|
140
|
+
* The method accepts the page number as its first argument and the number of items to show per page as its second argument:
|
|
141
|
+
* @example
|
|
142
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
143
|
+
* const page = collection.page({
|
|
144
|
+
* page: 2,
|
|
145
|
+
* pageSize: 3
|
|
146
|
+
* });
|
|
147
|
+
* page.toArray();
|
|
148
|
+
* // [4, 5, 6]
|
|
149
|
+
*/
|
|
150
|
+
page(settings: PageSettings): ICollection<TInput>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The sum method returns the sum of all items in the collection. If the collection contains nested arrays or objects,
|
|
154
|
+
* you should pass a map function that returns a number to be used in sum calculation.
|
|
155
|
+
* You can only pass filter to filter out the items you want:
|
|
156
|
+
* @example
|
|
157
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
158
|
+
* collection.sum();
|
|
159
|
+
* // 6
|
|
160
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
161
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
162
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
163
|
+
* @throws {TypeError} {@link TypeError}
|
|
164
|
+
*/
|
|
165
|
+
sum(throwOnNumberLimit?: boolean): EnsureType<TInput, number>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The average method returns the average of all items in the collection. If the collection contains nested arrays or objects,
|
|
169
|
+
* you should pass a map function that returns a number to be used in average calculation.
|
|
170
|
+
* You can only pass filter to filter out the items you want:
|
|
171
|
+
* @example
|
|
172
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
173
|
+
* collection.average();
|
|
174
|
+
* // 2
|
|
175
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
176
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
177
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
178
|
+
* @throws {TypeError} {@link TypeError}
|
|
179
|
+
*/
|
|
180
|
+
average(throwOnNumberLimit?: boolean): EnsureType<TInput, number>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The median method returns the median of all items in the collection. If the collection contains nested arrays or objects,
|
|
184
|
+
* you should pass a map function that returns a number to be used in median calculation.
|
|
185
|
+
* You can only pass filter to filter out the items you want:
|
|
186
|
+
* @example
|
|
187
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
188
|
+
* collection.median();
|
|
189
|
+
* // 2
|
|
190
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
191
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
192
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
193
|
+
* @throws {TypeError} {@link TypeError}
|
|
194
|
+
*/
|
|
195
|
+
median(throwOnNumberLimit?: boolean): EnsureType<TInput, number>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The min method returns the min of all items in the collection. If the collection contains nested arrays or objects,
|
|
199
|
+
* you should pass a map function that returns a number to be used in min calculation.
|
|
200
|
+
* You can only pass filter to filter out the items you want:
|
|
201
|
+
* @example
|
|
202
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
203
|
+
* collection.min();
|
|
204
|
+
* // 1
|
|
205
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
206
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
207
|
+
* @throws {TypeError} {@link TypeError}
|
|
208
|
+
*/
|
|
209
|
+
min(): EnsureType<TInput, number>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The max method returns the max of all items in the collection. If the collection contains nested arrays or objects,
|
|
213
|
+
* you should pass a map function that returns a number to be used in max calculation.
|
|
214
|
+
* You can only pass filter to filter out the items you want:
|
|
215
|
+
* @example
|
|
216
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
217
|
+
* collection.max();
|
|
218
|
+
* // 3
|
|
219
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
220
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
221
|
+
* @throws {TypeError} {@link TypeError}
|
|
222
|
+
*/
|
|
223
|
+
max(): EnsureType<TInput, number>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The percentage method may be used to quickly determine the percentage of items in the collection that pass a given truth test
|
|
227
|
+
* @example
|
|
228
|
+
* const collection = new ListCollection([1, 1, 2, 2, 2, 3]);
|
|
229
|
+
* collection.percentage(value => value === 1);
|
|
230
|
+
* // 33.333
|
|
231
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
232
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
233
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
234
|
+
*/
|
|
235
|
+
percentage(
|
|
236
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
237
|
+
throwOnNumberLimit?: boolean,
|
|
238
|
+
): number;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The some method determines whether the collection has a given item.
|
|
242
|
+
* You must pass a closure to the some method to determine if an element exists in the collection matching a given truth test:
|
|
243
|
+
* @example
|
|
244
|
+
* const collection = new ListCollection([0, 1, 2, 3, 4, 5]);
|
|
245
|
+
* collection.some(item => item === 1);
|
|
246
|
+
* // true
|
|
247
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
248
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
249
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
250
|
+
*/
|
|
251
|
+
some<TOutput extends TInput>(
|
|
252
|
+
filter: Filter<TInput, ICollection<TInput>, TOutput>,
|
|
253
|
+
throwOnNumberLimit?: boolean,
|
|
254
|
+
): boolean;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The every method may be used to verify that all elements of a collection pass a given truth test:
|
|
258
|
+
* @example
|
|
259
|
+
* const collection = new ListCollection([0, 1, 2, 3, 4, 5]);
|
|
260
|
+
* collection.every(item => item < 6);
|
|
261
|
+
* // true
|
|
262
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
263
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
264
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
265
|
+
*/
|
|
266
|
+
every<TOutput extends TInput>(
|
|
267
|
+
filter: Filter<TInput, ICollection<TInput>, TOutput>,
|
|
268
|
+
throwOnNumberLimit?: boolean,
|
|
269
|
+
): boolean;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The take method returns items in the collection until the given callback returns true:
|
|
273
|
+
* @example
|
|
274
|
+
* const collection = new ListCollection([0, 1, 2, 3, 4, 5]);
|
|
275
|
+
* const chunk = collection.take(3);
|
|
276
|
+
* chunk.toArray();
|
|
277
|
+
* // [0, 1, 2]
|
|
278
|
+
* @example
|
|
279
|
+
* const collection = new ListCollection([0, 1, 2, 3, 4, 5]);
|
|
280
|
+
* const chunk = collection.take(-2);
|
|
281
|
+
* chunk.toArray();
|
|
282
|
+
* // [4, 5]
|
|
283
|
+
*/
|
|
284
|
+
take(limit: number, throwOnNumberLimit?: boolean): ICollection<TInput>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The takeUntil method returns items in the collection until the given callback returns true:
|
|
288
|
+
* @example
|
|
289
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
290
|
+
* const chunk = collection.takeUntil(item => item >= 3);
|
|
291
|
+
* chunk.toArray();
|
|
292
|
+
* // [1, 2]
|
|
293
|
+
*/
|
|
294
|
+
takeUntil(
|
|
295
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
296
|
+
throwOnNumberLimit?: boolean,
|
|
297
|
+
): ICollection<TInput>;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The takeWhile method returns items in the collection until the given callback returns false:
|
|
301
|
+
* @example
|
|
302
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
303
|
+
* const chunk = collection.takeWhile(item => item < 3);
|
|
304
|
+
* chunk.toArray();
|
|
305
|
+
* // [1, 2]
|
|
306
|
+
*/
|
|
307
|
+
takeWhile(
|
|
308
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
309
|
+
throwOnNumberLimit?: boolean,
|
|
310
|
+
): ICollection<TInput>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The skip method returns a new collection, with the given number of elements removed from the beginning of the collection:
|
|
314
|
+
* @example
|
|
315
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).skip(4);
|
|
316
|
+
* collection.toArray();
|
|
317
|
+
* // [5, 6, 7, 8, 9, 10]
|
|
318
|
+
*/
|
|
319
|
+
skip(offset: number, throwOnNumberLimit?: boolean): ICollection<TInput>;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The skipUntil method skips over items from the collection until the given callback returns true
|
|
323
|
+
* and then returns the remaining items in the collection as a new collection instance:
|
|
324
|
+
* @example
|
|
325
|
+
* const collection = new ListCollection([1, 2, 3, 4]).skipUntil(item => item >= 3);
|
|
326
|
+
* collection.toArray();
|
|
327
|
+
* // [3, 4]
|
|
328
|
+
*/
|
|
329
|
+
skipUntil(
|
|
330
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
331
|
+
throwOnNumberLimit?: boolean,
|
|
332
|
+
): ICollection<TInput>;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The skipWhile method skips over items from the collection while the given callback returns false and then returns the remaining items in the collection as a new collection:
|
|
336
|
+
* @example
|
|
337
|
+
* const collection = new ListCollection([1, 2, 3, 4]).skipWhile(item => item <= 3);
|
|
338
|
+
* collection.toArray();
|
|
339
|
+
* // [4]
|
|
340
|
+
*/
|
|
341
|
+
skipWhile(
|
|
342
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
343
|
+
throwOnNumberLimit?: boolean,
|
|
344
|
+
): ICollection<TInput>;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The when method will execute the given callback when the first argument given to the method evaluates to true:
|
|
348
|
+
* @example
|
|
349
|
+
* const collection = new ListCollection([1, 2, 3, 4])
|
|
350
|
+
* .when(true, collection => collection.append([-3]))
|
|
351
|
+
* .when(false, collection => collection.append([20]));
|
|
352
|
+
* collection.toArray();
|
|
353
|
+
* // [1, 2, 3, 4, -3]
|
|
354
|
+
*/
|
|
355
|
+
when<TExtended = TInput>(
|
|
356
|
+
condition: boolean,
|
|
357
|
+
callback: Modifier<ICollection<TInput>, ICollection<TExtended>>,
|
|
358
|
+
): ICollection<TInput | TExtended>;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The whenEmpty method will execute the given callback when the collection is empty:
|
|
362
|
+
* @example
|
|
363
|
+
* const collection = new ListCollection([])
|
|
364
|
+
* .whenEmpty(collection => collection.append([-3]))
|
|
365
|
+
* collection.toArray();
|
|
366
|
+
* // [-3]
|
|
367
|
+
* @example
|
|
368
|
+
* const collection = new ListCollection([1])
|
|
369
|
+
* .whenEmpty(collection => collection.append([-3]))
|
|
370
|
+
* collection.toArray();
|
|
371
|
+
* // [1]
|
|
372
|
+
*/
|
|
373
|
+
whenEmpty<TExtended = TInput>(
|
|
374
|
+
callback: Modifier<ICollection<TInput>, ICollection<TExtended>>,
|
|
375
|
+
): ICollection<TInput | TExtended>;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The whenNot method will execute the given callback when the first argument given to the method evaluates to false:
|
|
379
|
+
* @example
|
|
380
|
+
* const collection = new ListCollection([1, 2, 3, 4])
|
|
381
|
+
* .whenNot(true, collection => collection.append([-3]))
|
|
382
|
+
* .whenNot(false, collection => collection.append([20]));
|
|
383
|
+
* collection.toArray();
|
|
384
|
+
* // [1, 2, 3, 4, 20]
|
|
385
|
+
*/
|
|
386
|
+
whenNot<TExtended = TInput>(
|
|
387
|
+
condition: boolean,
|
|
388
|
+
callback: Modifier<ICollection<TInput>, ICollection<TExtended>>,
|
|
389
|
+
): ICollection<TInput | TExtended>;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The whenNotEmpty method will execute the given callback when the collection is empty:
|
|
393
|
+
* @example
|
|
394
|
+
* const collection = new ListCollection([])
|
|
395
|
+
* .whenNotEmpty(collection => collection.append([-3]))
|
|
396
|
+
* collection.toArray();
|
|
397
|
+
* // []
|
|
398
|
+
* @example
|
|
399
|
+
* const collection = new ListCollection([1])
|
|
400
|
+
* .whenNotEmpty(collection => collection.append([-3]))
|
|
401
|
+
* collection.toArray();
|
|
402
|
+
* // [1, -3]
|
|
403
|
+
*/
|
|
404
|
+
whenNotEmpty<TExtended = TInput>(
|
|
405
|
+
callback: Modifier<ICollection<TInput>, ICollection<TExtended>>,
|
|
406
|
+
): ICollection<TInput | TExtended>;
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The pipe method passes the collection to the given closure and returns the result of the executed closure:
|
|
410
|
+
* @example
|
|
411
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
412
|
+
* const piped = collection.pipe(collection => collection.sum());
|
|
413
|
+
* // 6
|
|
414
|
+
*/
|
|
415
|
+
pipe<TOutput = TInput>(
|
|
416
|
+
callback: Transform<ICollection<TInput>, TOutput>,
|
|
417
|
+
): TOutput;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The tap method passes the collection to the given callback, allowing you to "tap" into the collection at a specific point
|
|
421
|
+
* and do something with the items while not affecting the collection itself.The collection is then returned by the tap method:
|
|
422
|
+
* @example
|
|
423
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6])
|
|
424
|
+
* .tap(collection => {
|
|
425
|
+
* collection
|
|
426
|
+
* .filter(value => value % 2 === 0)
|
|
427
|
+
* .forEach(value => console.log(value))
|
|
428
|
+
* })
|
|
429
|
+
* .toArray();
|
|
430
|
+
* // [1, 2, 3, 4, 5, 6]
|
|
431
|
+
*/
|
|
432
|
+
tap(callback: Tap<ICollection<TInput>>): ICollection<TInput>;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The chunk method breaks the collection into multiple, smaller collections of a given size:
|
|
436
|
+
* @example
|
|
437
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6, 7]);
|
|
438
|
+
* const chunks = collection.chunk(4);
|
|
439
|
+
* chunks.toArray();
|
|
440
|
+
* // [[1, 2, 3, 4], [5, 6, 7]]
|
|
441
|
+
*/
|
|
442
|
+
chunk(chunkSize: number): ICollection<ICollection<TInput>>;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The chunkWhile method breaks the collection into multiple, smaller collections based on the evaluation of the given callback.
|
|
446
|
+
* The chunk variable passed to the closure may be used to inspect the previous element:
|
|
447
|
+
* @example
|
|
448
|
+
* const collection = new ListCollection("AABBCCCD");
|
|
449
|
+
* const chunks = collection.chunkWhile((value, index, chunk) => {
|
|
450
|
+
* return value === chunk.last();
|
|
451
|
+
* });
|
|
452
|
+
* chunks.toArray();
|
|
453
|
+
* // [["A", "A"], ["B", "B"], ["C", "C", "C"], ["D"]]
|
|
454
|
+
*/
|
|
455
|
+
chunkWhile(
|
|
456
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
457
|
+
throwOnNumberLimit?: boolean,
|
|
458
|
+
): ICollection<ICollection<TInput>>;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The split method breaks a collection into the given number of groups:
|
|
462
|
+
* @example
|
|
463
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
464
|
+
* const chunks = collection.split(3);
|
|
465
|
+
* chunks.toArray();
|
|
466
|
+
* // [[1, 2], [3, 4], [5]]
|
|
467
|
+
*/
|
|
468
|
+
split(
|
|
469
|
+
chunkAmount: number,
|
|
470
|
+
throwOnNumberLimit?: boolean,
|
|
471
|
+
): ICollection<ICollection<TInput>>;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* The partition method is used to separate elements that pass a given truth test from those that do not:
|
|
475
|
+
* @example
|
|
476
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6]);
|
|
477
|
+
* collection.partition(item => item < 3);
|
|
478
|
+
* // [[1, 2], [3, 4, 5, 6]]
|
|
479
|
+
*/
|
|
480
|
+
partition(
|
|
481
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
482
|
+
throwOnNumberLimit?: boolean,
|
|
483
|
+
): ICollection<ICollection<TInput>>;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* The sliding method returns a new collection of chunks representing a "sliding window" view of the items in the collection:
|
|
487
|
+
* @experimental
|
|
488
|
+
* @example
|
|
489
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]).sliding(2);
|
|
490
|
+
* collection.toArray();
|
|
491
|
+
* // [[1, 2], [2, 3], [3, 4], [4, 5]]
|
|
492
|
+
*/
|
|
493
|
+
sliding(settings: SlidingSettings): ICollection<ICollection<TInput>>;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The groupBy method groups the collection's items by a given map function:
|
|
497
|
+
* @example
|
|
498
|
+
* const collection = new ListCollection(["a", "a", "a", "b", "b", "c"]);
|
|
499
|
+
* const group = collection
|
|
500
|
+
* .groupBy()
|
|
501
|
+
* .map(([key, value]) => [key, value.toArray()]);
|
|
502
|
+
* // [["a", ["a", "a", "a"]], ["b", ["b", "b", "b"]], ["c", ["c"]]]
|
|
503
|
+
* @example
|
|
504
|
+
* const collection = new ListCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
|
|
505
|
+
* const group = collection
|
|
506
|
+
* .groupBy(item => item.split("@")[1])
|
|
507
|
+
* .map(([key, value]) => [key, value.toArray()]);
|
|
508
|
+
* // [["gmail.com", ["alice@gmail.com", "carlos@gmail.com"]], ["yahoo.com", ["bob@yahoo.com"]]]
|
|
509
|
+
*/
|
|
510
|
+
groupBy<TOutput = TInput>(
|
|
511
|
+
settings?: GroupBySettings<TInput, ICollection<TInput>, TOutput>,
|
|
512
|
+
): ICollection<RecordItem<TOutput, ICollection<TInput>>>;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* The countBy method counts the occurrences of values in the collection.
|
|
516
|
+
* By default, the method counts the occurrences of every element, allowing you to count certain "types" of elements in the collection:
|
|
517
|
+
* @example
|
|
518
|
+
* const collection = new ListCollection(["a", "a", "a", "b", "b", "c"]);
|
|
519
|
+
* const count = collection.countBy();
|
|
520
|
+
* // [["a", 3], ["b", 2], ["c", 1]]
|
|
521
|
+
* @example
|
|
522
|
+
* const collection = new ListCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
|
|
523
|
+
* const count = collection.countBy(item => item.split("@")[1])
|
|
524
|
+
* // [["gmail.com", 2], ["yahoo.com", 1]]
|
|
525
|
+
*/
|
|
526
|
+
countBy<TOutput = TInput>(
|
|
527
|
+
settings?: GroupBySettings<TInput, ICollection<TInput>, TOutput>,
|
|
528
|
+
): ICollection<RecordItem<TOutput, number>>;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* The unique method removes all duplicate values from the collection:
|
|
532
|
+
* @example
|
|
533
|
+
* const collection = new ListCollection([1, 1, 2, 2, 3, 4, 2]);
|
|
534
|
+
* collection.unique().toArray();
|
|
535
|
+
* // [1, 2, 3, 4]
|
|
536
|
+
* @example
|
|
537
|
+
* const collection = new ListCollection([
|
|
538
|
+
* { name: "iPhone 6", brand: "Apple", type: "phone" },
|
|
539
|
+
* { name: "iPhone 5", brand: "Apple", type: "phone" },
|
|
540
|
+
* { name: "Apple Watch", brand: "Apple", type: "watch" },
|
|
541
|
+
* { name: "Galaxy S6", brand: "Samsung", type: "phone" },
|
|
542
|
+
* { name: "Galaxy Gear", brand: "Samsung", type: "watch" },
|
|
543
|
+
* ]);
|
|
544
|
+
* const unique = collection.unique(item => item.brand);
|
|
545
|
+
* unique.toArray();
|
|
546
|
+
* // [
|
|
547
|
+
* { name: "iPhone 6", brand: "Apple", type: "phone" },
|
|
548
|
+
* { name: "Galaxy S6", brand: "Samsung", type: "phone" },
|
|
549
|
+
* ]
|
|
550
|
+
*/
|
|
551
|
+
unique<TOutput = TInput>(
|
|
552
|
+
settings?: GroupBySettings<TInput, ICollection<TInput>, TOutput>,
|
|
553
|
+
): ICollection<TInput>;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* The diff method will return the values in the original collection that are not present in the given iterable:
|
|
557
|
+
* @example
|
|
558
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
559
|
+
* const difference = collection.difference([2, 4, 6, 8]);
|
|
560
|
+
* difference.toArray();
|
|
561
|
+
* // [1, 3, 5]
|
|
562
|
+
*/
|
|
563
|
+
difference<TOutput = TInput>(
|
|
564
|
+
iterable: Iterable<TInput>,
|
|
565
|
+
map?: Map<TInput, ICollection<TInput>, TOutput>,
|
|
566
|
+
): ICollection<TInput>;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* The repeat method will repat the current collection given amount
|
|
570
|
+
* @example
|
|
571
|
+
* const collection = new ListCollection([1, 2, 3]);
|
|
572
|
+
* const newCollection = collection.repeat(3);
|
|
573
|
+
* newCollection.toArray();
|
|
574
|
+
* // [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
|
575
|
+
*/
|
|
576
|
+
repeat(amount: number): ICollection<TInput>;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* The padStart method pads this collection with another item (multiple times, if needed) until the resulting collection reaches the given length.
|
|
580
|
+
* The padding is applied from the start of this collection:
|
|
581
|
+
* @example
|
|
582
|
+
* new ListCollection("abc").padStart(10, "foo").join({ seperator: ""});
|
|
583
|
+
* // "foofoofabc"
|
|
584
|
+
*
|
|
585
|
+
* new ListCollection("abc").padStart(6, "123465").join({ seperator: ""});
|
|
586
|
+
* // "123abc"
|
|
587
|
+
*
|
|
588
|
+
* new ListCollection("abc").padStart(8, "0").join({ seperator: ""});
|
|
589
|
+
* // "00000abc"
|
|
590
|
+
*
|
|
591
|
+
* new ListCollection("abc").padStart(1, "_").join({ seperator: ""});
|
|
592
|
+
* // "abc"
|
|
593
|
+
*/
|
|
594
|
+
padStart<TExtended = TInput>(
|
|
595
|
+
maxLength: number,
|
|
596
|
+
fillItems: Iterable<TExtended>,
|
|
597
|
+
): ICollection<TInput | TExtended>;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The padEnd method pads this collection with another item (multiple times, if needed) until the resulting collection reaches the given length.
|
|
601
|
+
* The padding is applied from the end of this collection:
|
|
602
|
+
* @example
|
|
603
|
+
* new ListCollection("abc").padEnd(10, "foo").join({ seperator: ""});
|
|
604
|
+
* // "abcfoofoof"
|
|
605
|
+
*
|
|
606
|
+
* new ListCollection("abc").padEnd(6, "123465").join({ seperator: ""});
|
|
607
|
+
* // "abc123"
|
|
608
|
+
*
|
|
609
|
+
* new ListCollection("abc").padEnd(8, "0").join({ seperator: ""});
|
|
610
|
+
* // "abc00000"
|
|
611
|
+
*
|
|
612
|
+
* new ListCollection("abc").padEnd(1, "_").join({ seperator: ""});
|
|
613
|
+
* // "abc"
|
|
614
|
+
*/
|
|
615
|
+
padEnd<TExtended = TInput>(
|
|
616
|
+
maxLength: number,
|
|
617
|
+
fillItems: Iterable<TExtended>,
|
|
618
|
+
): ICollection<TInput | TExtended>;
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* The slice is the same as Array.slice method. Se documentation on mdn:
|
|
622
|
+
* @link {https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice}
|
|
623
|
+
*/
|
|
624
|
+
slice(settings?: SliceSettings): ICollection<TInput>;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* The prepend method adds items to the beginning of the collection:
|
|
628
|
+
* @example
|
|
629
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]).prepend([-1, 20]);
|
|
630
|
+
* collection.toArray();
|
|
631
|
+
* // [-1, 20, 1, 2, 3, 4, 5]
|
|
632
|
+
*/
|
|
633
|
+
prepend<TExtended = TInput>(
|
|
634
|
+
iterable: Iterable<TInput | TExtended>,
|
|
635
|
+
): ICollection<TInput | TExtended>;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The append method adds items to the end of the collection:
|
|
639
|
+
* @example
|
|
640
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]).append([-1, -2]);
|
|
641
|
+
* collection.toArray();
|
|
642
|
+
* // [1, 2, 3, 4, 5, -1, -2,]
|
|
643
|
+
*/
|
|
644
|
+
append<TExtended = TInput>(
|
|
645
|
+
iterable: Iterable<TInput | TExtended>,
|
|
646
|
+
): ICollection<TInput | TExtended>;
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* The insertBefore method adds items before a specific filtered item:
|
|
650
|
+
* @example
|
|
651
|
+
* const collection = new ListCollection([1, 2, 2, 3, 4, 5]).insertBefore(item => item === 2, [-1, 20]);
|
|
652
|
+
* collection.toArray();
|
|
653
|
+
* // [1, -1, 20, 2, 2, 3, 4, 5]
|
|
654
|
+
*/
|
|
655
|
+
insertBefore<TExtended = TInput>(
|
|
656
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
657
|
+
iterable: Iterable<TInput | TExtended>,
|
|
658
|
+
throwOnNumberLimit?: boolean,
|
|
659
|
+
): ICollection<TInput | TExtended>;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* The insertAfter method adds items after a specific filtered item:
|
|
663
|
+
* @example
|
|
664
|
+
* const collection = new ListCollection([1, 2, 2, 3, 4, 5]).insertAfter(item => item === 2, [-1, 20]);
|
|
665
|
+
* collection.toArray();
|
|
666
|
+
* // [1, 2, -1, 20, 2, 3, 4, 5]
|
|
667
|
+
*/
|
|
668
|
+
insertAfter<TExtended = TInput>(
|
|
669
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
670
|
+
iterable: Iterable<TInput | TExtended>,
|
|
671
|
+
throwOnNumberLimit?: boolean,
|
|
672
|
+
): ICollection<TInput | TExtended>;
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* The crossJoin method cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations:
|
|
676
|
+
* @example
|
|
677
|
+
* const collection = new ListCollection([1, 2]);
|
|
678
|
+
* const matrix = collection.crossJoin(["a", "b"]);
|
|
679
|
+
* matrix.map(collection => collection.toArray()).toArray();
|
|
680
|
+
* // [
|
|
681
|
+
* // [1, "a"],
|
|
682
|
+
* // [1, "b"],
|
|
683
|
+
* // [2, "a"],
|
|
684
|
+
* // [2, "b"],
|
|
685
|
+
* // ]
|
|
686
|
+
* @example
|
|
687
|
+
* const collection = new ListCollection([1, 2]);
|
|
688
|
+
* const matrix = collection.crossJoin(["a", "b"], ["I", "II"]);
|
|
689
|
+
* matrix.map(collection => collection.toArray()).toArray();
|
|
690
|
+
* // [
|
|
691
|
+
* // [1, "a", "I"],
|
|
692
|
+
* // [1, "a", "II"],
|
|
693
|
+
* // [1, "b", "I"],
|
|
694
|
+
* // [1, "b", "II"],
|
|
695
|
+
* // [2, "a", "I"],
|
|
696
|
+
* // [2, "a", "II"],
|
|
697
|
+
* // [2, "b", "I"],
|
|
698
|
+
* // [2, "b", "II"],
|
|
699
|
+
* // ]
|
|
700
|
+
*/
|
|
701
|
+
crossJoin<TExtended = TInput>(
|
|
702
|
+
...iterables: Array<Iterable<TExtended>>
|
|
703
|
+
): ICollection<ICollection<TInput | TExtended>>;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* The zip method merges together the values of the given array with the values of the original collection at their corresponding index:
|
|
707
|
+
* @example
|
|
708
|
+
* const collection = new ListCollection(["Chair", "Desk"]);
|
|
709
|
+
* const zipped = collection.zip([100, 200]);
|
|
710
|
+
* zipped.toArray();
|
|
711
|
+
* // [["Chari", 100], ["Desk", 200]]
|
|
712
|
+
*/
|
|
713
|
+
zip<TExtended>(
|
|
714
|
+
iterable: Iterable<TExtended>,
|
|
715
|
+
): ICollection<RecordItem<TInput, TExtended>>;
|
|
716
|
+
|
|
717
|
+
sort(compare?: Comparator<TInput>): ICollection<TInput>;
|
|
718
|
+
|
|
719
|
+
reverse(settings?: ReverseSettings): ICollection<TInput>;
|
|
720
|
+
|
|
721
|
+
shuffle(): ICollection<TInput>;
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* The first method returns the first element in the collection that passes a given truth test. By default it will get the first element:
|
|
725
|
+
* @example
|
|
726
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
727
|
+
* collection.first({ filter: item => item > 2 });
|
|
728
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
729
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
730
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
731
|
+
* // 3
|
|
732
|
+
*/
|
|
733
|
+
first<TOutput extends TInput>(
|
|
734
|
+
settings?: FindSettings<TInput, ICollection<TInput>, TOutput>,
|
|
735
|
+
): TOutput | null;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* The firstOr method is the same as first method but will return a provided default value if not found
|
|
739
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
740
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
741
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
742
|
+
*/
|
|
743
|
+
firstOr<TOutput extends TInput, TExtended = TInput>(
|
|
744
|
+
settings: FindOrSettings<
|
|
745
|
+
TInput,
|
|
746
|
+
ICollection<TInput>,
|
|
747
|
+
TOutput,
|
|
748
|
+
TExtended
|
|
749
|
+
>,
|
|
750
|
+
): TOutput | TExtended;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* The firstOrFail method is the same as first method but will throw an Error if not found
|
|
754
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
755
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
756
|
+
* @throws {ItemNotFoundError} {@link ItemNotFoundError}
|
|
757
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
758
|
+
*/
|
|
759
|
+
firstOrFail<TOutput extends TInput>(
|
|
760
|
+
settings?: FindSettings<TInput, ICollection<TInput>, TOutput>,
|
|
761
|
+
): TOutput;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* The last method returns the last element in the collection that passes a given truth test. By default it will get the last element:
|
|
765
|
+
* @example
|
|
766
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
767
|
+
* collection.last({ filter: item => item > 2 });
|
|
768
|
+
* // 4
|
|
769
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
770
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
771
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
772
|
+
*/
|
|
773
|
+
last<TOutput extends TInput>(
|
|
774
|
+
settings?: FindSettings<TInput, ICollection<TInput>, TOutput>,
|
|
775
|
+
): TOutput | null;
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* The lastOr method is the same as last method but will return a provided default value if not found
|
|
779
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
780
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
781
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
782
|
+
*/
|
|
783
|
+
lastOr<TOutput extends TInput, TExtended = TInput>(
|
|
784
|
+
settings: FindOrSettings<
|
|
785
|
+
TInput,
|
|
786
|
+
ICollection<TInput>,
|
|
787
|
+
TOutput,
|
|
788
|
+
TExtended
|
|
789
|
+
>,
|
|
790
|
+
): TOutput | TExtended;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The lastOrFail method is the same as last method but will throw an Error if not found
|
|
794
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
795
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
796
|
+
* @throws {ItemNotFoundError} {@link ItemNotFoundError}
|
|
797
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
798
|
+
*/
|
|
799
|
+
lastOrFail<TOutput extends TInput>(
|
|
800
|
+
settings?: FindSettings<TInput, ICollection<TInput>, TOutput>,
|
|
801
|
+
): TOutput;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The before method is the opposite of the after method. It returns the item before the given item. null is returned if the given item is not found or is the first item:
|
|
805
|
+
* @example
|
|
806
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
807
|
+
* collection.before(item => item === 2);
|
|
808
|
+
* // 1
|
|
809
|
+
* @example
|
|
810
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
811
|
+
* collection.before(item => item === 1);
|
|
812
|
+
* // null
|
|
813
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
814
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
815
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
816
|
+
*/
|
|
817
|
+
before(
|
|
818
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
819
|
+
throwOnNumberLimit?: boolean,
|
|
820
|
+
): TInput | null;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* The beforeOr method is the same as before method but will return a provided default value if not found
|
|
824
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
825
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
826
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
827
|
+
*/
|
|
828
|
+
beforeOr<TExtended = TInput>(
|
|
829
|
+
defaultValue: Lazyable<TExtended>,
|
|
830
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
831
|
+
throwOnNumberLimit?: boolean,
|
|
832
|
+
): TInput | TExtended;
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* The beforeOrFail method is the same as before method but will throw an Error if not found
|
|
836
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
837
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
838
|
+
* @throws {ItemNotFoundError} {@link ItemNotFoundError}
|
|
839
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
840
|
+
*/
|
|
841
|
+
beforeOrFail(
|
|
842
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
843
|
+
throwOnNumberLimit?: boolean,
|
|
844
|
+
): TInput;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* The after method returns the item after the given item. null is returned if the given item is not found or is the last item:
|
|
848
|
+
* @example
|
|
849
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
850
|
+
* collection.after(item => item === 2);
|
|
851
|
+
* // 3
|
|
852
|
+
* @example
|
|
853
|
+
* const collection = new ListCollection([1, 2, 3, 4]);
|
|
854
|
+
* collection.after(item => item === 4);
|
|
855
|
+
* // null
|
|
856
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
857
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
858
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
859
|
+
*/
|
|
860
|
+
after(
|
|
861
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
862
|
+
throwOnNumberLimit?: boolean,
|
|
863
|
+
): TInput | null;
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* The afterOr method is the same as after method but will return a provided default value if not found
|
|
867
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
868
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
869
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
870
|
+
*/
|
|
871
|
+
afterOr<TExtended = TInput>(
|
|
872
|
+
defaultValue: Lazyable<TExtended>,
|
|
873
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
874
|
+
throwOnNumberLimit?: boolean,
|
|
875
|
+
): TInput | TExtended;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* The afterOrFail method is the same as after method but will throw an Error if not found
|
|
879
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
880
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
881
|
+
* @throws {ItemNotFoundError} {@link ItemNotFoundError}
|
|
882
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
883
|
+
*/
|
|
884
|
+
afterOrFail(
|
|
885
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
886
|
+
throwOnNumberLimit?: boolean,
|
|
887
|
+
): TInput;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* The sole method returns the first element in the collection that passes a given truth test, but only if the truth test matches exactly one element:
|
|
891
|
+
* @example
|
|
892
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
893
|
+
* collection.sole(item => item === 4);
|
|
894
|
+
* // 4
|
|
895
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
896
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
897
|
+
* @throws {ItemNotFoundError} {@link ItemNotFoundError}
|
|
898
|
+
* @throws {MultipleItemsFoundError} {@link MultipleItemsFoundError}
|
|
899
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
900
|
+
*/
|
|
901
|
+
sole<TOutput extends TInput>(
|
|
902
|
+
filter: Filter<TInput, ICollection<TInput>, TOutput>,
|
|
903
|
+
throwOnNumberLimit?: boolean,
|
|
904
|
+
): TOutput;
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* The nth method creates a new collection consisting of every n-th element:
|
|
908
|
+
* @example
|
|
909
|
+
* const collection = new ListCollection(["a", "b", "c", "d", "e", "f"]).nth(4);
|
|
910
|
+
* collection.toArray();
|
|
911
|
+
* // ["a", "e"]
|
|
912
|
+
*/
|
|
913
|
+
nth(step: number): ICollection<TInput>;
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* The count method returns the total number of items in the collection:
|
|
917
|
+
* @example
|
|
918
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5, 6]);
|
|
919
|
+
* collection.count(value => value % 2 === 0);
|
|
920
|
+
* // 3
|
|
921
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
922
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
923
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
924
|
+
*/
|
|
925
|
+
count(
|
|
926
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
927
|
+
throwOnNumberLimit?: boolean,
|
|
928
|
+
): number;
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
932
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
933
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
934
|
+
*/
|
|
935
|
+
size(throwOnNumberLimit?: boolean): number;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
939
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
940
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
941
|
+
*/
|
|
942
|
+
empty(): boolean;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
946
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
947
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
948
|
+
*/
|
|
949
|
+
notEmpty(): boolean;
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* The search method searches the collection for the given value and returns its index if found. If the item is not found, -1 is returned:
|
|
953
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
954
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
955
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
956
|
+
*/
|
|
957
|
+
search(
|
|
958
|
+
filter: Filter<TInput, ICollection<TInput>>,
|
|
959
|
+
throwOnNumberLimit?: boolean,
|
|
960
|
+
): number;
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
964
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
965
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
966
|
+
*/
|
|
967
|
+
forEach(
|
|
968
|
+
callback: ForEach<TInput, ICollection<TInput>>,
|
|
969
|
+
throwOnNumberLimit?: boolean,
|
|
970
|
+
): void;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* @throws {CollectionError} {@link CollectionError}
|
|
974
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
975
|
+
* @throws {IndexOverflowError} {@link IndexOverflowError}
|
|
976
|
+
*/
|
|
977
|
+
toArray(): TInput[];
|
|
978
|
+
};
|