@develia/commons 0.4.14 → 0.4.15

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.
Files changed (220) hide show
  1. package/dist/cjs/array.js +27 -1
  2. package/dist/cjs/array.js.map +1 -1
  3. package/dist/cjs/async-pool-executor.js +15 -0
  4. package/dist/cjs/async-pool-executor.js.map +1 -1
  5. package/dist/cjs/browser/form-utilities.js +26 -0
  6. package/dist/cjs/browser/form-utilities.js.map +1 -1
  7. package/dist/cjs/browser/geo-location.js +5 -0
  8. package/dist/cjs/browser/geo-location.js.map +1 -1
  9. package/dist/cjs/browser/index.js.map +1 -1
  10. package/dist/cjs/browser/native-bridge.js +9 -0
  11. package/dist/cjs/browser/native-bridge.js.map +1 -1
  12. package/dist/cjs/cancellable-promise.js.map +1 -1
  13. package/dist/cjs/clean-url-search-params.js +1 -0
  14. package/dist/cjs/clean-url-search-params.js.map +1 -1
  15. package/dist/cjs/collections/cache-dictionary.js +39 -0
  16. package/dist/cjs/collections/cache-dictionary.js.map +1 -1
  17. package/dist/cjs/collections/default-map.js +25 -1
  18. package/dist/cjs/collections/default-map.js.map +1 -1
  19. package/dist/cjs/collections/default-weak-map.js +23 -3
  20. package/dist/cjs/collections/default-weak-map.js.map +1 -1
  21. package/dist/cjs/{from.js → collections/from.js} +278 -4
  22. package/dist/cjs/collections/from.js.map +1 -0
  23. package/dist/cjs/collections/index.js +3 -1
  24. package/dist/cjs/collections/index.js.map +1 -1
  25. package/dist/cjs/draft.js +37 -0
  26. package/dist/cjs/draft.js.map +1 -1
  27. package/dist/cjs/event-bus.js +1 -0
  28. package/dist/cjs/event-bus.js.map +1 -1
  29. package/dist/cjs/index.js +14 -3
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/key-value-pair.js +6 -0
  32. package/dist/cjs/key-value-pair.js.map +1 -1
  33. package/dist/cjs/lazy.js +4 -0
  34. package/dist/cjs/lazy.js.map +1 -1
  35. package/dist/cjs/math.js +19 -0
  36. package/dist/cjs/math.js.map +1 -1
  37. package/dist/cjs/order.js.map +1 -1
  38. package/dist/cjs/parse.js +96 -0
  39. package/dist/cjs/parse.js.map +1 -1
  40. package/dist/cjs/patch.js +10 -2
  41. package/dist/cjs/patch.js.map +1 -1
  42. package/dist/cjs/stopwatch.js +10 -0
  43. package/dist/cjs/stopwatch.js.map +1 -1
  44. package/dist/cjs/string.js +62 -0
  45. package/dist/cjs/string.js.map +1 -1
  46. package/dist/cjs/timer.js +7 -0
  47. package/dist/cjs/timer.js.map +1 -1
  48. package/dist/cjs/timespan.js +202 -0
  49. package/dist/cjs/timespan.js.map +1 -1
  50. package/dist/cjs/type-code.js.map +1 -1
  51. package/dist/cjs/type.js +80 -1
  52. package/dist/cjs/type.js.map +1 -1
  53. package/dist/cjs/types.js.map +1 -1
  54. package/dist/cjs/utilities.js +183 -0
  55. package/dist/cjs/utilities.js.map +1 -1
  56. package/dist/esm/array.js +27 -1
  57. package/dist/esm/array.js.map +1 -1
  58. package/dist/esm/async-pool-executor.js +15 -0
  59. package/dist/esm/async-pool-executor.js.map +1 -1
  60. package/dist/esm/browser/form-utilities.js +26 -0
  61. package/dist/esm/browser/form-utilities.js.map +1 -1
  62. package/dist/esm/browser/geo-location.js +5 -0
  63. package/dist/esm/browser/geo-location.js.map +1 -1
  64. package/dist/esm/browser/index.js.map +1 -1
  65. package/dist/esm/browser/native-bridge.js +9 -0
  66. package/dist/esm/browser/native-bridge.js.map +1 -1
  67. package/dist/esm/cancellable-promise.js.map +1 -1
  68. package/dist/esm/clean-url-search-params.js +1 -0
  69. package/dist/esm/clean-url-search-params.js.map +1 -1
  70. package/dist/esm/collections/cache-dictionary.js +39 -0
  71. package/dist/esm/collections/cache-dictionary.js.map +1 -1
  72. package/dist/esm/collections/default-map.js +25 -1
  73. package/dist/esm/collections/default-map.js.map +1 -1
  74. package/dist/esm/collections/default-weak-map.js +22 -2
  75. package/dist/esm/collections/default-weak-map.js.map +1 -1
  76. package/dist/esm/{from.js → collections/from.js} +278 -4
  77. package/dist/esm/collections/from.js.map +1 -0
  78. package/dist/esm/collections/index.js +1 -0
  79. package/dist/esm/collections/index.js.map +1 -1
  80. package/dist/esm/draft.js +37 -0
  81. package/dist/esm/draft.js.map +1 -1
  82. package/dist/esm/event-bus.js +1 -0
  83. package/dist/esm/event-bus.js.map +1 -1
  84. package/dist/esm/index.js +13 -1
  85. package/dist/esm/index.js.map +1 -1
  86. package/dist/esm/key-value-pair.js +6 -0
  87. package/dist/esm/key-value-pair.js.map +1 -1
  88. package/dist/esm/lazy.js +4 -0
  89. package/dist/esm/lazy.js.map +1 -1
  90. package/dist/esm/math.js +19 -0
  91. package/dist/esm/math.js.map +1 -1
  92. package/dist/esm/order.js.map +1 -1
  93. package/dist/esm/parse.js +96 -0
  94. package/dist/esm/parse.js.map +1 -1
  95. package/dist/esm/patch.js +10 -2
  96. package/dist/esm/patch.js.map +1 -1
  97. package/dist/esm/stopwatch.js +10 -0
  98. package/dist/esm/stopwatch.js.map +1 -1
  99. package/dist/esm/string.js +62 -0
  100. package/dist/esm/string.js.map +1 -1
  101. package/dist/esm/timer.js +7 -0
  102. package/dist/esm/timer.js.map +1 -1
  103. package/dist/esm/timespan.js +202 -0
  104. package/dist/esm/timespan.js.map +1 -1
  105. package/dist/esm/type-code.js.map +1 -1
  106. package/dist/esm/type.js +80 -1
  107. package/dist/esm/type.js.map +1 -1
  108. package/dist/esm/types.js.map +1 -1
  109. package/dist/esm/utilities.js +183 -0
  110. package/dist/esm/utilities.js.map +1 -1
  111. package/dist/types/array.d.ts +26 -0
  112. package/dist/types/array.d.ts.map +1 -1
  113. package/dist/types/async-pool-executor.d.ts +15 -0
  114. package/dist/types/async-pool-executor.d.ts.map +1 -1
  115. package/dist/types/browser/form-utilities.d.ts +13 -0
  116. package/dist/types/browser/form-utilities.d.ts.map +1 -1
  117. package/dist/types/browser/index.d.ts.map +1 -1
  118. package/dist/types/browser/native-bridge.d.ts +6 -0
  119. package/dist/types/browser/native-bridge.d.ts.map +1 -1
  120. package/dist/types/collections/cache-dictionary.d.ts +39 -0
  121. package/dist/types/collections/cache-dictionary.d.ts.map +1 -1
  122. package/dist/types/collections/default-map.d.ts +23 -0
  123. package/dist/types/collections/default-map.d.ts.map +1 -1
  124. package/dist/types/collections/default-weak-map.d.ts +20 -1
  125. package/dist/types/collections/default-weak-map.d.ts.map +1 -1
  126. package/dist/types/collections/from.d.ts +333 -0
  127. package/dist/types/collections/from.d.ts.map +1 -0
  128. package/dist/types/collections/index.d.ts +1 -0
  129. package/dist/types/collections/index.d.ts.map +1 -1
  130. package/dist/types/draft.d.ts +68 -0
  131. package/dist/types/draft.d.ts.map +1 -1
  132. package/dist/types/index.d.ts +4 -1
  133. package/dist/types/index.d.ts.map +1 -1
  134. package/dist/types/key-value-pair.d.ts +6 -0
  135. package/dist/types/key-value-pair.d.ts.map +1 -1
  136. package/dist/types/lazy.d.ts +4 -0
  137. package/dist/types/lazy.d.ts.map +1 -1
  138. package/dist/types/math.d.ts +19 -0
  139. package/dist/types/math.d.ts.map +1 -1
  140. package/dist/types/parse.d.ts +121 -0
  141. package/dist/types/parse.d.ts.map +1 -1
  142. package/dist/types/string.d.ts +51 -0
  143. package/dist/types/string.d.ts.map +1 -1
  144. package/dist/types/timer.d.ts +7 -0
  145. package/dist/types/timer.d.ts.map +1 -1
  146. package/dist/types/timespan.d.ts +202 -0
  147. package/dist/types/timespan.d.ts.map +1 -1
  148. package/dist/types/type.d.ts +40 -0
  149. package/dist/types/type.d.ts.map +1 -1
  150. package/dist/types/utilities.d.ts +171 -0
  151. package/dist/types/utilities.d.ts.map +1 -1
  152. package/dist/web/array.js +27 -1
  153. package/dist/web/array.js.map +1 -1
  154. package/dist/web/async-pool-executor.js +15 -0
  155. package/dist/web/async-pool-executor.js.map +1 -1
  156. package/dist/web/browser/form-utilities.js +26 -0
  157. package/dist/web/browser/form-utilities.js.map +1 -1
  158. package/dist/web/browser/geo-location.js +5 -0
  159. package/dist/web/browser/geo-location.js.map +1 -1
  160. package/dist/web/browser/index.js.map +1 -1
  161. package/dist/web/browser/native-bridge.js +9 -0
  162. package/dist/web/browser/native-bridge.js.map +1 -1
  163. package/dist/web/cancellable-promise.js.map +1 -1
  164. package/dist/web/clean-url-search-params.js +1 -0
  165. package/dist/web/clean-url-search-params.js.map +1 -1
  166. package/dist/web/collections/cache-dictionary.js +39 -0
  167. package/dist/web/collections/cache-dictionary.js.map +1 -1
  168. package/dist/web/collections/default-map.js +25 -1
  169. package/dist/web/collections/default-map.js.map +1 -1
  170. package/dist/web/collections/default-weak-map.js +22 -2
  171. package/dist/web/collections/default-weak-map.js.map +1 -1
  172. package/dist/web/{from.js → collections/from.js} +279 -5
  173. package/dist/web/collections/from.js.map +1 -0
  174. package/dist/web/collections/index.js +1 -0
  175. package/dist/web/collections/index.js.map +1 -1
  176. package/dist/web/draft.js +37 -0
  177. package/dist/web/draft.js.map +1 -1
  178. package/dist/web/event-bus.js +1 -0
  179. package/dist/web/event-bus.js.map +1 -1
  180. package/dist/web/index.js +13 -1
  181. package/dist/web/index.js.map +1 -1
  182. package/dist/web/key-value-pair.js +6 -0
  183. package/dist/web/key-value-pair.js.map +1 -1
  184. package/dist/web/lazy.js +4 -0
  185. package/dist/web/lazy.js.map +1 -1
  186. package/dist/web/math.js +19 -0
  187. package/dist/web/math.js.map +1 -1
  188. package/dist/web/order.js.map +1 -1
  189. package/dist/web/parse.js +96 -0
  190. package/dist/web/parse.js.map +1 -1
  191. package/dist/web/patch.js +10 -2
  192. package/dist/web/patch.js.map +1 -1
  193. package/dist/web/stopwatch.js +10 -0
  194. package/dist/web/stopwatch.js.map +1 -1
  195. package/dist/web/string.js +62 -0
  196. package/dist/web/string.js.map +1 -1
  197. package/dist/web/timer.js +7 -0
  198. package/dist/web/timer.js.map +1 -1
  199. package/dist/web/timespan.js +202 -0
  200. package/dist/web/timespan.js.map +1 -1
  201. package/dist/web/type-code.js.map +1 -1
  202. package/dist/web/type.js +80 -1
  203. package/dist/web/type.js.map +1 -1
  204. package/dist/web/types.js.map +1 -1
  205. package/dist/web/utilities.js +183 -0
  206. package/dist/web/utilities.js.map +1 -1
  207. package/package.json +1 -1
  208. package/src/browser/index.ts +2 -2
  209. package/src/collections/cache-dictionary.ts +39 -1
  210. package/src/collections/default-map.ts +15 -9
  211. package/src/collections/default-weak-map.ts +14 -12
  212. package/src/{from.ts → collections/from.ts} +285 -15
  213. package/src/collections/index.ts +4 -3
  214. package/src/index.ts +1 -1
  215. package/src/timespan.ts +199 -20
  216. package/dist/cjs/from.js.map +0 -1
  217. package/dist/esm/from.js.map +0 -1
  218. package/dist/types/from.d.ts +0 -59
  219. package/dist/types/from.d.ts.map +0 -1
  220. package/dist/web/from.js.map +0 -1
