@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 +1 @@
1
- {"version":3,"file":"default-weak-map.js","sourceRoot":"","sources":["../../../src/collections/default-weak-map.ts"],"names":[],"mappings":";;AAWA,MAAqB,UAAgC,SAAQ,OAAa;IAOtE,YAAY,aAAkC,EAAE,UAAsC,SAAS;QAC3F,KAAK,EAAE,CAAC;QAER,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YAClB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC;gBACvC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;QAED,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;YACtC,MAAM,IAAI,SAAS,CAAC,wDAAwD,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACxC,CAAC;IAMQ,GAAG,CAAC,GAAM;QACf,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IAC3B,CAAC;CAGJ;AArCD,6BAqCC"}
1
+ {"version":3,"file":"default-weak-map.js","sourceRoot":"","sources":["../../../src/collections/default-weak-map.ts"],"names":[],"mappings":";;AAEA;;;;;;;GAOG;AACH,MAAqB,cAAoC,SAAQ,OAAa;IAG1E;;;OAGG;IACH,YAAY,aAAkC,EAAE,UAAsC,SAAS;QAC3F,KAAK,EAAE,CAAC;QAER,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YAClB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC;gBACvC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;QAED,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;YACtC,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACM,GAAG,CAAC,GAAM;QACf,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,iFAAiF;QACjF,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IAC3B,CAAC;CAGJ;AAxCD,iCAwCC","sourcesContent":["import type {Optional, UnaryFunction} from \"../types.js\";\r\n\r\n/**\r\n * DefaultWeakMap<K, V>\r\n * A WeakMap that automatically creates and saves a default value\r\n * when accessing a non-existent key with get(key).\r\n *\r\n * @template K - The type of the keys. Must be an object.\r\n * @template V - The type of the values.\r\n */\r\nexport default class DefaultWeakMap<K extends object, V> extends WeakMap<K, V> {\r\n private readonly _factoryMethod: (key: K) => V;\r\n\r\n /**\r\n * @param {UnaryFunction<K, V>} factoryMethod - Function that produces the default value for a key.\r\n * @param {Optional<Iterable<[K, V]>>} entries - Initial entries.\r\n */\r\n constructor(factoryMethod: UnaryFunction<K, V>, entries: Optional<Iterable<[K, V]>> = undefined) {\r\n super();\r\n\r\n if (entries != null) {\r\n for (const [key, value] of entries ?? []) {\r\n this.set(key, value);\r\n }\r\n }\r\n\r\n if (typeof factoryMethod !== \"function\") {\r\n throw new TypeError(\"DefaultWeakMap needs a factory (key => defaultValue).\");\r\n }\r\n this._factoryMethod = factoryMethod;\r\n }\r\n\r\n /**\r\n * Gets the value for the key. If it does not exist, it creates it using the factory,\r\n * saves it, and returns it.\r\n *\r\n * @param {K} key - The key to get.\r\n * @returns {V} The value associated with the key.\r\n */\r\n override get(key: K): V {\r\n if (!super.has(key)) {\r\n const value = this._factoryMethod(key);\r\n super.set(key, value);\r\n return value;\r\n }\r\n // ¡super.get puede devolver undefined si no existe! Pero ya comprobamos has(key)\r\n return super.get(key)!;\r\n }\r\n\r\n\r\n}\r\n"]}
@@ -5,8 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Grouping = exports.From = void 0;
7
7
  exports.default = from;
8
- const utilities_js_1 = require("./utilities.js");
9
- const order_js_1 = __importDefault(require("./order.js"));
8
+ const utilities_js_1 = require("../utilities.js");
9
+ const order_js_1 = __importDefault(require("../order.js"));
10
+ /**
11
+ * Creates a new From instance from an Iterable or a Supplier of an Iterable.
12
+ * @template T - The type of elements in the source.
13
+ * @param {Iterable<T> | Supplier<Iterable<T>>} source - The source data.
14
+ * @returns {From<T> | From<KeyValuePair<any, any>>} A new From instance.
15
+ * @throws {string} If source is null or invalid.
16
+ */
10
17
  function from(source) {
11
18
  if (source == null)
12
19
  throw "Source is null.";
@@ -20,7 +27,16 @@ function from(source) {
20
27
  }
21
28
  throw "Invalid source.";
22
29
  }
