@develia/commons 0.4.14 → 0.4.16

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 (230) hide show
  1. package/dist/cjs/array.js +43 -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 +16 -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/range.js +154 -0
  43. package/dist/cjs/range.js.map +1 -0
  44. package/dist/cjs/stopwatch.js +10 -0
  45. package/dist/cjs/stopwatch.js.map +1 -1
  46. package/dist/cjs/string.js +62 -0
  47. package/dist/cjs/string.js.map +1 -1
  48. package/dist/cjs/timer.js +7 -0
  49. package/dist/cjs/timer.js.map +1 -1
  50. package/dist/cjs/timespan.js +202 -0
  51. package/dist/cjs/timespan.js.map +1 -1
  52. package/dist/cjs/type-code.js.map +1 -1
  53. package/dist/cjs/type.js +80 -1
  54. package/dist/cjs/type.js.map +1 -1
  55. package/dist/cjs/types.js.map +1 -1
  56. package/dist/cjs/utilities.js +183 -0
  57. package/dist/cjs/utilities.js.map +1 -1
  58. package/dist/esm/array.js +42 -1
  59. package/dist/esm/array.js.map +1 -1
  60. package/dist/esm/async-pool-executor.js +15 -0
  61. package/dist/esm/async-pool-executor.js.map +1 -1
  62. package/dist/esm/browser/form-utilities.js +26 -0
  63. package/dist/esm/browser/form-utilities.js.map +1 -1
  64. package/dist/esm/browser/geo-location.js +5 -0
  65. package/dist/esm/browser/geo-location.js.map +1 -1
  66. package/dist/esm/browser/index.js.map +1 -1
  67. package/dist/esm/browser/native-bridge.js +9 -0
  68. package/dist/esm/browser/native-bridge.js.map +1 -1
  69. package/dist/esm/cancellable-promise.js.map +1 -1
  70. package/dist/esm/clean-url-search-params.js +1 -0
  71. package/dist/esm/clean-url-search-params.js.map +1 -1
  72. package/dist/esm/collections/cache-dictionary.js +39 -0
  73. package/dist/esm/collections/cache-dictionary.js.map +1 -1
  74. package/dist/esm/collections/default-map.js +25 -1
  75. package/dist/esm/collections/default-map.js.map +1 -1
  76. package/dist/esm/collections/default-weak-map.js +22 -2
  77. package/dist/esm/collections/default-weak-map.js.map +1 -1
  78. package/dist/esm/{from.js → collections/from.js} +278 -4
  79. package/dist/esm/collections/from.js.map +1 -0
  80. package/dist/esm/collections/index.js +1 -0
  81. package/dist/esm/collections/index.js.map +1 -1
  82. package/dist/esm/draft.js +37 -0
  83. package/dist/esm/draft.js.map +1 -1
  84. package/dist/esm/event-bus.js +1 -0
  85. package/dist/esm/event-bus.js.map +1 -1
  86. package/dist/esm/index.js +14 -1
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/key-value-pair.js +6 -0
  89. package/dist/esm/key-value-pair.js.map +1 -1
  90. package/dist/esm/lazy.js +4 -0
  91. package/dist/esm/lazy.js.map +1 -1
  92. package/dist/esm/math.js +19 -0
  93. package/dist/esm/math.js.map +1 -1
  94. package/dist/esm/order.js.map +1 -1
  95. package/dist/esm/parse.js +96 -0
  96. package/dist/esm/parse.js.map +1 -1
  97. package/dist/esm/patch.js +10 -2
  98. package/dist/esm/patch.js.map +1 -1
  99. package/dist/esm/range.js +151 -0
  100. package/dist/esm/range.js.map +1 -0
  101. package/dist/esm/stopwatch.js +10 -0
  102. package/dist/esm/stopwatch.js.map +1 -1
  103. package/dist/esm/string.js +62 -0
  104. package/dist/esm/string.js.map +1 -1
  105. package/dist/esm/timer.js +7 -0
  106. package/dist/esm/timer.js.map +1 -1
  107. package/dist/esm/timespan.js +202 -0
  108. package/dist/esm/timespan.js.map +1 -1
  109. package/dist/esm/type-code.js.map +1 -1
  110. package/dist/esm/type.js +80 -1
  111. package/dist/esm/type.js.map +1 -1
  112. package/dist/esm/types.js.map +1 -1
  113. package/dist/esm/utilities.js +183 -0
  114. package/dist/esm/utilities.js.map +1 -1
  115. package/dist/types/array.d.ts +35 -0
  116. package/dist/types/array.d.ts.map +1 -1
  117. package/dist/types/async-pool-executor.d.ts +15 -0
  118. package/dist/types/async-pool-executor.d.ts.map +1 -1
  119. package/dist/types/browser/form-utilities.d.ts +13 -0
  120. package/dist/types/browser/form-utilities.d.ts.map +1 -1
  121. package/dist/types/browser/index.d.ts.map +1 -1
  122. package/dist/types/browser/native-bridge.d.ts +6 -0
  123. package/dist/types/browser/native-bridge.d.ts.map +1 -1
  124. package/dist/types/collections/cache-dictionary.d.ts +39 -0
  125. package/dist/types/collections/cache-dictionary.d.ts.map +1 -1
  126. package/dist/types/collections/default-map.d.ts +23 -0
  127. package/dist/types/collections/default-map.d.ts.map +1 -1
  128. package/dist/types/collections/default-weak-map.d.ts +20 -1
  129. package/dist/types/collections/default-weak-map.d.ts.map +1 -1
  130. package/dist/types/collections/from.d.ts +333 -0
  131. package/dist/types/collections/from.d.ts.map +1 -0
  132. package/dist/types/collections/index.d.ts +1 -0
  133. package/dist/types/collections/index.d.ts.map +1 -1
  134. package/dist/types/draft.d.ts +68 -0
  135. package/dist/types/draft.d.ts.map +1 -1
  136. package/dist/types/index.d.ts +5 -1
  137. package/dist/types/index.d.ts.map +1 -1
  138. package/dist/types/key-value-pair.d.ts +6 -0
  139. package/dist/types/key-value-pair.d.ts.map +1 -1
  140. package/dist/types/lazy.d.ts +4 -0
  141. package/dist/types/lazy.d.ts.map +1 -1
  142. package/dist/types/math.d.ts +19 -0
  143. package/dist/types/math.d.ts.map +1 -1
  144. package/dist/types/parse.d.ts +121 -0
  145. package/dist/types/parse.d.ts.map +1 -1
  146. package/dist/types/range.d.ts +72 -0
  147. package/dist/types/range.d.ts.map +1 -0
  148. package/dist/types/string.d.ts +51 -0
  149. package/dist/types/string.d.ts.map +1 -1
  150. package/dist/types/timer.d.ts +7 -0
  151. package/dist/types/timer.d.ts.map +1 -1
  152. package/dist/types/timespan.d.ts +202 -0
  153. package/dist/types/timespan.d.ts.map +1 -1
  154. package/dist/types/type.d.ts +40 -0
  155. package/dist/types/type.d.ts.map +1 -1
  156. package/dist/types/utilities.d.ts +171 -0
  157. package/dist/types/utilities.d.ts.map +1 -1
  158. package/dist/web/array.js +42 -1
  159. package/dist/web/array.js.map +1 -1
  160. package/dist/web/async-pool-executor.js +15 -0
  161. package/dist/web/async-pool-executor.js.map +1 -1
  162. package/dist/web/browser/form-utilities.js +26 -0
  163. package/dist/web/browser/form-utilities.js.map +1 -1
  164. package/dist/web/browser/geo-location.js +5 -0
  165. package/dist/web/browser/geo-location.js.map +1 -1
  166. package/dist/web/browser/index.js.map +1 -1
  167. package/dist/web/browser/native-bridge.js +9 -0
  168. package/dist/web/browser/native-bridge.js.map +1 -1
  169. package/dist/web/cancellable-promise.js.map +1 -1
  170. package/dist/web/clean-url-search-params.js +1 -0
  171. package/dist/web/clean-url-search-params.js.map +1 -1
  172. package/dist/web/collections/cache-dictionary.js +39 -0
  173. package/dist/web/collections/cache-dictionary.js.map +1 -1
  174. package/dist/web/collections/default-map.js +25 -1
  175. package/dist/web/collections/default-map.js.map +1 -1
  176. package/dist/web/collections/default-weak-map.js +22 -2
  177. package/dist/web/collections/default-weak-map.js.map +1 -1
  178. package/dist/web/{from.js → collections/from.js} +279 -5
  179. package/dist/web/collections/from.js.map +1 -0
  180. package/dist/web/collections/index.js +1 -0
  181. package/dist/web/collections/index.js.map +1 -1
  182. package/dist/web/draft.js +37 -0
  183. package/dist/web/draft.js.map +1 -1
  184. package/dist/web/event-bus.js +1 -0
  185. package/dist/web/event-bus.js.map +1 -1
  186. package/dist/web/index.js +14 -1
  187. package/dist/web/index.js.map +1 -1
  188. package/dist/web/key-value-pair.js +6 -0
  189. package/dist/web/key-value-pair.js.map +1 -1
  190. package/dist/web/lazy.js +4 -0
  191. package/dist/web/lazy.js.map +1 -1
  192. package/dist/web/math.js +19 -0
  193. package/dist/web/math.js.map +1 -1
  194. package/dist/web/order.js.map +1 -1
  195. package/dist/web/parse.js +96 -0
  196. package/dist/web/parse.js.map +1 -1
  197. package/dist/web/patch.js +10 -2
  198. package/dist/web/patch.js.map +1 -1
  199. package/dist/web/range.js +151 -0
  200. package/dist/web/range.js.map +1 -0
  201. package/dist/web/stopwatch.js +10 -0
  202. package/dist/web/stopwatch.js.map +1 -1
  203. package/dist/web/string.js +62 -0
  204. package/dist/web/string.js.map +1 -1
  205. package/dist/web/timer.js +7 -0
  206. package/dist/web/timer.js.map +1 -1
  207. package/dist/web/timespan.js +202 -0
  208. package/dist/web/timespan.js.map +1 -1
  209. package/dist/web/type-code.js.map +1 -1
  210. package/dist/web/type.js +80 -1
  211. package/dist/web/type.js.map +1 -1
  212. package/dist/web/types.js.map +1 -1
  213. package/dist/web/utilities.js +183 -0
  214. package/dist/web/utilities.js.map +1 -1
  215. package/package.json +1 -1
  216. package/src/array.ts +16 -0
  217. package/src/browser/index.ts +2 -2
  218. package/src/collections/cache-dictionary.ts +39 -1
  219. package/src/collections/default-map.ts +15 -9
  220. package/src/collections/default-weak-map.ts +14 -12
  221. package/src/{from.ts → collections/from.ts} +285 -15
  222. package/src/collections/index.ts +4 -3
  223. package/src/index.ts +43 -42
  224. package/src/range.ts +165 -0
  225. package/src/timespan.ts +199 -20
  226. package/dist/cjs/from.js.map +0 -1
  227. package/dist/esm/from.js.map +0 -1
  228. package/dist/types/from.d.ts +0 -59
  229. package/dist/types/from.d.ts.map +0 -1
  230. package/dist/web/from.js.map +0 -1