@@ -1,5 +1,12 @@
1
- import { shallowEqual, toPairs } from "./utilities.js";
2
- import Order from "./order.js";
1
+ import { shallowEqual, toPairs } from "../utilities.js";
2
+ import Order from "../order.js";
3
+ /**
4
+ * Creates a new From instance from an Iterable or a Supplier of an Iterable.
5
+ * @template T - The type of elements in the source.
6
+ * @param {Iterable<T> | Supplier<Iterable<T>>} source - The source data.
7
+ * @returns {From<T> | From<KeyValuePair<any, any>>} A new From instance.
8
+ * @throws {string} If source is null or invalid.
9
+ */
3
10
  export default function from(source) {
4
11
  if (source == null)
5
12
  throw "Source is null.";
@@ -13,7 +20,16 @@ export default function from(source) {
13
20
  }
14
21
  throw "Invalid source.";
15
22
  }
23
+ /**
24
+ * A LINQ-like wrapper for iterables that provides various transformation and query methods.
25
+ * @template T - The type of elements in the sequence.
26
+ */
16
27
  export class From {
28
+ /**
29
+ * Creates a From instance from an object's entries.
30
+ * @param {any} obj - The object to convert to pairs.
31
+ * @returns {From<KeyValuePair<any, any>>} A From instance of key-value pairs.
32
+ */
17
33
  static object(obj) {
18
34
  return new From(function () {
19
35
  return toPairs(obj);
@@ -22,14 +38,30 @@ export class From {
22
38
  constructor(fn) {
23
39
  this._fn = fn;
24
40
  }
41
+ /**
42
+ * Creates a From instance from a supplier function.
43
+ * @template T
44
+ * @param {Supplier<Iterable<T>>} callable - A function that returns an Iterable.
45
+ * @returns {From<T>} A new From instance.
46
+ */
25
47
  static fn(callable) {
26
48
  return new From(callable);
27
49
  }
28
- ;
50
+ /**
51
+ * Collects all elements into an array and returns a new From instance from it.
52
+ * Useful for freezing the sequence and preventing multiple iterations over a generator.
53
+ * @returns {From<T>} A new From instance with cached data.
54
+ */
29
55
  collect() {
30
56
  const cache = Array.from(this);
31
57
  return From.iterable(cache);
32
58
  }
59
+ /**
60
+ * Creates a From instance from an Iterable.
61
+ * @template T
62
+ * @param {Iterable<T>} iterable - The source iterable.
63
+ * @returns {From<T>} A new From instance.
64
+ */
33
65
  static iterable(iterable) {
34
66
  return From.fn(function* () {
35
67
  for (const item of iterable) {
@@ -37,7 +69,12 @@ export class From {
37
69
  }
38
70
  });
39
71
  }
40
- ;
72
+ /**
73
+ * Maps each element of the sequence into a new form.
74
+ * @template R
75
+ * @param {UnaryFunction<T, R>} mapper - A transformation function.
76
+ * @returns {From<R>} A new From instance with the mapped elements.
77
+ */
41
78
  map(mapper) {
42
79
  const self = this;
43
80
  return From.fn(function* () {
@@ -49,6 +86,11 @@ export class From {
49
86
  *[Symbol.iterator]() {
50
87
  yield* this._fn();
51
88
  }
89
+ /**
90
+ * Checks if all elements in the sequence satisfy the given predicate.
91
+ * @param {Predicate<T>} predicate - A function to test each element.
92
+ * @returns {boolean} True if all elements satisfy the predicate.
93
+ */
52
94
  all(predicate) {
53
95
  for (let item of this._fn()) {
54
96
  if (!predicate(item)) {
@@ -57,6 +99,12 @@ export class From {
57
99
  }
58
100
  return true;
59
101
  }
102
+ /**
103
+ * Checks if any element in the sequence satisfies the given predicate.
104
+ * If no predicate is provided, checks if the sequence is not empty.
105
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
106
+ * @returns {boolean} True if any element satisfies the predicate.
107
+ */
60
108
  any(predicate = undefined) {
61
109
  for (let item of this) {
62
110
  if (predicate == null || predicate(item)) {
@@ -65,9 +113,19 @@ export class From {
65
113
  }
66
114
  return false;
67
115
  }
116
+ /**
117
+ * Gets the number of elements in the sequence.
118
+ * @returns {number} The count of elements.
119
+ */
68
120
  get length() {
69
121
  return this.count();
70
122
  }
123
+ /**
124
+ * Counts the number of elements that satisfy the given predicate.
125
+ * If no predicate is provided, counts all elements.
126
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
127
+ * @returns {number} The count of elements.
128
+ */
71
129
  count(predicate = undefined) {
72
130
  let output = 0;
73
131
  for (let item of this) {
@@ -77,6 +135,11 @@ export class From {
77
135
  }
78
136
  return output;
79
137
  }
138
+ /**
139
+ * Filters the sequence based on a predicate.
140
+ * @param {Predicate<T>} predicate - A function to test each element.
141
+ * @returns {From<T>} A new From instance with the filtered elements.
142
+ */
80
143
  filter(predicate) {
81
144
  const self = this;
82
145
  return From.fn(function* () {
@@ -87,6 +150,11 @@ export class From {
87
150
  }
88
151
  });
89
152
  }
153
+ /**
154
+ * Checks if the sequence contains a specific value.
155
+ * @param {T} value - The value to search for.
156
+ * @returns {boolean} True if the value is found.
157
+ */
90
158
  contains(value) {
91
159
  for (let item of this) {
92
160
  if (item === value) {
@@ -95,6 +163,11 @@ export class From {
95
163
  }
96
164
  return false;
97
165
  }
166
+ /**
167
+ * Returns the first element of the sequence that satisfies a condition.
168
+ * @param {Predicate<T>} [predicate] - Optional condition.
169
+ * @returns {T | undefined} The first element or undefined.
170
+ */
98
171
  first(predicate) {
99
172
  if (predicate) {
100
173
  for (let item of this) {
@@ -104,12 +177,19 @@ export class From {
104
177
  }
105
178
  }
106
179
  else {
180
+ // noinspection LoopStatementThatDoesntLoopJS
107
181
  for (let item of this) {
108
182
  return item;
109
183
  }
110
184
  }
111
185
  return undefined;
112
186
  }
187
+ /**
188
+ * Returns the only element of the sequence that satisfies a condition, or throws if more than one exists.
189
+ * @param {Predicate<T>} [predicate] - Optional condition.
190
+ * @returns {T | null} The single element or null if not found.
191
+ * @throws {Error} If more than one element is found.
192
+ */
113
193
  single(predicate) {
114
194
  let found = false;
115
195
  let output = null;
@@ -125,6 +205,7 @@ export class From {
125
205
  }
126
206
  }
127
207
  else {
208
+ // noinspection LoopStatementThatDoesntLoopJS
128
209
  for (let item of this) {
129
210
  if (found) {
130
211
  throw new Error("Sequence contains more than one element.");
@@ -135,6 +216,11 @@ export class From {
135
216
  }
136
217
  return output;
137
218
  }
219
+ /**
220
+ * Appends an item to the end of the sequence.
221
+ * @param {T} item - The item to append.
222
+ * @returns {From<T>} A new From instance.
223
+ */
138
224
  append(item) {
139
225
  const self = this;
140
226
  return From.fn(function* () {
@@ -144,6 +230,11 @@ export class From {
144
230
  yield item;
145
231
  });
146
232
  }
233
+ /**
234
+ * Prepends an item to the beginning of the sequence.
235
+ * @param {T} item - The item to prepend.
236
+ * @returns {From<T>} A new From instance.
237
+ */
147
238
  prepend(item) {
148
239
  const self = this;
149
240
  return From.fn(function* () {
@@ -153,6 +244,11 @@ export class From {
153
244
  }
154
245
  });
155
246
  }
247
+ /**
248
+ * Gets the element at a specific index.
249
+ * @param {number} index - The zero-based index.
250
+ * @returns {T | undefined} The element at the index or undefined.
251
+ */
156
252
  at(index) {
157
253
  let idx = 0;
158
254
  for (let item of this) {
@@ -162,6 +258,11 @@ export class From {
162
258
  }
163
259
  return undefined;
164
260
  }
261
+ /**
262
+ * Returns the last element of the sequence that satisfies a condition.
263
+ * @param {Predicate<T>} [predicate] - Optional condition.
264
+ * @returns {T | undefined} The last element or undefined.
265
+ */
165
266
  last(predicate) {
166
267
  let last = undefined;
167
268
  if (predicate)
@@ -177,6 +278,12 @@ export class From {
177
278
  }
178
279
  return last;
179
280
  }
281
+ /**
282
+ * Projects each element of a sequence to an Iterable and flattens the resulting sequences into one sequence.
283
+ * @template R
284
+ * @param {UnaryFunction<T, Iterable<R>>} mapper - A transformation function.
285
+ * @returns {From<R>} A new From instance.
286
+ */
180
287
  mapMany(mapper) {
181
288
  const self = this;
182
289
  return From.fn(function* () {
@@ -188,6 +295,10 @@ export class From {
188
295
  }
189
296
  });
190
297
  }
298
+ /**
299
+ * Flattens a sequence of iterables.
300
+ * @returns {From<any>} A new From instance.
301
+ */
191
302
  flatten() {
192
303
  const self = this;
193
304
  return From.fn(function* () {
@@ -199,6 +310,11 @@ export class From {
199
310
  }
200
311
  });
201
312
  }
313
+ /**
314
+ * Calculates the sum of the elements in the sequence.
315
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
316
+ * @returns {number} The sum.
317
+ */
202
318
  sum(mapper) {
203
319
  let total = 0;
204
320
  if (mapper)
@@ -211,6 +327,11 @@ export class From {
211
327
  }
212
328
  return total;
213
329
  }
330
+ /**
331
+ * Calculates the average of the elements in the sequence.
332
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
333
+ * @returns {number} The average.
334
+ */
214
335
  avg(mapper) {
215
336
  let total = 0;
216
337
  let count = 0;
@@ -226,6 +347,11 @@ export class From {
226
347
  }
227
348
  return count > 0 ? total / count : 0;
228
349
  }
350
+ /**
351
+ * Returns the maximum value in the sequence.
352
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
353
+ * @returns {number} The maximum value.
354
+ */
229
355
  max(mapper) {
230
356
  let max = -Infinity;
231
357
  for (let item of this) {
@@ -234,6 +360,11 @@ export class From {
234
360
  }
235
361
  return max;
236
362
  }
363
+ /**
364
+ * Returns the minimum value in the sequence.
365
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
366
+ * @returns {number} The minimum value.
367
+ */
237
368
  min(mapper) {
238
369
  let min = Infinity;
239
370
  for (let item of this) {
@@ -242,6 +373,11 @@ export class From {
242
373
  }
243
374
  return min;
244
375
  }
376
+ /**
377
+ * Returns the element with the maximum value.
378
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
379
+ * @returns {T | undefined} The element with the maximum value.
380
+ */
245
381
  maxBy(mapper) {
246
382
  let max = -Infinity;
247
383
  let maxItem;
@@ -254,6 +390,11 @@ export class From {
254
390
  }
255
391
  return maxItem;
256
392
  }
393
+ /**
394
+ * Returns the element with the minimum value.
395
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
396
+ * @returns {T | undefined} The element with the minimum value.
397
+ */
257
398
  minBy(mapper) {
258
399
  let min = Infinity;
259
400
  let minItem;
@@ -266,6 +407,13 @@ export class From {
266
407
  }
267
408
  return minItem;
268
409
  }
410
+ /**
411
+ * Sorts the elements of the sequence.
412
+ * @template R
413
+ * @param {UnaryFunction<T, R>} mapper - Projection function for the key to sort by.
414
+ * @param {Order} [order] - Ascending or Descending.
415
+ * @returns {From<T>} A new From instance.
416
+ */
269
417
  orderBy(mapper, order = Order.Ascending) {
270
418
  const array = Array.from(this._fn());
271
419
  if (order == Order.Ascending) {
@@ -287,6 +435,13 @@ export class From {
287
435
  }
288
436
  return From.iterable(array);
289
437
  }
438
+ /**
439
+ * Groups the elements of the sequence.
440
+ * @template TKey
441
+ * @param {UnaryFunction<T, TKey>} keySelector - Function to extract the key for each element.
442
+ * @param {EqualityComparer<TKey>} [equalityComparer] - Optional comparer for keys.
443
+ * @returns {From<Grouping<TKey, T>>} A new From instance.
444
+ */
290
445
  groupBy(keySelector, equalityComparer) {
291
446
  equalityComparer = (equalityComparer == null ? shallowEqual : equalityComparer);
292
447
  const self = this;
@@ -309,6 +464,11 @@ export class From {
309
464
  yield* groups.map(([key, values]) => new Grouping(key, values));
310
465
  });
311
466
  }
467
+ /**
468
+ * Returns a specified number of contiguous elements from the start of the sequence.
469
+ * @param {number} n - The number of elements to return.
470
+ * @returns {From<T>} A new From instance.
471
+ */
312
472
  head(n) {
313
473
  const self = this;
314
474
  return From.fn(function* () {
@@ -323,6 +483,11 @@ export class From {
323
483
  }
324
484
  });
325
485
  }
486
+ /**
487
+ * Returns a specified number of contiguous elements from the end of the sequence.
488
+ * @param {number} n - The number of elements to return.
489
+ * @returns {From<T>} A new From instance.
490
+ */
326
491
  tail(n) {
327
492
  const self = this;
328
493
  return From.fn(function* () {
@@ -336,14 +501,29 @@ export class From {
336
501
  yield* buffer;
337
502
  });
338
503
  }
504
+ /**
505
+ * Performs the specified action on each element of the sequence.
506
+ * @param {Consumer<T>} action - The action to perform.
507
+ */
339
508
  forEach(action) {
340
509
  for (let item of this) {
341
510
  action(item);
342
511
  }
343
512
  }
513
+ /**
514
+ * Converts the sequence to an array.
515
+ * @returns {T[]} The array.
516
+ */
344
517
  toArray() {
345
518
  return Array.from(this);
346
519
  }
520
+ /**
521
+ * Converts the sequence to a record.
522
+ * @template R
523
+ * @param {UnaryFunction<T, string | symbol | number>} keySelector - Key selector.
524
+ * @param {UnaryFunction<T, R>} valueSelector - Value selector.
525
+ * @returns {Record<string | symbol | number, R>} The record.
526
+ */
347
527
  toRecord(keySelector, valueSelector) {
348
528
  const output = {};
349
529
  for (let item of this) {
@@ -351,6 +531,13 @@ export class From {
351
531
  }
352
532
  return output;
353
533
  }
534
+ /**
535
+ * Converts the sequence to a Map.
536
+ * @template RKey, RValue
537
+ * @param {UnaryFunction<T, RKey>} keySelector - Key selector.
538
+ * @param {UnaryFunction<T, RValue>} valueSelector - Value selector.
539
+ * @returns {Map<RKey, RValue>} The map.
540
+ */
354
541
  toMap(keySelector, valueSelector) {
355
542
  const map = new Map();
356
543
  for (let item of this) {
@@ -360,9 +547,19 @@ export class From {
360
547
  }
361
548
  return map;
362
549
  }
550
+ /**
551
+ * Returns elements that are instances of a specific primitive type.
552
+ * @param {string} type - The type string (e.g., 'string', 'number').
553
+ * @returns {From<T>} A new From instance.
554
+ */
363
555
  instancesOf(type) {
364
556
  return this.filter(item => typeof item === type);
365
557
  }
558
+ /**
559
+ * Checks if all elements are instances of a specific class.
560
+ * @param {new (...args: any[]) => any} type - The class constructor.
561
+ * @returns {boolean} True if all elements are instances of the type.
562
+ */
366
563
  allInstanceOf(type) {
367
564
  for (let item of this) {
368
565
  if (!(item instanceof type)) {
@@ -371,6 +568,11 @@ export class From {
371
568
  }
372
569
  return true;
373
570
  }
571
+ /**
572
+ * Returns distinct elements from the sequence.
573
+ * @param {EqualityComparer<T>} [eq_comparer] - Optional equality comparer.
574
+ * @returns {From<T>} A new From instance.
575
+ */
374
576
  distinct(eq_comparer) {
375
577
  if (eq_comparer == null)
376
578
  eq_comparer = shallowEqual;
@@ -385,6 +587,12 @@ export class From {
385
587
  }
386
588
  });
387
589
  }
590
+ /**
591
+ * Inserts an item at a specific index.
592
+ * @param {T} item - The item to insert.
593
+ * @param {number} index - The zero-based index.
594
+ * @returns {From<T>} A new From instance.
595
+ */
388
596
  insert(item, index) {
389
597
  const self = this;
390
598
  return From.fn(function* () {
@@ -403,6 +611,11 @@ export class From {
403
611
  }
404
612
  });
405
613
  }
614
+ /**
615
+ * Bypasses a specified number of elements in a sequence and then returns the remaining elements.
616
+ * @param {number} n - The number of elements to skip.
617
+ * @returns {From<T>} A new From instance.
618
+ */
406
619
  skip(n) {
407
620
  const self = this;
408
621
  return From.fn(function* () {
@@ -415,6 +628,11 @@ export class From {
415
628
  }
416
629
  });
417
630
  }
631
+ /**
632
+ * Concatenates two sequences.
633
+ * @param {Iterable<T>} other - The other sequence.
634
+ * @returns {From<T>} A new From instance.
635
+ */
418
636
  union(other) {
419
637
  const self = this;
420
638
  return From.fn(function* () {
@@ -422,6 +640,15 @@ export class From {
422
640
  yield* other;
423
641
  });
424
642
  }
643
+ /**
644
+ * Correlates the elements of two sequences based on matching keys.
645
+ * @template T2, R, R2
646
+ * @param {Iterable<T2>} other - The other sequence.
647
+ * @param {UnaryFunction<T, R>} thisKeySelector - Key selector for this sequence.
648
+ * @param {UnaryFunction<T2, R>} otherKeySelector - Key selector for the other sequence.
649
+ * @param {(thisItem: T, otherItem: T2) => R2} resultSelector - Function to create a result element from two matching elements.
650
+ * @returns {From<R2>} A new From instance.
651
+ */
425
652
  innerJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
426
653
  const self = this;
427
654
  return From.fn(() => {
@@ -434,6 +661,15 @@ export class From {
434
661
  .map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
435
662
  });
436
663
  }
664
+ /**
665
+ * Performs a left join on two sequences.
666
+ * @template U, K, R
667
+ * @param {Iterable<U>} other - The other sequence.
668
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
669
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
670
+ * @param {(thisItem: T, otherItem: U | undefined) => R} resultSelector - Function to create a result element.
671
+ * @returns {From<R>} A new From instance.
672
+ */
437
673
  leftJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
438
674
  const self = this;
439
675
  return From.fn(() => {
@@ -444,6 +680,15 @@ export class From {
444
680
  return Array.from(self).map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
445
681
  });
446
682
  }
683
+ /**
684
+ * Performs a left group join on two sequences.
685
+ * @template U, K, R
686
+ * @param {Iterable<U>} other - The other sequence.
687
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
688
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
689
+ * @param {(thisItem: T, otherItems: Array<U>) => R} resultSelector - Function to create a result element.
690
+ * @returns {From<R>} A new From instance.
691
+ */
447
692
  leftGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
448
693
  const self = this;
449
694
  return From.fn(() => {
@@ -458,6 +703,15 @@ export class From {
458
703
  return Array.from(self).map(item => resultSelector(item, otherByKeys.get(thisKeySelector(item)) || []));
459
704
  });
460
705
  }
706
+ /**
707
+ * Performs a right group join on two sequences.
708
+ * @template U, K, R
709
+ * @param {Iterable<U>} other - The other sequence.
710
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
711
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
712
+ * @param {(thisItems: Array<T>, otherItem: U) => R} resultSelector - Function to create a result element.
713
+ * @returns {From<R>} A new From instance.
714
+ */
461
715
  rightGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
462
716
  const self = this;
463
717
  return From.fn(() => {
@@ -472,6 +726,15 @@ export class From {
472
726
  return Array.from(other).map(item => resultSelector(thisByKeys.get(otherKeySelector(item)) || [], item));
473
727
  });
474
728
  }
729
+ /**
730
+ * Performs a right join on two sequences.
731
+ * @template U, K, R
732
+ * @param {Iterable<U>} other - The other sequence.
733
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
734
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
735
+ * @param {(thisItem: T | undefined, otherItem: U) => R} resultSelector - Function to create a result element.
736
+ * @returns {From<R>} A new From instance.
737
+ */
475
738
  rightJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
476
739
  const self = this;
477
740
  return From.fn(() => {
@@ -483,10 +746,21 @@ export class From {
483
746
  });
484
747
  }
485
748
  }
749
+ /**
750
+ * Represents a group of elements that have a common key.
751
+ * @template TKey, T
752
+ */
486
753
  export class Grouping extends From {
754
+ /**
755
+ * Gets the key of the group.
756
+ */
487
757
  get key() {
488
758
  return this._key;
489
759
  }
760
+ /**
761
+ * @param {TKey} key - The group key.
762
+ * @param {Array<T>} values - The values in the group.
763
+ */
490
764
  constructor(key, values) {
491
765
  super(() => values);
492
766
  this._key = key;