30
+ /**
31
+ * A LINQ-like wrapper for iterables that provides various transformation and query methods.
32
+ * @template T - The type of elements in the sequence.
33
+ */
23
34
  class From {
35
+ /**
36
+ * Creates a From instance from an object's entries.
37
+ * @param {any} obj - The object to convert to pairs.
38
+ * @returns {From<KeyValuePair<any, any>>} A From instance of key-value pairs.
39
+ */
24
40
  static object(obj) {
25
41
  return new From(function () {
26
42
  return (0, utilities_js_1.toPairs)(obj);
@@ -29,14 +45,30 @@ class From {
29
45
  constructor(fn) {
30
46
  this._fn = fn;
31
47
  }
48
+ /**
49
+ * Creates a From instance from a supplier function.
50
+ * @template T
51
+ * @param {Supplier<Iterable<T>>} callable - A function that returns an Iterable.
52
+ * @returns {From<T>} A new From instance.
53
+ */
32
54
  static fn(callable) {
33
55
  return new From(callable);
34
56
  }
35
- ;
57
+ /**
58
+ * Collects all elements into an array and returns a new From instance from it.
59
+ * Useful for freezing the sequence and preventing multiple iterations over a generator.
60
+ * @returns {From<T>} A new From instance with cached data.
61
+ */
36
62
  collect() {
37
63
  const cache = Array.from(this);
38
64
  return From.iterable(cache);
39
65
  }
66
+ /**
67
+ * Creates a From instance from an Iterable.
68
+ * @template T
69
+ * @param {Iterable<T>} iterable - The source iterable.
70
+ * @returns {From<T>} A new From instance.
71
+ */
40
72
  static iterable(iterable) {
41
73
  return From.fn(function* () {
42
74
  for (const item of iterable) {
@@ -44,7 +76,12 @@ class From {
44
76
  }
45
77
  });
46
78
  }
47
- ;
79
+ /**
80
+ * Maps each element of the sequence into a new form.
81
+ * @template R
82
+ * @param {UnaryFunction<T, R>} mapper - A transformation function.
83
+ * @returns {From<R>} A new From instance with the mapped elements.
84
+ */
48
85
  map(mapper) {
49
86
  const self = this;
50
87
  return From.fn(function* () {
@@ -56,6 +93,11 @@ class From {
56
93
  *[Symbol.iterator]() {
57
94
  yield* this._fn();
58
95
  }
96
+ /**
97
+ * Checks if all elements in the sequence satisfy the given predicate.
98
+ * @param {Predicate<T>} predicate - A function to test each element.
99
+ * @returns {boolean} True if all elements satisfy the predicate.
100
+ */
59
101
  all(predicate) {
60
102
  for (let item of this._fn()) {
61
103
  if (!predicate(item)) {
@@ -64,6 +106,12 @@ class From {
64
106
  }
65
107
  return true;
66
108
  }
109
+ /**
110
+ * Checks if any element in the sequence satisfies the given predicate.
111
+ * If no predicate is provided, checks if the sequence is not empty.
112
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
113
+ * @returns {boolean} True if any element satisfies the predicate.
114
+ */
67
115
  any(predicate = undefined) {
68
116
  for (let item of this) {
69
117
  if (predicate == null || predicate(item)) {
@@ -72,9 +120,19 @@ class From {
72
120
  }
73
121
  return false;
74
122
  }
123
+ /**
124
+ * Gets the number of elements in the sequence.
125
+ * @returns {number} The count of elements.
126
+ */
75
127
  get length() {
76
128
  return this.count();
77
129
  }
130
+ /**
131
+ * Counts the number of elements that satisfy the given predicate.
132
+ * If no predicate is provided, counts all elements.
133
+ * @param {Optional<Predicate<T>>} predicate - A function to test each element.
134
+ * @returns {number} The count of elements.
135
+ */
78
136
  count(predicate = undefined) {
79
137
  let output = 0;
80
138
  for (let item of this) {
@@ -84,6 +142,11 @@ class From {
84
142
  }
85
143
  return output;
86
144
  }
145
+ /**
146
+ * Filters the sequence based on a predicate.
147
+ * @param {Predicate<T>} predicate - A function to test each element.
148
+ * @returns {From<T>} A new From instance with the filtered elements.
149
+ */
87
150
  filter(predicate) {
88
151
  const self = this;
89
152
  return From.fn(function* () {
@@ -94,6 +157,11 @@ class From {
94
157
  }
95
158
  });
96
159
  }
160
+ /**
161
+ * Checks if the sequence contains a specific value.
162
+ * @param {T} value - The value to search for.
163
+ * @returns {boolean} True if the value is found.
164
+ */
97
165
  contains(value) {
98
166
  for (let item of this) {
99
167
  if (item === value) {
@@ -102,6 +170,11 @@ class From {
102
170
  }
103
171
  return false;
104
172
  }
173
+ /**
174
+ * Returns the first element of the sequence that satisfies a condition.
175
+ * @param {Predicate<T>} [predicate] - Optional condition.
176
+ * @returns {T | undefined} The first element or undefined.
177
+ */
105
178
  first(predicate) {
106
179
  if (predicate) {
107
180
  for (let item of this) {
@@ -111,12 +184,19 @@ class From {
111
184
  }
112
185
  }
113
186
  else {
187
+ // noinspection LoopStatementThatDoesntLoopJS
114
188
  for (let item of this) {
115
189
  return item;
116
190
  }
117
191
  }
118
192
  return undefined;
119
193
  }
194
+ /**
195
+ * Returns the only element of the sequence that satisfies a condition, or throws if more than one exists.
196
+ * @param {Predicate<T>} [predicate] - Optional condition.
197
+ * @returns {T | null} The single element or null if not found.
198
+ * @throws {Error} If more than one element is found.
199
+ */
120
200
  single(predicate) {
121
201
  let found = false;
122
202
  let output = null;
@@ -132,6 +212,7 @@ class From {
132
212
  }
133
213
  }
134
214
  else {
215
+ // noinspection LoopStatementThatDoesntLoopJS
135
216
  for (let item of this) {
136
217
  if (found) {
137
218
  throw new Error("Sequence contains more than one element.");
@@ -142,6 +223,11 @@ class From {
142
223
  }
143
224
  return output;
144
225
  }
226
+ /**
227
+ * Appends an item to the end of the sequence.
228
+ * @param {T} item - The item to append.
229
+ * @returns {From<T>} A new From instance.
230
+ */
145
231
  append(item) {
146
232
  const self = this;
147
233
  return From.fn(function* () {
@@ -151,6 +237,11 @@ class From {
151
237
  yield item;
152
238
  });
153
239
  }
240
+ /**
241
+ * Prepends an item to the beginning of the sequence.
242
+ * @param {T} item - The item to prepend.
243
+ * @returns {From<T>} A new From instance.
244
+ */
154
245
  prepend(item) {
155
246
  const self = this;
156
247
  return From.fn(function* () {
@@ -160,6 +251,11 @@ class From {
160
251
  }
161
252
  });
162
253
  }
254
+ /**
255
+ * Gets the element at a specific index.
256
+ * @param {number} index - The zero-based index.
257
+ * @returns {T | undefined} The element at the index or undefined.
258
+ */
163
259
  at(index) {
164
260
  let idx = 0;
165
261
  for (let item of this) {
@@ -169,6 +265,11 @@ class From {
169
265
  }
170
266
  return undefined;
171
267
  }
268
+ /**
269
+ * Returns the last element of the sequence that satisfies a condition.
270
+ * @param {Predicate<T>} [predicate] - Optional condition.
271
+ * @returns {T | undefined} The last element or undefined.
272
+ */
172
273
  last(predicate) {
173
274
  let last = undefined;
174
275
  if (predicate)
@@ -184,6 +285,12 @@ class From {
184
285
  }
185
286
  return last;
186
287
  }
288
+ /**
289
+ * Projects each element of a sequence to an Iterable and flattens the resulting sequences into one sequence.
290
+ * @template R
291
+ * @param {UnaryFunction<T, Iterable<R>>} mapper - A transformation function.
292
+ * @returns {From<R>} A new From instance.
293
+ */
187
294
  mapMany(mapper) {
188
295
  const self = this;
189
296
  return From.fn(function* () {
@@ -195,6 +302,10 @@ class From {
195
302
  }
196
303
  });
197
304
  }
305
+ /**
306
+ * Flattens a sequence of iterables.
307
+ * @returns {From<any>} A new From instance.
308
+ */
198
309
  flatten() {
199
310
  const self = this;
200
311
  return From.fn(function* () {
@@ -206,6 +317,11 @@ class From {
206
317
  }
207
318
  });
208
319
  }
320
+ /**
321
+ * Calculates the sum of the elements in the sequence.
322
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
323
+ * @returns {number} The sum.
324
+ */
209
325
  sum(mapper) {
210
326
  let total = 0;
211
327
  if (mapper)
@@ -218,6 +334,11 @@ class From {
218
334
  }
219
335
  return total;
220
336
  }
337
+ /**
338
+ * Calculates the average of the elements in the sequence.
339
+ * @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
340
+ * @returns {number} The average.
341
+ */
221
342
  avg(mapper) {
222
343
  let total = 0;
223
344
  let count = 0;
@@ -233,6 +354,11 @@ class From {
233
354
  }
234
355
  return count > 0 ? total / count : 0;
235
356
  }
357
+ /**
358
+ * Returns the maximum value in the sequence.
359
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
360
+ * @returns {number} The maximum value.
361
+ */
236
362
  max(mapper) {
237
363
  let max = -Infinity;
238
364
  for (let item of this) {
@@ -241,6 +367,11 @@ class From {
241
367
  }
242
368
  return max;
243
369
  }
370
+ /**
371
+ * Returns the minimum value in the sequence.
372
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
373
+ * @returns {number} The minimum value.
374
+ */
244
375
  min(mapper) {
245
376
  let min = Infinity;
246
377
  for (let item of this) {
@@ -249,6 +380,11 @@ class From {
249
380
  }
250
381
  return min;
251
382
  }
383
+ /**
384
+ * Returns the element with the maximum value.
385
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
386
+ * @returns {T | undefined} The element with the maximum value.
387
+ */
252
388
  maxBy(mapper) {
253
389
  let max = -Infinity;
254
390
  let maxItem;
@@ -261,6 +397,11 @@ class From {
261
397
  }
262
398
  return maxItem;
263
399
  }
400
+ /**
401
+ * Returns the element with the minimum value.
402
+ * @param {UnaryFunction<T, number>} mapper - Projection function.
403
+ * @returns {T | undefined} The element with the minimum value.
404
+ */
264
405
  minBy(mapper) {
265
406
  let min = Infinity;
266
407
  let minItem;
@@ -273,6 +414,13 @@ class From {
273
414
  }
274
415
  return minItem;
275
416
  }
417
+ /**
418
+ * Sorts the elements of the sequence.
419
+ * @template R
420
+ * @param {UnaryFunction<T, R>} mapper - Projection function for the key to sort by.
421
+ * @param {Order} [order] - Ascending or Descending.
422
+ * @returns {From<T>} A new From instance.
423
+ */
276
424
  orderBy(mapper, order = order_js_1.default.Ascending) {
277
425
  const array = Array.from(this._fn());
278
426
  if (order == order_js_1.default.Ascending) {
@@ -294,6 +442,13 @@ class From {
294
442
  }
295
443
  return From.iterable(array);
296
444
  }
445
+ /**
446
+ * Groups the elements of the sequence.
447
+ * @template TKey
448
+ * @param {UnaryFunction<T, TKey>} keySelector - Function to extract the key for each element.
449
+ * @param {EqualityComparer<TKey>} [equalityComparer] - Optional comparer for keys.
450
+ * @returns {From<Grouping<TKey, T>>} A new From instance.
451
+ */
297
452
  groupBy(keySelector, equalityComparer) {
298
453
  equalityComparer = (equalityComparer == null ? utilities_js_1.shallowEqual : equalityComparer);
299
454
  const self = this;
@@ -316,6 +471,11 @@ class From {
316
471
  yield* groups.map(([key, values]) => new Grouping(key, values));
317
472
  });
318
473
  }
474
+ /**
475
+ * Returns a specified number of contiguous elements from the start of the sequence.
476
+ * @param {number} n - The number of elements to return.
477
+ * @returns {From<T>} A new From instance.
478
+ */
319
479
  head(n) {
320
480
  const self = this;
321
481
  return From.fn(function* () {
@@ -330,6 +490,11 @@ class From {
330
490
  }
331
491
  });
332
492
  }
493
+ /**
494
+ * Returns a specified number of contiguous elements from the end of the sequence.
495
+ * @param {number} n - The number of elements to return.
496
+ * @returns {From<T>} A new From instance.
497
+ */
333
498
  tail(n) {
334
499
  const self = this;
335
500
  return From.fn(function* () {
@@ -343,14 +508,29 @@ class From {
343
508
  yield* buffer;
344
509
  });
345
510
  }
511
+ /**
512
+ * Performs the specified action on each element of the sequence.
513
+ * @param {Consumer<T>} action - The action to perform.
514
+ */
346
515
  forEach(action) {
347
516
  for (let item of this) {
348
517
  action(item);
349
518
  }
350
519
  }
520
+ /**
521
+ * Converts the sequence to an array.
522
+ * @returns {T[]} The array.
523
+ */
351
524
  toArray() {
352
525
  return Array.from(this);
353
526
  }
527
+ /**
528
+ * Converts the sequence to a record.
529
+ * @template R
530
+ * @param {UnaryFunction<T, string | symbol | number>} keySelector - Key selector.
531
+ * @param {UnaryFunction<T, R>} valueSelector - Value selector.
532
+ * @returns {Record<string | symbol | number, R>} The record.
533
+ */
354
534
  toRecord(keySelector, valueSelector) {
355
535
  const output = {};
356
536
  for (let item of this) {
@@ -358,6 +538,13 @@ class From {
358
538
  }
359
539
  return output;
360
540
  }
541
+ /**
542
+ * Converts the sequence to a Map.
543
+ * @template RKey, RValue
544
+ * @param {UnaryFunction<T, RKey>} keySelector - Key selector.
545
+ * @param {UnaryFunction<T, RValue>} valueSelector - Value selector.
546
+ * @returns {Map<RKey, RValue>} The map.
547
+ */
361
548
  toMap(keySelector, valueSelector) {
362
549
  const map = new Map();
363
550
  for (let item of this) {
@@ -367,9 +554,19 @@ class From {
367
554
  }
368
555
  return map;
369
556
  }
557
+ /**
558
+ * Returns elements that are instances of a specific primitive type.
559
+ * @param {string} type - The type string (e.g., 'string', 'number').
560
+ * @returns {From<T>} A new From instance.
561
+ */
370
562
  instancesOf(type) {
371
563
  return this.filter(item => typeof item === type);
372
564
  }
565
+ /**
566
+ * Checks if all elements are instances of a specific class.
567
+ * @param {new (...args: any[]) => any} type - The class constructor.
568
+ * @returns {boolean} True if all elements are instances of the type.
569
+ */
373
570
  allInstanceOf(type) {
374
571
  for (let item of this) {
375
572
  if (!(item instanceof type)) {
@@ -378,6 +575,11 @@ class From {
378
575
  }
379
576
  return true;
380
577
  }
578
+ /**
579
+ * Returns distinct elements from the sequence.
580
+ * @param {EqualityComparer<T>} [eq_comparer] - Optional equality comparer.
581
+ * @returns {From<T>} A new From instance.
582
+ */
381
583
  distinct(eq_comparer) {
382
584
  if (eq_comparer == null)
383
585
  eq_comparer = utilities_js_1.shallowEqual;
@@ -392,6 +594,12 @@ class From {
392
594
  }
393
595
  });
394
596
  }
597
+ /**
598
+ * Inserts an item at a specific index.
599
+ * @param {T} item - The item to insert.
600
+ * @param {number} index - The zero-based index.
601
+ * @returns {From<T>} A new From instance.
602
+ */
395
603
  insert(item, index) {
396
604
  const self = this;
397
605
  return From.fn(function* () {
@@ -410,6 +618,11 @@ class From {
410
618
  }
411
619
  });
412
620
  }
621
+ /**
622
+ * Bypasses a specified number of elements in a sequence and then returns the remaining elements.
623
+ * @param {number} n - The number of elements to skip.
624
+ * @returns {From<T>} A new From instance.
625
+ */
413
626
  skip(n) {
414
627
  const self = this;
415
628
  return From.fn(function* () {
@@ -422,6 +635,11 @@ class From {
422
635
  }
423
636
  });
424
637
  }
638
+ /**
639
+ * Concatenates two sequences.
640
+ * @param {Iterable<T>} other - The other sequence.
641
+ * @returns {From<T>} A new From instance.
642
+ */
425
643
  union(other) {
426
644
  const self = this;
427
645
  return From.fn(function* () {
@@ -429,6 +647,15 @@ class From {
429
647
  yield* other;
430
648
  });
431
649
  }
650
+ /**
651
+ * Correlates the elements of two sequences based on matching keys.
652
+ * @template T2, R, R2
653
+ * @param {Iterable<T2>} other - The other sequence.
654
+ * @param {UnaryFunction<T, R>} thisKeySelector - Key selector for this sequence.
655
+ * @param {UnaryFunction<T2, R>} otherKeySelector - Key selector for the other sequence.
656
+ * @param {(thisItem: T, otherItem: T2) => R2} resultSelector - Function to create a result element from two matching elements.
657
+ * @returns {From<R2>} A new From instance.
658
+ */
432
659
  innerJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
433
660
  const self = this;
434
661
  return From.fn(() => {
@@ -441,6 +668,15 @@ class From {
441
668
  .map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
442
669
  });
443
670
  }
671
+ /**
672
+ * Performs a left join on two sequences.
673
+ * @template U, K, R
674
+ * @param {Iterable<U>} other - The other sequence.
675
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
676
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
677
+ * @param {(thisItem: T, otherItem: U | undefined) => R} resultSelector - Function to create a result element.
678
+ * @returns {From<R>} A new From instance.
679
+ */
444
680
  leftJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
445
681
  const self = this;
446
682
  return From.fn(() => {
@@ -451,6 +687,15 @@ class From {
451
687
  return Array.from(self).map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
452
688
  });
453
689
  }
690
+ /**
691
+ * Performs a left group join on two sequences.
692
+ * @template U, K, R
693
+ * @param {Iterable<U>} other - The other sequence.
694
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
695
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
696
+ * @param {(thisItem: T, otherItems: Array<U>) => R} resultSelector - Function to create a result element.
697
+ * @returns {From<R>} A new From instance.
698
+ */
454
699
  leftGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
455
700
  const self = this;
456
701
  return From.fn(() => {
@@ -465,6 +710,15 @@ class From {
465
710
  return Array.from(self).map(item => resultSelector(item, otherByKeys.get(thisKeySelector(item)) || []));
466
711
  });
467
712
  }
713
+ /**
714
+ * Performs a right group join on two sequences.
715
+ * @template U, K, R
716
+ * @param {Iterable<U>} other - The other sequence.
717
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
718
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
719
+ * @param {(thisItems: Array<T>, otherItem: U) => R} resultSelector - Function to create a result element.
720
+ * @returns {From<R>} A new From instance.
721
+ */
468
722
  rightGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
469
723
  const self = this;
470
724
  return From.fn(() => {
@@ -479,6 +733,15 @@ class From {
479
733
  return Array.from(other).map(item => resultSelector(thisByKeys.get(otherKeySelector(item)) || [], item));
480
734
  });
481
735
  }
736
+ /**
737
+ * Performs a right join on two sequences.
738
+ * @template U, K, R
739
+ * @param {Iterable<U>} other - The other sequence.
740
+ * @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
741
+ * @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
742
+ * @param {(thisItem: T | undefined, otherItem: U) => R} resultSelector - Function to create a result element.
743
+ * @returns {From<R>} A new From instance.
744
+ */
482
745
  rightJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
483
746
  const self = this;
484
747
  return From.fn(() => {
@@ -491,10 +754,21 @@ class From {
491
754
  }
492
755
  }
493
756
  exports.From = From;
757
+ /**
758
+ * Represents a group of elements that have a common key.
759
+ * @template TKey, T
760
+ */
494
761
  class Grouping extends From {
762
+ /**
763
+ * Gets the key of the group.
764
+ */
495
765
  get key() {
496
766
  return this._key;
497
767
  }
768
+ /**
769
+ * @param {TKey} key - The group key.
770
+ * @param {Array<T>} values - The values in the group.
771
+ */
498
772
  constructor(key, values) {
499
773
  super(() => values);
500
774
  this._key = key;