@@ -1,9 +1,16 @@
1
- import type {Consumer, EqualityComparer, UnaryFunction, Predicate, Supplier, Optional, Nullable} from "./types.js";
2
- import {shallowEqual, toPairs} from "./utilities.js";
3
- import KeyValuePair from "./key-value-pair.js";
4
- import Order from "./order.js";
5
-
6
-
1
+ import type {Consumer, EqualityComparer, UnaryFunction, Predicate, Supplier, Optional, Nullable} from "../types.js";
2
+ import {shallowEqual, toPairs} from "../utilities.js";
3
+ import KeyValuePair from "../key-value-pair.js";
4
+ import Order from "../order.js";
5
+
6
+
7
+ /**
8
+ * Creates a new From instance from an Iterable or a Supplier of an Iterable.
9
+ * @template T - The type of elements in the source.
10
+ * @param {Iterable<T> | Supplier<Iterable<T>>} source - The source data.
11
+ * @returns {From<T> | From<KeyValuePair<any, any>>} A new From instance.
12
+ * @throws {string} If source is null or invalid.
13
+ */
7
14
  export default function from<T>(source: Iterable<T> | Supplier<Iterable<T>>): From<T> | From<KeyValuePair<any, any>> {
8
15
  if (source == null)
9
16
  throw "Source is null.";
@@ -12,14 +19,23 @@ export default function from<T>(source: Iterable<T> | Supplier<Iterable<T>>): Fr
12
19
  if (typeof source[Symbol.iterator] === 'function') {
13
20
  return From.iterable<T>(source);
14
21
  } else if (typeof source === 'object') {
15
- return From.object(source)
22
+ return From.object(source);
16
23
  }
17
24
 
18
25
  throw "Invalid source.";
19
26
  }
