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