20
27
 
28
+ /**
29
+ * A LINQ-like wrapper for iterables that provides various transformation and query methods.
30
+ * @template T - The type of elements in the sequence.
31
+ */
21
32
  export class From<T> implements Iterable<T> {
22
33
 
34
+ /**
35
+ * Creates a From instance from an object's entries.
36
+ * @param {any} obj - The object to convert to pairs.
37
+ * @returns {From<KeyValuePair<any, any>>} A From instance of key-value pairs.
38
+ */
23
39
  public static object(obj: any): From<KeyValuePair<any, any>> {
24
40
  return new From<KeyValuePair<any, any>>(function () {
25
41
  return toPairs(obj);
@@ -33,37 +49,65 @@ export class From<T> implements Iterable<T> {
33
49
  this._fn = fn;
34
50
  }
35
51
 
52
+ /**
53
+ * Creates a From instance from a supplier function.
54
+ * @template T
55
+ * @param {Supplier<Iterable<T>>} callable - A function that returns an Iterable.
56
+ * @returns {From<T>} A new From instance.
57
+ */
36
58
  public static fn<T>(callable: Supplier<Iterable<T>>): From<T> {
37
59
  return new From<T>(callable);
38
- };
60
+ }
39
61
 
62
+ /**
63
+ * Collects all elements into an array and returns a new From instance from it.
64
+ * Useful for freezing the sequence and preventing multiple iterations over a generator.
65
+ * @returns {From<T>} A new From instance with cached data.
66
+ */
40
67
  public collect(): From<T> {
41
68
  const cache = Array.from(this);
42
69
  return From.iterable(cache);
43
70
  }
44
71
 
72
+ /**
73
+ * Creates a From instance from an Iterable.
74
+ * @template T
75
+ * @param {Iterable<T>} iterable - The source iterable.
76
+ * @returns {From<T>} A new From instance.
77
+ */
45
78
  public static iterable<T>(iterable: Iterable<T>): From<T> {
46
79
  return From.fn<T>(function* () {
47
80
  for (const item of iterable) {
48
81
  yield item;
49
82
  }
50
83
  });
51
- };
84
+ }
52
85
 
86
+ /**
87
+ * Maps each element of the sequence into a new form.
88
+ * @template R
89
+ * @param {UnaryFunction<T, R>} mapper - A transformation function.
90
+ * @returns {From<R>} A new From instance with the mapped elements.
91
+ */
53
92
  public map<R>(mapper: UnaryFunction<T, R>): From<R> {
54
93
  const self = this;
55
94
  return From.fn<R>(function* () {
56
95
  for (let item of self) {
57
96
  yield mapper(item);
58
97
  }
59
- })
98
+ });
60
99
  }
61
100
 
62
101
  * [Symbol.iterator](): Iterator<T> {
63
- yield* this._fn()
102
+ yield* this._fn();
64
103
  }
65
104
 
66
105
 
106
+ /**
107
+ * Checks if all elements in the sequence satisfy the given predicate.
108
+ * @param {Predicate<T>} predicate - A function to test each element.
109
+ * @returns {boolean} True if all elements satisfy the predicate.
110
+ */
67
111
  public all(predicate: Predicate<T>): boolean {
68
112
  for (let item of this._fn()) {
69
113
  if (!predicate(item)) {
@@ -73,6 +117,12 @@ export class From<T> implements Iterable<T> {
73
117
  return true;
74
118
  }
75
119
 
120
+ /**
121
+ * Checks if any element in the sequence satisfies the given predicate.
122
+ * If no predicate is provided, checks if the sequence is not empty.
123
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
124
+ * @returns {boolean} True if any element satisfies the predicate.
125
+ */
76
126
  public any(predicate: Optional<Predicate<T>> = undefined): boolean {
77
127
  for (let item of this) {
78
128
  if (predicate == null || predicate(item)) {
@@ -82,10 +132,20 @@ export class From<T> implements Iterable<T> {
82
132
  return false;
83
133
  }
84
134
 
135
+ /**
136
+ * Gets the number of elements in the sequence.
137
+ * @returns {number} The count of elements.
138
+ */
85
139
  public get length(): number {
86
140
  return this.count();
87
141
  }
88
142
 
143
+ /**
144
+ * Counts the number of elements that satisfy the given predicate.
145
+ * If no predicate is provided, counts all elements.
146
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
147
+ * @returns {number} The count of elements.
148
+ */
89
149
  public count(predicate: Optional<Predicate<T>> = undefined): number {
90
150
 
91
151
  let output = 0;
@@ -99,6 +159,11 @@ export class From<T> implements Iterable<T> {
99
159
  return output;
100
160
  }
101
161
 
162
+ /**
163
+ * Filters the sequence based on a predicate.
164
+ * @param {Predicate<T>} predicate - A function to test each element.
165
+ * @returns {From<T>} A new From instance with the filtered elements.
166
+ */
102
167
  public filter(predicate: Predicate<T>): From<T> {
103
168
  const self = this;
104
169
  return From.fn<T>(function* () {
@@ -110,6 +175,11 @@ export class From<T> implements Iterable<T> {
110
175
  });
111
176
  }
112
177
 
178
+ /**
179
+ * Checks if the sequence contains a specific value.
180
+ * @param {T} value - The value to search for.
181
+ * @returns {boolean} True if the value is found.
182
+ */
113
183
  public contains(value: T): boolean {
114
184
  for (let item of this) {
115
185
  if (item === value) {
@@ -120,7 +190,11 @@ export class From<T> implements Iterable<T> {
120
190
  }
121
191
 
122
192
 
123
- // noinspection LoopStatementThatDoesntLoopJS
193
+ /**
194
+ * Returns the first element of the sequence that satisfies a condition.
195
+ * @param {Predicate<T>} [predicate] - Optional condition.
196
+ * @returns {T | undefined} The first element or undefined.
197
+ */
124
198
  public first(predicate?: Predicate<T>): T | undefined {
125
199
 
126
200
  if (predicate) {
@@ -139,7 +213,12 @@ export class From<T> implements Iterable<T> {
139
213
  return undefined;
140
214
  }
141
215
 
142
- // noinspection LoopStatementThatDoesntLoopJS
216
+ /**
217
+ * Returns the only element of the sequence that satisfies a condition, or throws if more than one exists.
218
+ * @param {Predicate<T>} [predicate] - Optional condition.
219
+ * @returns {T | null} The single element or null if not found.
220
+ * @throws {Error} If more than one element is found.
221
+ */
143
222
  public single(predicate?: Predicate<T>): T | null {
144
223
 
145
224
  let found = false;
@@ -169,6 +248,11 @@ export class From<T> implements Iterable<T> {
169
248
  return output;
170
249
  }
171
250
 
251
+ /**
252
+ * Appends an item to the end of the sequence.
253
+ * @param {T} item - The item to append.
254
+ * @returns {From<T>} A new From instance.
255
+ */
172
256
  public append(item: T): From<T> {
173
257
  const self = this;
174
258
  return From.fn<T>(function* () {
@@ -179,6 +263,11 @@ export class From<T> implements Iterable<T> {
179
263
  });
180
264
  }
181
265
 
266
+ /**
267
+ * Prepends an item to the beginning of the sequence.
268
+ * @param {T} item - The item to prepend.
269
+ * @returns {From<T>} A new From instance.
270
+ */
182
271
  public prepend(item: T): From<T> {
183
272
  const self = this;
184
273
  return From.fn<T>(function* () {
@@ -189,6 +278,11 @@ export class From<T> implements Iterable<T> {
189
278
  });
190
279
  }
191
280
 
281
+ /**
282
+ * Gets the element at a specific index.
283
+ * @param {number} index - The zero-based index.
284
+ * @returns {T | undefined} The element at the index or undefined.
285
+ */
192
286
  public at(index: number): T | undefined {
193
287
  let idx = 0;
194
288
  for (let item of this) {
@@ -199,6 +293,11 @@ export class From<T> implements Iterable<T> {
199
293
  return undefined;
200
294
  }
201
295
 
296
+ /**
297
+ * Returns the last element of the sequence that satisfies a condition.
298
+ * @param {Predicate<T>} [predicate] - Optional condition.
299
+ * @returns {T | undefined} The last element or undefined.
300
+ */
202
301
  public last(predicate?: Predicate<T>): T | undefined {
203
302
 
204
303
 
@@ -218,6 +317,12 @@ export class From<T> implements Iterable<T> {
218
317
  return last;
219
318
  }
220
319
 
320
+ /**
321
+ * Projects each element of a sequence to an Iterable and flattens the resulting sequences into one sequence.
322
+ * @template R
323
+ * @param {UnaryFunction<T, Iterable<R>>} mapper - A transformation function.
324
+ * @returns {From<R>} A new From instance.
325
+ */
221
326
  public mapMany<R>(mapper: UnaryFunction<T, Iterable<R>>): From<R> {
222
327
  const self = this;
223
328
  return From.fn(function* () {
@@ -230,6 +335,10 @@ export class From<T> implements Iterable<T> {
230
335
  })
231
336
  }
232
337
 
338
+ /**
339
+ * Flattens a sequence of iterables.
340
+ * @returns {From<any>} A new From instance.
341
+ */
233
342
  public flatten(): From<any> {
234
343
  const self = this;
235
344
  return From.fn<T>(function* () {
@@ -242,6 +351,11 @@ export class From<T> implements Iterable<T> {
242
351
  });
243
352
  }
244
353
 
354
+ /**
355
+ * Calculates the sum of the elements in the sequence.
356
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
357
+ * @returns {number} The sum.
358
+ */
245
359
  public sum(mapper?: UnaryFunction<T, number>): number {
246
360
  let total = 0;
247
361
 
@@ -256,6 +370,11 @@ export class From<T> implements Iterable<T> {
256
370
  return total;
257
371
  }
258
372
 
373
+ /**
374
+ * Calculates the average of the elements in the sequence.
375
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
376
+ * @returns {number} The average.
377
+ */
259
378
  public avg(mapper?: UnaryFunction<T, number>): number {
260
379
  let total = 0;
261
380
  let count = 0;
@@ -273,6 +392,11 @@ export class From<T> implements Iterable<T> {
273
392
  return count > 0 ? total / count : 0;
274
393
  }
275
394
 
395
+ /**
396
+ * Returns the maximum value in the sequence.
397
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
398
+ * @returns {number} The maximum value.
399
+ */
276
400
  public max(mapper: UnaryFunction<T, number>): number {
277
401
  let max = -Infinity;
278
402
  for (let item of this) {
@@ -282,6 +406,11 @@ export class From<T> implements Iterable<T> {
282
406
  return max;
283
407
  }
284
408
 
409
+ /**
410
+ * Returns the minimum value in the sequence.
411
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
412
+ * @returns {number} The minimum value.
413
+ */
285
414
  public min(mapper: UnaryFunction<T, number>): number {
286
415
  let min = Infinity;
287
416
  for (let item of this) {
@@ -291,6 +420,11 @@ export class From<T> implements Iterable<T> {
291
420
  return min;
292
421
  }
293
422
 
423
+ /**
424
+ * Returns the element with the maximum value.
425
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
426
+ * @returns {T | undefined} The element with the maximum value.
427
+ */
294
428
  public maxBy(mapper: UnaryFunction<T, number>): T | undefined {
295
429
  let max = -Infinity;
296
430
  let maxItem: T | undefined;
@@ -304,6 +438,11 @@ export class From<T> implements Iterable<T> {
304
438
  return maxItem;
305
439
  }
306
440
 
441
+ /**
442
+ * Returns the element with the minimum value.
443
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
444
+ * @returns {T | undefined} The element with the minimum value.
445
+ */
307
446
  public minBy(mapper: UnaryFunction<T, number>): T | undefined {
308
447
  let min = Infinity;
309
448
  let minItem: T | undefined;
@@ -317,6 +456,13 @@ export class From<T> implements Iterable<T> {
317
456
  return minItem;
318
457
  }
319
458
 
459
+ /**
460
+ * Sorts the elements of the sequence.
461
+ * @template R
462
+ * @param {UnaryFunction<T, R>} mapper - Projection function for the key to sort by.
463
+ * @param {Order} [order] - Ascending or Descending.
464
+ * @returns {From<T>} A new From instance.
465
+ */
320
466
  public orderBy<R>(mapper: UnaryFunction<T, R>, order: Order = Order.Ascending): From<T> {
321
467
  const array = Array.from(this._fn());
322
468
  if (order == Order.Ascending) {
@@ -338,6 +484,13 @@ export class From<T> implements Iterable<T> {
338
484
  return From.iterable(array);
339
485
  }
340
486
 
487
+ /**
488
+ * Groups the elements of the sequence.
489
+ * @template TKey
490
+ * @param {UnaryFunction<T, TKey>} keySelector - Function to extract the key for each element.
491
+ * @param {EqualityComparer<TKey>} [equalityComparer] - Optional comparer for keys.
492
+ * @returns {From<Grouping<TKey, T>>} A new From instance.
493
+ */
341
494
  public groupBy<TKey>(keySelector: UnaryFunction<T, TKey>, equalityComparer?: EqualityComparer<TKey>): From<Grouping<TKey, T>> {
342
495
 
343
496
  equalityComparer = (equalityComparer == null ? shallowEqual : equalityComparer);
@@ -363,6 +516,11 @@ export class From<T> implements Iterable<T> {
363
516
  });
364
517
  }
365
518
 
519
+ /**
520
+ * Returns a specified number of contiguous elements from the start of the sequence.
521
+ * @param {number} n - The number of elements to return.
522
+ * @returns {From<T>} A new From instance.
523
+ */
366
524
  public head(n: number): From<T> {
367
525
 
368
526
  const self = this;
@@ -378,6 +536,11 @@ export class From<T> implements Iterable<T> {
378
536
  });
379
537
  }
380
538
 
539
+ /**
540
+ * Returns a specified number of contiguous elements from the end of the sequence.
541
+ * @param {number} n - The number of elements to return.
542
+ * @returns {From<T>} A new From instance.
543
+ */
381
544
  public tail(n: number): From<T> {
382
545
 
383
546
  const self = this;
@@ -393,16 +556,31 @@ export class From<T> implements Iterable<T> {
393
556
  });
394
557
  }
395
558
 
559
+ /**
560
+ * Performs the specified action on each element of the sequence.
561
+ * @param {Consumer<T>} action - The action to perform.
562
+ */
396
563
  public forEach(action: Consumer<T>): void {
397
564
  for (let item of this) {
398
565
  action(item);
399
566
  }
400
567
  }
401
568
 
569
+ /**
570
+ * Converts the sequence to an array.
571
+ * @returns {T[]} The array.
572
+ */
402
573
  public toArray(): T[] {
403
574
  return Array.from(this);
404
575
  }
405
576
 
577
+ /**
578
+ * Converts the sequence to a record.
579
+ * @template R
580
+ * @param {UnaryFunction<T, string | symbol | number>} keySelector - Key selector.
581
+ * @param {UnaryFunction<T, R>} valueSelector - Value selector.
582
+ * @returns {Record<string | symbol | number, R>} The record.
583
+ */
406
584
  public toRecord<R>(keySelector: UnaryFunction<T, string | symbol | number>, valueSelector: UnaryFunction<T, R>): Record<string | symbol | number, R> {
407
585
  const output: Record<string | symbol | number, R> = {};
408
586
 
@@ -412,6 +590,13 @@ export class From<T> implements Iterable<T> {
412
590
  return output;
413
591
  }
414
592
 
593
+ /**
594
+ * Converts the sequence to a Map.
595
+ * @template RKey, RValue
596
+ * @param {UnaryFunction<T, RKey>} keySelector - Key selector.
597
+ * @param {UnaryFunction<T, RValue>} valueSelector - Value selector.
598
+ * @returns {Map<RKey, RValue>} The map.
599
+ */
415
600
  public toMap<RKey, RValue>(keySelector: UnaryFunction<T, RKey>, valueSelector: UnaryFunction<T, RValue>): Map<RKey, RValue> {
416
601
  const map = new Map<any, any>();
417
602
 
@@ -425,10 +610,20 @@ export class From<T> implements Iterable<T> {
425
610
  }
426
611
 
427
612
 
613
+ /**
614
+ * Returns elements that are instances of a specific primitive type.
615
+ * @param {string} type - The type string (e.g., 'string', 'number').
616
+ * @returns {From<T>} A new From instance.
617
+ */
428
618
  public instancesOf(type: string): From<T> {
429
619
  return this.filter(item => typeof item === type);
430
620
  }
431
621
 
622
+ /**
623
+ * Checks if all elements are instances of a specific class.
624
+ * @param {new (...args: any[]) => any} type - The class constructor.
625
+ * @returns {boolean} True if all elements are instances of the type.
626
+ */
432
627
  public allInstanceOf(type: new (...args: any[]) => any): boolean {
433
628
  for (let item of this) {
434
629
  if (!(item instanceof type)) {
@@ -438,6 +633,11 @@ export class From<T> implements Iterable<T> {
438
633
  return true;
439
634
  }
440
635
 
636
+ /**
637
+ * Returns distinct elements from the sequence.
638
+ * @param {EqualityComparer<T>} [eq_comparer] - Optional equality comparer.
639
+ * @returns {From<T>} A new From instance.
640
+ */
441
641
  public distinct(eq_comparer?: EqualityComparer<T>): From<T> {
442
642
 
443
643
  if (eq_comparer == null)
@@ -457,6 +657,12 @@ export class From<T> implements Iterable<T> {
457
657
  });
458
658
  }
459
659
 
660
+ /**
661
+ * Inserts an item at a specific index.
662
+ * @param {T} item - The item to insert.
663
+ * @param {number} index - The zero-based index.
664
+ * @returns {From<T>} A new From instance.
665
+ */
460
666
  public insert(item: T, index: number): From<T> {
461
667
 
462
668
  const self = this;
@@ -477,6 +683,11 @@ export class From<T> implements Iterable<T> {
477
683
  });
478
684
  }
479
685
 
686
+ /**
687
+ * Bypasses a specified number of elements in a sequence and then returns the remaining elements.
688
+ * @param {number} n - The number of elements to skip.
689
+ * @returns {From<T>} A new From instance.
690
+ */
480
691
  public skip(n: number): From<T> {
481
692
  const self = this;
482
693
  return From.fn<T>(function* () {
@@ -491,6 +702,11 @@ export class From<T> implements Iterable<T> {
491
702
  }
492
703
 
493
704
 
705
+ /**
706
+ * Concatenates two sequences.
707
+ * @param {Iterable<T>} other - The other sequence.
708
+ * @returns {From<T>} A new From instance.
709
+ */
494
710
  public union(other: Iterable<T>): From<T> {
495
711
  const self = this;
496
712
  return From.fn<T>(function* () {
@@ -499,6 +715,15 @@ export class From<T> implements Iterable<T> {
499
715
  });
500
716
  }
501
717
 
718
+ /**
719
+ * Correlates the elements of two sequences based on matching keys.
720
+ * @template T2, R, R2
721
+ * @param {Iterable<T2>} other - The other sequence.
722
+ * @param {UnaryFunction<T, R>} thisKeySelector - Key selector for this sequence.
723
+ * @param {UnaryFunction<T2, R>} otherKeySelector - Key selector for the other sequence.
724
+ * @param {(thisItem: T, otherItem: T2) => R2} resultSelector - Function to create a result element from two matching elements.
725
+ * @returns {From<R2>} A new From instance.
726
+ */
502
727
  public innerJoin<T2, R, R2>(other: Iterable<T2>, thisKeySelector: UnaryFunction<T, R>, otherKeySelector: UnaryFunction<T2, R>, resultSelector: (thisItem: T, otherItem: T2) => R2): From<R2> {
503
728
 
504
729
  const self = this;
@@ -513,6 +738,15 @@ export class From<T> implements Iterable<T> {
513
738
  });
514
739
  }
515
740
 
741
+ /**
742
+ * Performs a left join on two sequences.
743
+ * @template U, K, R
744
+ * @param {Iterable<U>} other - The other sequence.
745
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
746
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
747
+ * @param {(thisItem: T, otherItem: U | undefined) => R} resultSelector - Function to create a result element.
748
+ * @returns {From<R>} A new From instance.
749
+ */
516
750
  public leftJoin<U, K, R>(other: Iterable<U>, thisKeySelector: UnaryFunction<T, K>, otherKeySelector: UnaryFunction<U, K>, resultSelector: (thisItem: T, otherItem: U | undefined) => R): From<R> {
517
751
 
518
752
  const self = this;
@@ -526,6 +760,15 @@ export class From<T> implements Iterable<T> {
526
760
  }
527
761
 
528
762
 
763
+ /**
764
+ * Performs a left group join on two sequences.
765
+ * @template U, K, R
766
+ * @param {Iterable<U>} other - The other sequence.
767
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
768
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
769
+ * @param {(thisItem: T, otherItems: Array<U>) => R} resultSelector - Function to create a result element.
770
+ * @returns {From<R>} A new From instance.
771
+ */
529
772
  public leftGroupJoin<U, K, R>(other: Iterable<U>, thisKeySelector: UnaryFunction<T, K>, otherKeySelector: UnaryFunction<U, K>, resultSelector: (thisItem: T, otherItems: Array<U>) => R): From<R> {
530
773
 
531
774
  const self = this;
@@ -542,6 +785,15 @@ export class From<T> implements Iterable<T> {
542
785
  });
543
786
  }
544
787
 
788
+ /**
789
+ * Performs a right group join on two sequences.
790
+ * @template U, K, R
791
+ * @param {Iterable<U>} other - The other sequence.
792
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
793
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
794
+ * @param {(thisItems: Array<T>, otherItem: U) => R} resultSelector - Function to create a result element.
795
+ * @returns {From<R>} A new From instance.
796
+ */
545
797
  public rightGroupJoin<U, K, R>(other: Iterable<U>, thisKeySelector: UnaryFunction<T, K>, otherKeySelector: UnaryFunction<U, K>, resultSelector: (thisItems: Array<T>, otherItem: U) => R): From<R> {
546
798
 
547
799
  const self = this;
@@ -559,6 +811,15 @@ export class From<T> implements Iterable<T> {
559
811
  }
560
812
 
561
813
 
814
+ /**
815
+ * Performs a right join on two sequences.
816
+ * @template U, K, R
817
+ * @param {Iterable<U>} other - The other sequence.
818
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
819
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
820
+ * @param {(thisItem: T | undefined, otherItem: U) => R} resultSelector - Function to create a result element.
821
+ * @returns {From<R>} A new From instance.
822
+ */
562
823
  public rightJoin<U, K, R>(other: Iterable<U>, thisKeySelector: UnaryFunction<T, K>, otherKeySelector: UnaryFunction<U, K>, resultSelector: (thisItem: T | undefined, otherItem: U) => R): From<R> {
563
824
 
564
825
  const self = this;
@@ -573,18 +834,27 @@ export class From<T> implements Iterable<T> {
573
834
 
574
835
  }
575
836
 
837
+ /**
838
+ * Represents a group of elements that have a common key.
839
+ * @template TKey, T
840
+ */
576
841
  export class Grouping<TKey, T> extends From<T> {
577
842
 
578
843
  private readonly _key: TKey;
579
844
 
845
+ /**
846
+ * Gets the key of the group.
847
+ */
580
848
  public get key(): TKey {
581
849
  return this._key;
582
850
  }
583
851
 
852
+ /**
853
+ * @param {TKey} key - The group key.
854
+ * @param {Array<T>} values - The values in the group.
855
+ */
584
856
  public constructor(key: TKey, values: Array<T>) {
585
857
  super(() => values);
586
858
  this._key = key;
587
859
  }
588
-
589
-
590
860
  }
@@ -1,3 +1,4 @@
1
- export {default as DefaultWeakMap} from './default-weak-map.js'
2
- export {default as DefaultMap} from './default-map.js'
3
- export {default as CacheDictionary} from './cache-dictionary.js';
1
+ export {default as DefaultWeakMap} from './default-weak-map.js';
2
+ export {default as DefaultMap} from './default-map.js';
3
+ export {default as CacheDictionary} from './cache-dictionary.js';
4
+ export {default as from} from './from.js';