@develia/commons 0.3.44 → 0.4.0

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 (189) hide show
  1. package/dist/cjs/array.js +44 -0
  2. package/dist/cjs/array.js.map +1 -0
  3. package/dist/cjs/async-pool-executor.js +49 -0
  4. package/dist/cjs/async-pool-executor.js.map +1 -0
  5. package/dist/cjs/cache-dictionary.js +67 -0
  6. package/dist/cjs/cache-dictionary.js.map +1 -0
  7. package/dist/cjs/clean-url-search-params.js +10 -0
  8. package/dist/cjs/clean-url-search-params.js.map +1 -0
  9. package/dist/cjs/collections/default-map.js +21 -0
  10. package/dist/cjs/collections/default-map.js.map +1 -0
  11. package/dist/cjs/collections/lazy-map.js +22 -0
  12. package/dist/cjs/collections/lazy-map.js.map +1 -0
  13. package/dist/cjs/collections.js +11 -0
  14. package/dist/cjs/collections.js.map +1 -0
  15. package/dist/cjs/from.js +504 -0
  16. package/dist/cjs/from.js.map +1 -0
  17. package/dist/cjs/index.js +73 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/key-value-pair.js +16 -0
  20. package/dist/cjs/key-value-pair.js.map +1 -0
  21. package/dist/cjs/lazy.js +25 -0
  22. package/dist/cjs/lazy.js.map +1 -0
  23. package/dist/cjs/math.js +15 -0
  24. package/dist/cjs/math.js.map +1 -0
  25. package/dist/cjs/order.js +9 -0
  26. package/dist/cjs/order.js.map +1 -0
  27. package/dist/cjs/patch.js +44 -0
  28. package/dist/cjs/patch.js.map +1 -0
  29. package/dist/cjs/stopwatch.js +36 -0
  30. package/dist/cjs/stopwatch.js.map +1 -0
  31. package/dist/cjs/string.js +29 -0
  32. package/dist/cjs/string.js.map +1 -0
  33. package/dist/cjs/timer.js +50 -0
  34. package/dist/cjs/timer.js.map +1 -0
  35. package/dist/cjs/timespan.js +152 -0
  36. package/dist/cjs/timespan.js.map +1 -0
  37. package/dist/cjs/type.js +16 -0
  38. package/dist/cjs/type.js.map +1 -0
  39. package/dist/cjs/types.js +3 -0
  40. package/dist/cjs/types.js.map +1 -0
  41. package/dist/cjs/utilities.js +309 -0
  42. package/dist/cjs/utilities.js.map +1 -0
  43. package/dist/esm/array.js +38 -0
  44. package/dist/esm/array.js.map +1 -0
  45. package/dist/esm/async-pool-executor.js +46 -0
  46. package/dist/esm/async-pool-executor.js.map +1 -0
  47. package/dist/esm/cache-dictionary.js +64 -0
  48. package/dist/esm/cache-dictionary.js.map +1 -0
  49. package/dist/esm/clean-url-search-params.js +7 -0
  50. package/dist/esm/clean-url-search-params.js.map +1 -0
  51. package/dist/esm/collections/default-map.js +18 -0
  52. package/dist/esm/collections/default-map.js.map +1 -0
  53. package/dist/esm/collections/lazy-map.js +19 -0
  54. package/dist/esm/collections/lazy-map.js.map +1 -0
  55. package/dist/esm/collections.js +3 -0
  56. package/dist/esm/collections.js.map +1 -0
  57. package/dist/esm/from.js +495 -0
  58. package/dist/esm/from.js.map +1 -0
  59. package/dist/esm/index.js +19 -0
  60. package/dist/esm/index.js.map +1 -0
  61. package/dist/esm/key-value-pair.js +13 -0
  62. package/dist/esm/key-value-pair.js.map +1 -0
  63. package/dist/esm/lazy.js +22 -0
  64. package/dist/esm/lazy.js.map +1 -0
  65. package/dist/esm/math.js +11 -0
  66. package/dist/esm/math.js.map +1 -0
  67. package/dist/esm/order.js +7 -0
  68. package/dist/esm/order.js.map +1 -0
  69. package/dist/esm/patch.js +40 -0
  70. package/dist/esm/patch.js.map +1 -0
  71. package/dist/esm/stopwatch.js +30 -0
  72. package/dist/esm/stopwatch.js.map +1 -0
  73. package/dist/esm/string.js +24 -0
  74. package/dist/esm/string.js.map +1 -0
  75. package/dist/esm/timer.js +47 -0
  76. package/dist/esm/timer.js.map +1 -0
  77. package/dist/esm/timespan.js +150 -0
  78. package/dist/esm/timespan.js.map +1 -0
  79. package/dist/esm/type.js +14 -0
  80. package/dist/esm/type.js.map +1 -0
  81. package/dist/esm/types.js +2 -0
  82. package/dist/esm/types.js.map +1 -0
  83. package/dist/esm/utilities.js +277 -0
  84. package/dist/esm/utilities.js.map +1 -0
  85. package/dist/types/array.d.ts +6 -0
  86. package/dist/types/array.d.ts.map +1 -0
  87. package/dist/types/async-pool-executor.d.ts +14 -0
  88. package/dist/types/async-pool-executor.d.ts.map +1 -0
  89. package/dist/types/cache-dictionary.d.ts +16 -0
  90. package/dist/types/cache-dictionary.d.ts.map +1 -0
  91. package/dist/types/clean-url-search-params.d.ts +4 -0
  92. package/dist/types/clean-url-search-params.d.ts.map +1 -0
  93. package/dist/types/collections/default-map.d.ts +7 -0
  94. package/dist/types/collections/default-map.d.ts.map +1 -0
  95. package/dist/types/collections/lazy-map.d.ts +6 -0
  96. package/dist/types/collections/lazy-map.d.ts.map +1 -0
  97. package/dist/types/collections.d.ts +3 -0
  98. package/dist/types/collections.d.ts.map +1 -0
  99. package/dist/types/from.d.ts +59 -0
  100. package/dist/types/from.d.ts.map +1 -0
  101. package/dist/types/index.d.ts +19 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/types/key-value-pair.d.ts +8 -0
  104. package/dist/types/key-value-pair.d.ts.map +1 -0
  105. package/dist/types/lazy.d.ts +11 -0
  106. package/dist/types/lazy.d.ts.map +1 -0
  107. package/dist/types/math.d.ts +3 -0
  108. package/dist/types/math.d.ts.map +1 -0
  109. package/dist/types/order.d.ts +6 -0
  110. package/dist/types/order.d.ts.map +1 -0
  111. package/dist/types/patch.d.ts +8 -0
  112. package/dist/types/patch.d.ts.map +1 -0
  113. package/dist/types/stopwatch.d.ts +10 -0
  114. package/dist/types/stopwatch.d.ts.map +1 -0
  115. package/dist/types/string.d.ts +4 -0
  116. package/dist/types/string.d.ts.map +1 -0
  117. package/dist/types/timer.d.ts +15 -0
  118. package/dist/types/timer.d.ts.map +1 -0
  119. package/dist/types/timespan.d.ts +47 -0
  120. package/dist/types/timespan.d.ts.map +1 -0
  121. package/dist/types/type.d.ts +13 -0
  122. package/dist/types/type.d.ts.map +1 -0
  123. package/dist/types/types.d.ts +14 -0
  124. package/dist/types/types.d.ts.map +1 -0
  125. package/dist/types/utilities.d.ts +31 -0
  126. package/dist/types/utilities.d.ts.map +1 -0
  127. package/dist/web/array.js +38 -0
  128. package/dist/web/array.js.map +1 -0
  129. package/dist/web/async-pool-executor.js +46 -0
  130. package/dist/web/async-pool-executor.js.map +1 -0
  131. package/dist/web/cache-dictionary.js +64 -0
  132. package/dist/web/cache-dictionary.js.map +1 -0
  133. package/dist/web/clean-url-search-params.js +7 -0
  134. package/dist/web/clean-url-search-params.js.map +1 -0
  135. package/dist/web/collections/default-map.js +18 -0
  136. package/dist/web/collections/default-map.js.map +1 -0
  137. package/dist/web/collections/lazy-map.js +19 -0
  138. package/dist/web/collections/lazy-map.js.map +1 -0
  139. package/dist/web/collections.js +3 -0
  140. package/dist/web/collections.js.map +1 -0
  141. package/dist/web/from.js +496 -0
  142. package/dist/web/from.js.map +1 -0
  143. package/dist/web/index.js +19 -0
  144. package/dist/web/index.js.map +1 -0
  145. package/dist/web/key-value-pair.js +13 -0
  146. package/dist/web/key-value-pair.js.map +1 -0
  147. package/dist/web/lazy.js +22 -0
  148. package/dist/web/lazy.js.map +1 -0
  149. package/dist/web/math.js +11 -0
  150. package/dist/web/math.js.map +1 -0
  151. package/dist/web/order.js +7 -0
  152. package/dist/web/order.js.map +1 -0
  153. package/dist/web/patch.js +40 -0
  154. package/dist/web/patch.js.map +1 -0
  155. package/dist/web/stopwatch.js +30 -0
  156. package/dist/web/stopwatch.js.map +1 -0
  157. package/dist/web/string.js +24 -0
  158. package/dist/web/string.js.map +1 -0
  159. package/dist/web/timer.js +47 -0
  160. package/dist/web/timer.js.map +1 -0
  161. package/dist/web/timespan.js +150 -0
  162. package/dist/web/timespan.js.map +1 -0
  163. package/dist/web/type.js +14 -0
  164. package/dist/web/type.js.map +1 -0
  165. package/dist/web/types.js +2 -0
  166. package/dist/web/types.js.map +1 -0
  167. package/dist/web/utilities.js +277 -0
  168. package/dist/web/utilities.js.map +1 -0
  169. package/package.json +25 -12
  170. package/src/array.ts +49 -0
  171. package/src/async-pool-executor.ts +2 -2
  172. package/src/collections/default-map.ts +42 -0
  173. package/src/collections/lazy-map.ts +24 -0
  174. package/src/collections.ts +2 -24
  175. package/src/from.ts +4 -4
  176. package/src/index.ts +28 -22
  177. package/src/lazy.ts +1 -1
  178. package/src/patch.ts +80 -0
  179. package/src/stopwatch.ts +1 -1
  180. package/src/{typing.ts → type.ts} +3 -1
  181. package/src/types.ts +4 -1
  182. package/src/utilities.ts +19 -18
  183. package/dist/develia-commons.js +0 -1690
  184. package/dist/develia-commons.min.js +0 -1
  185. package/dist/index.cjs.js +0 -1688
  186. package/dist/index.cjs.js.map +0 -1
  187. package/dist/index.esm.js +0 -1641
  188. package/dist/index.esm.js.map +0 -1
  189. package/src/array-manipulator.ts +0 -159
@@ -1,1690 +0,0 @@
1
- (function (exports) {
2
- 'use strict';
3
-
4
- /**
5
- * Represents different types in JavaScript.
6
- * @enum {string}
7
- */
8
- exports.Type = void 0;
9
- (function (Type) {
10
- Type["Undefined"] = "undefined";
11
- Type["Number"] = "number";
12
- Type["String"] = "string";
13
- Type["Boolean"] = "boolean";
14
- Type["Object"] = "object";
15
- Type["Function"] = "function";
16
- Type["Symbol"] = "symbol";
17
- Type["BigInt"] = "bigint";
18
- Type["Null"] = "null";
19
- })(exports.Type || (exports.Type = {}));
20
-
21
- /**
22
- * Represents a pair of key and value.
23
- *
24
- * @template TKey The type of the key.
25
- * @template TValue The type of the value.
26
- */
27
- class KeyValuePair {
28
- get value() {
29
- return this._value;
30
- }
31
- get key() {
32
- return this._key;
33
- }
34
- constructor(key, value) {
35
- this._key = key;
36
- this._value = value;
37
- }
38
- }
39
-
40
- // noinspection JSUnusedGlobalSymbols
41
- /**
42
- * Checks if an object is iterable.
43
- *
44
- * @param {any} obj - The object to check.
45
- * @return {boolean} - Returns true if the object is iterable, otherwise false.
46
- */
47
- function isIterable(obj) {
48
- return obj[Symbol.iterator] === 'function';
49
- }
50
- /**
51
- * Checks if a given value is a string.
52
- *
53
- * @param {*} value - The value to check.
54
- * @return {boolean} - Returns true if the value is a string, otherwise returns false.
55
- */
56
- function isString(value) {
57
- return typeof value === 'string';
58
- }
59
- /**
60
- * Checks if a value is a number.
61
- *
62
- * @param {any} value - The value to check.
63
- * @return {boolean} - Returns true if the value is a number, otherwise false.
64
- */
65
- function isNumber(value) {
66
- return typeof value === 'number';
67
- }
68
- /**
69
- * Checks if a given value is a boolean.
70
- *
71
- * @param {any} value - The value to be checked.
72
- *
73
- * @return {boolean} - Returns true if the value is a boolean, otherwise false.
74
- */
75
- function isBoolean(value) {
76
- return typeof value === 'boolean';
77
- }
78
- /**
79
- * Checks if a value is an object.
80
- * @param {any} value - The value to be checked.
81
- * @returns {boolean} - Returns true if the value is an object, otherwise returns false.
82
- */
83
- function isObject(value) {
84
- return value != null && typeof value === 'object' && !Array.isArray(value);
85
- }
86
- /**
87
- * Determines if a value is an array.
88
- *
89
- * @param value - The value to be checked.
90
- *
91
- * @return Whether the value is an array.
92
- */
93
- function isArray(value) {
94
- return Array.isArray(value);
95
- }
96
- /**
97
- * Checks if a value is a function.
98
- *
99
- * @param {any} value - The value to be checked.
100
- * @return {boolean} - Returns true if the value is a function, otherwise returns false.
101
- */
102
- function isFunction(value) {
103
- return typeof value === 'function';
104
- }
105
- /**
106
- * Compares two objects or arrays to check if they have the same fields and values,
107
- * or the same elements if they are arrays (deep equality check).
108
- *
109
- * @param {any} a - The first object or array.
110
- * @param {any} b - The second object or array.
111
- * @return {boolean} - Returns true if the objects/arrays are deeply equal, otherwise false.
112
- */
113
- function deepEqual(a, b) {
114
- if (a === b) {
115
- return true;
116
- }
117
- if (a === null || b === null || typeof a !== typeof b) {
118
- return false;
119
- }
120
- if (Array.isArray(a) && Array.isArray(b)) {
121
- if (a.length !== b.length) {
122
- return false;
123
- }
124
- for (let i = 0; i < a.length; i++) {
125
- if (!deepEqual(a[i], b[i])) {
126
- return false;
127
- }
128
- }
129
- return true;
130
- }
131
- if (typeof a === "object" && typeof b === "object") {
132
- const keysA = Object.keys(a);
133
- const keysB = Object.keys(b);
134
- if (keysA.length !== keysB.length) {
135
- return false;
136
- }
137
- for (const key of keysA) {
138
- if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {
139
- return false;
140
- }
141
- }
142
- return true;
143
- }
144
- return false;
145
- }
146
- /**
147
- * Submits an HTML form programmatically using the specified HTTP method (default is POST),
148
- * without using AJAX. Supports nested objects and arrays using bracket notation (e.g., `user[name]`, `tags[]`).
149
- *
150
- * @param url - The destination URL where the form will be submitted.
151
- * @param data - An object containing key-value pairs. Supports nested structures and arrays.
152
- * @param method - HTTP method to use: 'POST' or 'GET' (default: 'POST').
153
- * @param target - Optional parameter specifying the target for the form submission (e.g., '_blank', '_self', '_parent', '_top').
154
- */
155
- function submitForm(url, data, method = 'POST', target) {
156
- const form = document.createElement('form');
157
- form.method = method.toUpperCase();
158
- form.action = url;
159
- form.style.display = 'none';
160
- if (target) {
161
- form.target = target;
162
- }
163
- /**
164
- * Recursively appends inputs to the form, supporting nested keys and arrays.
165
- * @param keyPrefix - Key path, e.g., 'user[name]' or 'tags[]'
166
- * @param value - The value to append (can be nested)
167
- */
168
- const appendInputs = (keyPrefix, value) => {
169
- if (Array.isArray(value)) {
170
- value.forEach(val => {
171
- appendInputs(`${keyPrefix}[]`, val);
172
- });
173
- }
174
- else if (typeof value === 'object' && value !== null) {
175
- for (const subKey in value) {
176
- if (value.hasOwnProperty(subKey)) {
177
- appendInputs(`${keyPrefix}[${subKey}]`, value[subKey]);
178
- }
179
- }
180
- }
181
- else {
182
- const input = document.createElement('input');
183
- input.type = 'hidden';
184
- input.name = keyPrefix;
185
- input.value = String(value);
186
- form.appendChild(input);
187
- }
188
- };
189
- for (const key in data) {
190
- if (data.hasOwnProperty(key)) {
191
- appendInputs(key, data[key]);
192
- }
193
- }
194
- document.body.appendChild(form);
195
- form.submit();
196
- }
197
- /**
198
- * Compares two objects or arrays to check if they have the same immediate fields and values,
199
- * or the same immediate elements if they are arrays (shallow equality check).
200
- *
201
- * @param {any} a - The first object or array.
202
- * @param {any} b - The second object or array.
203
- * @return {boolean} - Returns true if the objects/arrays are shallowly equal, otherwise false.
204
- */
205
- function shallowEqual(a, b) {
206
- if (a === b) {
207
- return true;
208
- }
209
- if (a === null || b === null || typeof a !== typeof b) {
210
- return false;
211
- }
212
- if (Array.isArray(a) && Array.isArray(b)) {
213
- if (a.length !== b.length) {
214
- return false;
215
- }
216
- return a.every((value, index) => value === b[index]);
217
- }
218
- if (typeof a === "object" && typeof b === "object") {
219
- const keysA = Object.keys(a);
220
- const keysB = Object.keys(b);
221
- if (keysA.length !== keysB.length) {
222
- return false;
223
- }
224
- return keysA.every(key => b.hasOwnProperty(key) && a[key] === b[key]);
225
- }
226
- return false;
227
- }
228
- /**
229
- * Pauses the execution of an asynchronous function for a specified duration.
230
- *
231
- * @param {number} ms - The delay duration in milliseconds.
232
- * @return {Promise<void>} A promise that resolves after the specified delay.
233
- */
234
- async function delay(ms) {
235
- await new Promise(resolve => setTimeout(resolve, ms));
236
- }
237
- /**
238
- * Checks if a value is undefined.
239
- *
240
- * @param {any} value - The value to check.
241
- * @returns {boolean} - True if the value is undefined, false otherwise.
242
- */
243
- function isUndefined(value) {
244
- return typeof value === 'undefined';
245
- }
246
- /**
247
- * Checks if a value is defined or not.
248
- *
249
- * @param {any} value - The value to be checked.
250
- *
251
- * @return {boolean} - True if the value is defined, false otherwise.
252
- */
253
- function isDefined(value) {
254
- return typeof value !== 'undefined';
255
- }
256
- /**
257
- * Checks if a given value is null.
258
- *
259
- * @param {any} value - The value to check for null.
260
- * @return {boolean} - Returns true if the value is null, otherwise returns false.
261
- */
262
- function isNull(value) {
263
- return value === null;
264
- }
265
- /**
266
- * Determines whether the given value is of type bigint.
267
- * @param {any} value - The value to be checked.
268
- * @return {boolean} - Returns true if the value is of type bigint, false otherwise.
269
- */
270
- function isBigInt(value) {
271
- return typeof value === 'bigint';
272
- }
273
- /**
274
- * Checks if a given value is a symbol.
275
- *
276
- * @param {any} value - The value to be checked.
277
- * @return {boolean} - Returns true if the value is a symbol, false otherwise.
278
- */
279
- function isSymbol(value) {
280
- return typeof value === 'symbol';
281
- }
282
- /**
283
- * Checks if a value is null or undefined.
284
- *
285
- * @param {any} value - The value to check.
286
- * @return {boolean} - Returns true if the value is null or undefined, false otherwise.
287
- */
288
- function isNullOrUndefined(value) {
289
- return value === null || typeof value === 'undefined';
290
- }
291
- /**
292
- * Checks if a given value is empty.
293
- *
294
- * @param {any} value - The value to check.
295
- * @return {boolean} - Returns true if the value is empty, otherwise returns false.
296
- */
297
- function isEmpty(value) {
298
- return (Array.isArray(value) && value.length === 0) ||
299
- (typeof value === 'string' && value === '') ||
300
- value === null || typeof value === 'undefined';
301
- }
302
- /**
303
- * Check if a value is empty or contains only whitespace characters.
304
- *
305
- * @param {any} value - The value to check.
306
- * @return {boolean} Returns true if the value is empty or contains only whitespace characters, otherwise returns false.
307
- */
308
- function isEmptyOrWhitespace(value) {
309
- return (Array.isArray(value) && value.length === 0) ||
310
- (typeof value === 'string' && value.trim() === '') ||
311
- value === null || typeof value === 'undefined';
312
- }
313
- /**
314
- * Submits a form via AJAX and returns a Promise that resolves to the Response object.
315
- *
316
- * @param {HTMLFormElement | string} selectorOrElement - The form element or selector.
317
- * @return {Promise<Response>} A Promise that resolves to the Response object.
318
- * @throws {Error} If the element is invalid.
319
- */
320
- async function ajaxSubmit(selectorOrElement) {
321
- const form = typeof selectorOrElement === 'string'
322
- ? document.querySelector(selectorOrElement)
323
- : selectorOrElement;
324
- if (!(form instanceof HTMLFormElement)) {
325
- throw new Error("Invalid element.");
326
- }
327
- // Crear un objeto FormData a partir del formulario
328
- return await fetch(form.action, {
329
- method: form.method,
330
- body: new FormData(form),
331
- });
332
- }
333
- /**
334
- * Converts an object into an array of key-value pairs.
335
- *
336
- * @param {Record<string, any>} obj - The object to convert.
337
- * @return {KeyValuePair<string, any>[]} - The array of key-value pairs.
338
- */
339
- function toPairs(obj) {
340
- let output = [];
341
- for (const key in obj) {
342
- output.push(new KeyValuePair(key, obj[key]));
343
- }
344
- return output;
345
- }
346
- /**
347
- * Converts a given thing into a Promise.
348
- * @template T
349
- * @param {any} thing - The thing to be converted into a Promise.
350
- * @returns {Promise<T>} - A Promise representing the given thing.
351
- */
352
- function promisify(thing) {
353
- if (thing instanceof Promise)
354
- return thing;
355
- if (isFunction(thing)) {
356
- return new Promise((resolve, reject) => {
357
- try {
358
- const result = thing();
359
- resolve(result);
360
- }
361
- catch (error) {
362
- reject(error);
363
- }
364
- });
365
- }
366
- return Promise.resolve(thing);
367
- }
368
- function ajaxSubmission(selectorOrElement, onSuccess = undefined, onFailure = undefined) {
369
- const form = typeof selectorOrElement === 'string'
370
- ? document.querySelector(selectorOrElement)
371
- : selectorOrElement;
372
- if (!(form instanceof HTMLFormElement)) {
373
- return;
374
- }
375
- form.addEventListener('submit', async (event) => {
376
- event.preventDefault();
377
- let promise = ajaxSubmit(form);
378
- if (promise) {
379
- if (onSuccess)
380
- promise = promise.then(onSuccess);
381
- if (onFailure)
382
- promise.catch(onFailure);
383
- }
384
- });
385
- }
386
- /**
387
- * Creates a deep clone of the given object.
388
- * @template T
389
- * @param {T} obj - The object to clone.
390
- * @return {T} - The deep clone of the given object.
391
- */
392
- function deepClone(obj) {
393
- if (obj === null || typeof obj !== 'object') {
394
- return obj;
395
- }
396
- if (Array.isArray(obj)) {
397
- const copy = [];
398
- for (const element of obj) {
399
- copy.push(deepClone(element));
400
- }
401
- return copy;
402
- }
403
- const copy = {};
404
- for (const key in obj) {
405
- if (obj.hasOwnProperty(key)) {
406
- copy[key] = deepClone(obj[key]);
407
- }
408
- }
409
- return copy;
410
- }
411
- /**
412
- * Returns the type of the given value.
413
- *
414
- * @param {any} value - The value to determine the type of.
415
- * @return {Type} - The type of the given value.
416
- */
417
- function getType(value) {
418
- return value === null ? exports.Type.Null : exports.Type[typeof value];
419
- }
420
- function formToObject(form) {
421
- const fd = new FormData(form);
422
- const out = {};
423
- for (const [key, value] of fd.entries()) {
424
- if (key in out) {
425
- const current = out[key];
426
- if (Array.isArray(current)) {
427
- current.push(value);
428
- }
429
- else {
430
- out[key] = [current, value];
431
- }
432
- }
433
- else {
434
- out[key] = value;
435
- }
436
- }
437
- return out;
438
- }
439
- /**
440
- * Converts an object to `FormData` format recursively.
441
- *
442
- * @param {Record<string, any>} data - The object data to convert.
443
- * @param {FormData} formData - The `FormData` instance to append data to.
444
- * @param {string} parentKey - The parent key to append to child keys in the `FormData`.
445
- * @returns {FormData} - The `FormData` instance with the converted data.
446
- */
447
- function _objectToFormData(data, formData, parentKey = '') {
448
- for (const key in data) {
449
- if (data.hasOwnProperty(key)) {
450
- const value = data[key];
451
- if (value instanceof Date) {
452
- formData.append(parentKey ? `${parentKey}[${key}]` : key, value.toISOString());
453
- }
454
- else if (value instanceof File) {
455
- formData.append(parentKey ? `${parentKey}[${key}]` : key, value);
456
- }
457
- else if (typeof value === 'object' && !Array.isArray(value)) {
458
- _objectToFormData(value, formData, parentKey ? `${parentKey}[${key}]` : key);
459
- }
460
- else if (Array.isArray(value)) {
461
- value.forEach((item, index) => {
462
- const arrayKey = `${parentKey ? `${parentKey}[${key}]` : key}[${index}]`;
463
- if (typeof item === 'object' && !Array.isArray(item)) {
464
- _objectToFormData(item, formData, arrayKey);
465
- }
466
- else {
467
- formData.append(arrayKey, item);
468
- }
469
- });
470
- }
471
- else {
472
- formData.append(parentKey ? `${parentKey}[${key}]` : key, value);
473
- }
474
- }
475
- }
476
- return formData;
477
- }
478
- /**
479
- * Converts an object into FormData.
480
- *
481
- * @param {Record<string, any>} data - The object to be converted into FormData.
482
- * @return {FormData} - The FormData object representing the converted data.
483
- */
484
- function objectToFormData(data) {
485
- let formData = new FormData();
486
- return _objectToFormData(data, formData);
487
- }
488
-
489
- /**
490
- * Ensures that a given string has a specific prefix.
491
- *
492
- * @param {string} str - The string to ensure the prefix on.
493
- * @param {string} prefix - The prefix to ensure on the string.
494
- * @return {string} - The resulting string with the ensured prefix.
495
- */
496
- function ensurePrefix(str, prefix) {
497
- if (!str.startsWith(prefix))
498
- return prefix + str;
499
- return str;
500
- }
501
- /**
502
- * Ensures that a string ends with a specified suffix.
503
- *
504
- * @param {string} str - The original string.
505
- * @param {string} suffix - The suffix to ensure.
506
- * @return {string} - The modified string with the suffix added if it was not already present.
507
- */
508
- function ensureSuffix(str, suffix) {
509
- if (!str.endsWith(suffix))
510
- return str + suffix;
511
- return str;
512
- }
513
- /**
514
- * Formats a string using a template and provided arguments.
515
- *
516
- * @param {string} template - The template string containing placeholders.
517
- * @param {any[]} args - Optional arguments to replace the placeholders in the template.
518
- * @return {string} The formatted string.
519
- */
520
- function format(template, ...args) {
521
- let regex;
522
- if (args.length === 1 && typeof args[0] === 'object') {
523
- args = args[0];
524
- regex = /{(.+?)}/g;
525
- }
526
- else {
527
- regex = /{(\d+?)}/g;
528
- }
529
- return template.replace(regex, (match, key) => {
530
- return typeof args[key] !== 'undefined' ? args[key] : "";
531
- });
532
- }
533
-
534
- /**
535
- * Linearly interpolates a number between two ranges.
536
- *
537
- * @param {number} n - The number to interpolate.
538
- * @param {number} inMin - The minimum value of the input range.
539
- * @param {number} inMax - The maximum value of the input range.
540
- * @param {number} outMin - The minimum value of the output range.
541
- * @param {number} outMax - The maximum value of the output range.
542
- *
543
- * @return {number} - The interpolated value.
544
- */
545
- function lerp(n, inMin, inMax, outMin, outMax) {
546
- return outMin + (outMax - outMin) * ((n - inMin) / (inMax - inMin));
547
- }
548
- /**
549
- * Clamps a number between a minimum and maximum value.
550
- *
551
- * @param {number} n - The value to be clamped.
552
- * @param {number} min - The minimum value.
553
- * @param {number} max - The maximum value.
554
- * @return {number} The clamped value.
555
- */
556
- function clamp(n, min, max) {
557
- if (n <= min)
558
- return min;
559
- if (n >= max)
560
- return max;
561
- return n;
562
- }
563
-
564
- class CacheDictionary {
565
- constructor(fallback = null, defaultDuration = null) {
566
- this.fallback = fallback;
567
- this.cache = {};
568
- this.defaultDuration = defaultDuration;
569
- this.expiration = {};
570
- }
571
- getExpiration(key) {
572
- return this.expiration[key];
573
- }
574
- setExpiration(key, expiration) {
575
- this.expiration[key] = expiration;
576
- }
577
- setDuration(key, duration) {
578
- if (duration === null) {
579
- delete this.expiration[key];
580
- }
581
- else {
582
- const expiration = new Date();
583
- expiration.setSeconds(expiration.getSeconds() + duration);
584
- this.expiration[key] = expiration;
585
- }
586
- }
587
- get(key) {
588
- if (!this.cache.hasOwnProperty(key)) {
589
- if (this.fallback) {
590
- this.cache[key] = this.fallback(key);
591
- this.expiration[key] = this.calculateExpiration(this.defaultDuration);
592
- }
593
- else {
594
- return null;
595
- }
596
- }
597
- if (this.isExpired(key)) {
598
- this.remove(key);
599
- return null;
600
- }
601
- return this.cache[key];
602
- }
603
- set(key, value, duration = null) {
604
- this.cache[key] = value;
605
- this.expiration[key] = this.calculateExpiration(duration);
606
- }
607
- remove(key) {
608
- delete this.cache[key];
609
- delete this.expiration[key];
610
- }
611
- isExpired(key) {
612
- const expiration = this.expiration[key];
613
- if (expiration instanceof Date) {
614
- return expiration < new Date();
615
- }
616
- return false;
617
- }
618
- calculateExpiration(duration) {
619
- if (duration === null) {
620
- return undefined;
621
- }
622
- const expiration = new Date();
623
- expiration.setSeconds(expiration.getSeconds() + duration);
624
- return expiration;
625
- }
626
- }
627
-
628
- var Order;
629
- (function (Order) {
630
- Order["Ascending"] = "asc";
631
- Order["Descending"] = "desc";
632
- })(Order || (Order = {}));
633
- var Order$1 = Order;
634
-
635
- function from(source) {
636
- if (source == null)
637
- throw "Source is null.";
638
- if (typeof source === 'function')
639
- return From.fn(source);
640
- if (typeof source[Symbol.iterator] === 'function') {
641
- return From.iterable(source);
642
- }
643
- else if (typeof source === 'object') {
644
- return From.object(source);
645
- }
646
- throw "Invalid source.";
647
- }
648
- class From {
649
- static object(obj) {
650
- return new From(function () {
651
- return toPairs(obj);
652
- });
653
- }
654
- constructor(fn) {
655
- this._fn = fn;
656
- }
657
- static fn(callable) {
658
- return new From(callable);
659
- }
660
- ;
661
- collect() {
662
- const cache = Array.from(this);
663
- return From.iterable(cache);
664
- }
665
- static iterable(iterable) {
666
- return From.fn(function* () {
667
- for (const item of iterable) {
668
- yield item;
669
- }
670
- });
671
- }
672
- ;
673
- map(mapper) {
674
- const self = this;
675
- return From.fn(function* () {
676
- for (let item of self) {
677
- yield mapper(item);
678
- }
679
- });
680
- }
681
- *[Symbol.iterator]() {
682
- yield* this._fn();
683
- }
684
- all(predicate) {
685
- for (let item of this._fn()) {
686
- if (!predicate(item)) {
687
- return false;
688
- }
689
- }
690
- return true;
691
- }
692
- any(predicate = undefined) {
693
- for (let item of this) {
694
- if (predicate == null || predicate(item)) {
695
- return true;
696
- }
697
- }
698
- return false;
699
- }
700
- get length() {
701
- return this.count();
702
- }
703
- count(predicate = undefined) {
704
- let output = 0;
705
- for (let item of this) {
706
- if (predicate == null || predicate(item)) {
707
- output++;
708
- }
709
- }
710
- return output;
711
- }
712
- filter(predicate) {
713
- const self = this;
714
- return From.fn(function* () {
715
- for (let item of self) {
716
- if (predicate(item)) {
717
- yield item;
718
- }
719
- }
720
- });
721
- }
722
- contains(value) {
723
- for (let item of this) {
724
- if (item === value) {
725
- return true;
726
- }
727
- }
728
- return false;
729
- }
730
- // noinspection LoopStatementThatDoesntLoopJS
731
- first(predicate) {
732
- if (predicate) {
733
- for (let item of this) {
734
- if (predicate(item)) {
735
- return item;
736
- }
737
- }
738
- }
739
- else {
740
- // noinspection LoopStatementThatDoesntLoopJS
741
- for (let item of this) {
742
- return item;
743
- }
744
- }
745
- return undefined;
746
- }
747
- // noinspection LoopStatementThatDoesntLoopJS
748
- single(predicate) {
749
- let found = false;
750
- let output = null;
751
- if (predicate) {
752
- for (let item of this) {
753
- if (predicate(item)) {
754
- if (found) {
755
- throw new Error("Sequence contains more than one element.");
756
- }
757
- found = true;
758
- output = item;
759
- }
760
- }
761
- }
762
- else {
763
- // noinspection LoopStatementThatDoesntLoopJS
764
- for (let item of this) {
765
- if (found) {
766
- throw new Error("Sequence contains more than one element.");
767
- }
768
- found = true;
769
- output = item;
770
- }
771
- }
772
- return output;
773
- }
774
- append(item) {
775
- const self = this;
776
- return From.fn(function* () {
777
- for (let element of self) {
778
- yield element;
779
- }
780
- yield item;
781
- });
782
- }
783
- prepend(item) {
784
- const self = this;
785
- return From.fn(function* () {
786
- yield item;
787
- for (let element of self) {
788
- yield element;
789
- }
790
- });
791
- }
792
- at(index) {
793
- let idx = 0;
794
- for (let item of this) {
795
- if (idx++ === index) {
796
- return item;
797
- }
798
- }
799
- return undefined;
800
- }
801
- last(predicate) {
802
- let last = undefined;
803
- if (predicate)
804
- for (let item of this) {
805
- if (!predicate || predicate(item)) {
806
- last = item;
807
- }
808
- }
809
- else {
810
- for (let item of this) {
811
- last = item;
812
- }
813
- }
814
- return last;
815
- }
816
- mapMany(mapper) {
817
- const self = this;
818
- return From.fn(function* () {
819
- for (const item of self) {
820
- const subitems = mapper(item);
821
- for (const subitem of subitems) {
822
- yield subitem;
823
- }
824
- }
825
- });
826
- }
827
- flatten() {
828
- const self = this;
829
- return From.fn(function* () {
830
- for (let item of self) {
831
- let temp = item;
832
- for (let subitem of temp) {
833
- yield subitem;
834
- }
835
- }
836
- });
837
- }
838
- sum(mapper) {
839
- let total = 0;
840
- if (mapper)
841
- for (let item of this) {
842
- total += mapper(item);
843
- }
844
- else
845
- for (let item of this) {
846
- total += item;
847
- }
848
- return total;
849
- }
850
- avg(mapper) {
851
- let total = 0;
852
- let count = 0;
853
- if (mapper)
854
- for (let item of this) {
855
- total += mapper(item);
856
- count++;
857
- }
858
- else
859
- for (let item of this) {
860
- total += item;
861
- count++;
862
- }
863
- return count > 0 ? total / count : 0;
864
- }
865
- max(mapper) {
866
- let max = -Infinity;
867
- for (let item of this) {
868
- let value = mapper(item);
869
- max = value > max ? value : max;
870
- }
871
- return max;
872
- }
873
- min(mapper) {
874
- let min = Infinity;
875
- for (let item of this) {
876
- let value = mapper(item);
877
- min = value < min ? value : min;
878
- }
879
- return min;
880
- }
881
- maxBy(mapper) {
882
- let max = -Infinity;
883
- let maxItem;
884
- for (let item of this) {
885
- let value = mapper(item);
886
- if (value > max) {
887
- max = value;
888
- maxItem = item;
889
- }
890
- }
891
- return maxItem;
892
- }
893
- minBy(mapper) {
894
- let min = Infinity;
895
- let minItem;
896
- for (let item of this) {
897
- let value = mapper(item);
898
- if (value < min) {
899
- min = value;
900
- minItem = item;
901
- }
902
- }
903
- return minItem;
904
- }
905
- orderBy(mapper, order = Order$1.Ascending) {
906
- const array = Array.from(this._fn());
907
- if (order == Order$1.Ascending) {
908
- array.sort((a, b) => {
909
- const aValue = mapper(a);
910
- const bValue = mapper(b);
911
- return aValue > bValue ? 1 : bValue > aValue ? -1 : 0;
912
- });
913
- }
914
- else if (order == Order$1.Descending) {
915
- array.sort((a, b) => {
916
- const aValue = mapper(a);
917
- const bValue = mapper(b);
918
- return aValue > bValue ? 1 : bValue < aValue ? -1 : 0;
919
- });
920
- }
921
- else {
922
- throw new Error("invalid order argument");
923
- }
924
- return From.iterable(array);
925
- }
926
- groupBy(keySelector, equalityComparer) {
927
- equalityComparer = (equalityComparer == null ? shallowEqual : equalityComparer);
928
- const self = this;
929
- return From.fn(function* () {
930
- const groups = [];
931
- for (let item of self) {
932
- const key = keySelector(item);
933
- let found = false;
934
- for (let [entryKey, group] of groups) {
935
- if (equalityComparer(key, entryKey)) {
936
- group.push(item);
937
- found = true;
938
- break;
939
- }
940
- }
941
- if (!found) {
942
- groups.push([key, [item]]);
943
- }
944
- }
945
- yield* groups.map(([key, values]) => new Grouping(key, values));
946
- });
947
- }
948
- head(n) {
949
- const self = this;
950
- return From.fn(function* () {
951
- let count = 0;
952
- for (let item of self) {
953
- if (count++ < n) {
954
- yield item;
955
- }
956
- else {
957
- return;
958
- }
959
- }
960
- });
961
- }
962
- tail(n) {
963
- const self = this;
964
- return From.fn(function* () {
965
- let buffer = [];
966
- for (let item of self) {
967
- buffer.push(item);
968
- if (buffer.length > n) {
969
- buffer.shift();
970
- }
971
- }
972
- yield* buffer;
973
- });
974
- }
975
- forEach(action) {
976
- for (let item of this) {
977
- action(item);
978
- }
979
- }
980
- toArray() {
981
- return Array.from(this);
982
- }
983
- toRecord(keySelector, valueSelector) {
984
- const output = {};
985
- for (let item of this) {
986
- output[keySelector(item)] = valueSelector(item);
987
- }
988
- return output;
989
- }
990
- toMap(keySelector, valueSelector) {
991
- const map = new Map();
992
- for (let item of this) {
993
- const key = keySelector(item);
994
- const value = valueSelector(item);
995
- map.set(key, value);
996
- }
997
- return map;
998
- }
999
- instancesOf(type) {
1000
- return this.filter(item => typeof item === type);
1001
- }
1002
- allInstanceOf(type) {
1003
- for (let item of this) {
1004
- if (!(item instanceof type)) {
1005
- return false;
1006
- }
1007
- }
1008
- return true;
1009
- }
1010
- distinct(eq_comparer) {
1011
- if (eq_comparer == null)
1012
- eq_comparer = shallowEqual;
1013
- const self = this;
1014
- return From.fn(function* () {
1015
- const included = [];
1016
- for (let item of self) {
1017
- if (!From.iterable(included).any(x => eq_comparer(x, item))) {
1018
- included.push(item);
1019
- yield item;
1020
- }
1021
- }
1022
- });
1023
- }
1024
- insert(item, index) {
1025
- const self = this;
1026
- return From.fn(function* () {
1027
- let i = 0;
1028
- let inserted = false;
1029
- for (let existingItem of self) {
1030
- if (i === index) {
1031
- yield item;
1032
- inserted = true;
1033
- }
1034
- yield existingItem;
1035
- i++;
1036
- }
1037
- if (!inserted) {
1038
- yield item;
1039
- }
1040
- });
1041
- }
1042
- skip(n) {
1043
- const self = this;
1044
- return From.fn(function* () {
1045
- let i = 0;
1046
- for (let item of self) {
1047
- if (i >= n) {
1048
- yield item;
1049
- }
1050
- i++;
1051
- }
1052
- });
1053
- }
1054
- union(other) {
1055
- const self = this;
1056
- return From.fn(function* () {
1057
- yield* self;
1058
- yield* other;
1059
- });
1060
- }
1061
- innerJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
1062
- const self = this;
1063
- return From.fn(() => {
1064
- const otherByKey = new Map();
1065
- for (let item of other) {
1066
- otherByKey.set(otherKeySelector(item), item);
1067
- }
1068
- return Array.from(self)
1069
- .filter(item => otherByKey.has(thisKeySelector(item)))
1070
- .map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
1071
- });
1072
- }
1073
- leftJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
1074
- const self = this;
1075
- return From.fn(() => {
1076
- const otherByKey = new Map();
1077
- for (let item of other) {
1078
- otherByKey.set(otherKeySelector(item), item);
1079
- }
1080
- return Array.from(self).map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
1081
- });
1082
- }
1083
- leftGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
1084
- const self = this;
1085
- return From.fn(() => {
1086
- const otherByKeys = new Map();
1087
- for (let item of other) {
1088
- const key = otherKeySelector(item);
1089
- if (!otherByKeys.has(key)) {
1090
- otherByKeys.set(key, []);
1091
- }
1092
- otherByKeys.get(key).push(item);
1093
- }
1094
- return Array.from(self).map(item => resultSelector(item, otherByKeys.get(thisKeySelector(item)) || []));
1095
- });
1096
- }
1097
- rightGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
1098
- const self = this;
1099
- return From.fn(() => {
1100
- const thisByKeys = new Map();
1101
- for (let item of self) {
1102
- const key = thisKeySelector(item);
1103
- if (!thisByKeys.has(key)) {
1104
- thisByKeys.set(key, []);
1105
- }
1106
- thisByKeys.get(key).push(item);
1107
- }
1108
- return Array.from(other).map(item => resultSelector(thisByKeys.get(otherKeySelector(item)) || [], item));
1109
- });
1110
- }
1111
- rightJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
1112
- const self = this;
1113
- return From.fn(() => {
1114
- const thisByKey = new Map();
1115
- for (let item of self) {
1116
- thisByKey.set(thisKeySelector(item), item);
1117
- }
1118
- return Array.from(other).map(item => resultSelector(thisByKey.get(otherKeySelector(item)), item));
1119
- });
1120
- }
1121
- }
1122
- class Grouping extends From {
1123
- get key() {
1124
- return this._key;
1125
- }
1126
- constructor(key, values) {
1127
- super(() => values);
1128
- this._key = key;
1129
- }
1130
- }
1131
-
1132
- /**
1133
- * A class representing a timer that executes a callback function at a specified interval.
1134
- */
1135
- class Timer {
1136
- /**
1137
- * @param callback Callback
1138
- * @param interval Seconds between calls
1139
- */
1140
- constructor(callback, interval) {
1141
- this._callback = callback;
1142
- this._interval = interval;
1143
- this._intervalId = null;
1144
- }
1145
- get running() {
1146
- return this._intervalId !== null && this._intervalId !== undefined;
1147
- }
1148
- get interval() {
1149
- return this._interval;
1150
- }
1151
- set interval(value) {
1152
- if (value != this._interval) {
1153
- this._interval = value;
1154
- if (this.running)
1155
- this.restart();
1156
- }
1157
- }
1158
- get callback() {
1159
- return this._callback;
1160
- }
1161
- set callback(value) {
1162
- if (value != this._callback) {
1163
- this._callback = value;
1164
- }
1165
- }
1166
- start() {
1167
- if (this._intervalId === null) {
1168
- this._intervalId = setInterval(() => {
1169
- if (this._callback != null)
1170
- this._callback();
1171
- }, this._interval);
1172
- }
1173
- }
1174
- stop() {
1175
- if (this._intervalId !== null) {
1176
- clearInterval(this._intervalId);
1177
- this._intervalId = null;
1178
- }
1179
- }
1180
- restart() {
1181
- this.stop();
1182
- this.start();
1183
- }
1184
- }
1185
-
1186
- /**
1187
- * Represents a duration of time in milliseconds.
1188
- */
1189
- class TimeSpan {
1190
- constructor(milliseconds) {
1191
- this.milliseconds = milliseconds;
1192
- }
1193
- // Obtener el intervalo de tiempo en segundos
1194
- seconds() {
1195
- return this.milliseconds / 1000;
1196
- }
1197
- // Obtener el intervalo de tiempo en minutos
1198
- minutes() {
1199
- return this.milliseconds / (1000 * 60);
1200
- }
1201
- // Obtener el intervalo de tiempo en horas
1202
- hours() {
1203
- return this.milliseconds / (1000 * 60 * 60);
1204
- }
1205
- // Obtener el intervalo de tiempo en días
1206
- days() {
1207
- return this.milliseconds / (1000 * 60 * 60 * 24);
1208
- }
1209
- // Obtener el intervalo de tiempo en semanas
1210
- weeks() {
1211
- return this.milliseconds / (1000 * 60 * 60 * 24 * 7);
1212
- }
1213
- // Constructor estático para crear un TimeSpan desde milisegundos
1214
- static fromMilliseconds(milliseconds) {
1215
- return new TimeSpan(milliseconds);
1216
- }
1217
- // Constructor estático para crear un TimeSpan desde segundos
1218
- static fromSeconds(seconds) {
1219
- return new TimeSpan(seconds * 1000);
1220
- }
1221
- // Constructor estático para crear un TimeSpan desde minutos
1222
- static fromMinutes(minutes) {
1223
- return new TimeSpan(minutes * 1000 * 60);
1224
- }
1225
- // Constructor estático para crear un TimeSpan desde horas
1226
- static fromHours(hours) {
1227
- return new TimeSpan(hours * 1000 * 60 * 60);
1228
- }
1229
- // Constructor estático para crear un TimeSpan desde días
1230
- static fromDays(days) {
1231
- return new TimeSpan(days * 1000 * 60 * 60 * 24);
1232
- }
1233
- // Constructor estático para crear un TimeSpan desde semanas
1234
- static fromWeeks(weeks) {
1235
- return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);
1236
- }
1237
- // Añadir un intervalo de tiempo
1238
- addMilliseconds(milliseconds) {
1239
- return new TimeSpan(this.milliseconds + milliseconds);
1240
- }
1241
- addSeconds(seconds) {
1242
- return this.addMilliseconds(seconds * 1000);
1243
- }
1244
- addMinutes(minutes) {
1245
- return this.addMilliseconds(minutes * 1000 * 60);
1246
- }
1247
- addHours(hours) {
1248
- return this.addMilliseconds(hours * 1000 * 60 * 60);
1249
- }
1250
- addDays(days) {
1251
- return this.addMilliseconds(days * 1000 * 60 * 60 * 24);
1252
- }
1253
- addWeeks(weeks) {
1254
- return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
1255
- }
1256
- // Restar un intervalo de tiempo
1257
- subtractMilliseconds(milliseconds) {
1258
- return new TimeSpan(this.milliseconds - milliseconds);
1259
- }
1260
- subtractSeconds(seconds) {
1261
- return this.subtractMilliseconds(seconds * 1000);
1262
- }
1263
- subtractMinutes(minutes) {
1264
- return this.subtractMilliseconds(minutes * 1000 * 60);
1265
- }
1266
- subtractHours(hours) {
1267
- return this.subtractMilliseconds(hours * 1000 * 60 * 60);
1268
- }
1269
- subtractDays(days) {
1270
- return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);
1271
- }
1272
- subtractWeeks(weeks) {
1273
- return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
1274
- }
1275
- // Añadir otro TimeSpan
1276
- add(other) {
1277
- return new TimeSpan(this.milliseconds + other.milliseconds);
1278
- }
1279
- // Restar otro TimeSpan
1280
- subtract(other) {
1281
- return new TimeSpan(this.milliseconds - other.milliseconds);
1282
- }
1283
- // Añadir un intervalo de tiempo a una fecha
1284
- addTo(date) {
1285
- return new Date(date.getTime() + this.milliseconds);
1286
- }
1287
- // Restar un intervalo de tiempo de una fecha
1288
- subtractFrom(date) {
1289
- return new Date(date.getTime() - this.milliseconds);
1290
- }
1291
- static fromDifference(earlierDate, laterDate) {
1292
- return new TimeSpan(laterDate.getTime() - earlierDate.getTime());
1293
- }
1294
- format(format = 'hh:mm:ss') {
1295
- const formatLower = format.toLowerCase();
1296
- const hasHours = formatLower.includes("h");
1297
- const hasMinutes = formatLower.includes("m");
1298
- let hours = 0, minutes = 0, seconds = Math.floor(this.milliseconds / 1000);
1299
- if (hasHours) {
1300
- hours = Math.floor(seconds / 3600);
1301
- seconds -= hours * 3600;
1302
- }
1303
- if (hasMinutes) {
1304
- minutes = Math.floor(seconds / 60);
1305
- seconds -= minutes * 60;
1306
- }
1307
- const hoursPadded = String(hours).padStart(2, '0');
1308
- const minutesPadded = String(minutes).padStart(2, '0');
1309
- const secondsPadded = String(seconds).padStart(2, '0');
1310
- return formatLower
1311
- .replace('hh', hoursPadded)
1312
- .replace('h', hours.toString())
1313
- .replace('mm', minutesPadded)
1314
- .replace('m', minutes.toString())
1315
- .replace('ss', secondsPadded)
1316
- .replace('s', seconds.toString());
1317
- }
1318
- eq(other) {
1319
- return this.milliseconds === other.milliseconds;
1320
- }
1321
- le(other) {
1322
- return this.milliseconds <= other.milliseconds;
1323
- }
1324
- lt(other) {
1325
- return this.milliseconds < other.milliseconds;
1326
- }
1327
- ge(other) {
1328
- return this.milliseconds >= other.milliseconds;
1329
- }
1330
- gt(other) {
1331
- return this.milliseconds > other.milliseconds;
1332
- }
1333
- multiply(number) {
1334
- return new TimeSpan(this.milliseconds * number);
1335
- }
1336
- divide(number) {
1337
- return new TimeSpan(this.milliseconds / number);
1338
- }
1339
- abs() {
1340
- return new TimeSpan(Math.abs(this.milliseconds));
1341
- }
1342
- isInfinite() {
1343
- return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY;
1344
- }
1345
- // Determinar si es un TimeSpan infinitamente positivo
1346
- isPositiveInfinite() {
1347
- return this.milliseconds === Number.POSITIVE_INFINITY;
1348
- }
1349
- // Determinar si es un TimeSpan infinitamente negativo
1350
- isNegativeInfinite() {
1351
- return this.milliseconds === Number.NEGATIVE_INFINITY;
1352
- }
1353
- }
1354
- TimeSpan.INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);
1355
- TimeSpan.NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);
1356
-
1357
- /**
1358
- * Represents a lazy value that is created only when it is accessed for the first time.
1359
- * @template T The type of the lazy value.
1360
- */
1361
- class Lazy {
1362
- constructor(getter) {
1363
- this._valueCreated = false;
1364
- this._value = null;
1365
- this._factoryMethod = getter;
1366
- }
1367
- get valueCreated() {
1368
- return this._valueCreated;
1369
- }
1370
- get value() {
1371
- if (!this._valueCreated) {
1372
- this._value = this._factoryMethod();
1373
- this._valueCreated = true;
1374
- }
1375
- return this._value;
1376
- }
1377
- reset() {
1378
- this._valueCreated = false;
1379
- this._value = null;
1380
- }
1381
- }
1382
-
1383
- /**
1384
- * Represents a class for manipulating an array of items.
1385
- *
1386
- * @template T - The type of items in the array.
1387
- * @deprecated
1388
- */
1389
- class ArrayManipulator {
1390
- constructor(array) {
1391
- this._array = array;
1392
- }
1393
- [Symbol.iterator]() {
1394
- return this._array[Symbol.iterator]();
1395
- }
1396
- /**
1397
- * Retrieves or sets the value at the specified index in the array.
1398
- * If `item` is not provided, returns the value at index `n`.
1399
- * If `item` is provided, sets the value at index `n` to the provided value.
1400
- *
1401
- * @param {number} n - The index at which to retrieve or set the value.
1402
- * @param {T | undefined} [item] - The value to set at index `n`, if provided.
1403
- *
1404
- * @return {T | void} - If `item` is not provided, returns the value at index `n`.
1405
- * - If `item` is provided, does not return anything.
1406
- */
1407
- at(n, item = undefined) {
1408
- if (item === undefined)
1409
- return this._array[n];
1410
- else
1411
- this._array[n] = item;
1412
- }
1413
- /**
1414
- * Removes the specified item from the array.
1415
- *
1416
- * @param {T} item - The item to be removed.
1417
- * @returns {ArrayManipulator<T>} - The updated ArrayManipulator instance.
1418
- */
1419
- remove(item) {
1420
- const index = this._array.indexOf(item);
1421
- if (index !== -1) {
1422
- this._array.splice(index, 1);
1423
- }
1424
- return this;
1425
- }
1426
- /**
1427
- * Applies a mapping function to each element in the array, transforming it into a new array.
1428
- * @template R
1429
- * @param {UnaryFunction<T, R>} mapFn - The function to be applied to each element.
1430
- * @return {ArrayManipulator<R>} - The new ArrayManipulator instance with the mapped elements.
1431
- */
1432
- map(mapFn) {
1433
- for (let i = 0; i < this._array.length; i++) {
1434
- this._array[i] = mapFn(this._array[i]);
1435
- }
1436
- return this;
1437
- }
1438
- /**
1439
- * Filters the elements of the array based on a given filter function.
1440
- * The filter function should return a boolean value, indicating whether the element should be included in the filtered array or not.
1441
- *
1442
- * @param {Predicate<T>} filterFn - The function that will be used to filter the elements. It should accept an element of type T and return a boolean value.
1443
- * @returns {ArrayManipulator<T>} - The filtered ArrayManipulator instance with the elements that passed the filter.
1444
- */
1445
- filter(filterFn) {
1446
- for (let i = 0; i < this._array.length; i++) {
1447
- if (!filterFn(this._array[i])) {
1448
- this._array.splice(i, 1);
1449
- i--;
1450
- }
1451
- }
1452
- return this;
1453
- }
1454
- head(n) {
1455
- this._array.splice(n);
1456
- return this;
1457
- }
1458
- slice(start, count = undefined) {
1459
- this._array.splice(0, start); // Eliminar los primeros elementos hasta `start`
1460
- if (count !== undefined) {
1461
- this._array.splice(count); // Mantener solo `count` elementos restantes
1462
- }
1463
- return this;
1464
- }
1465
- mapMany(mapper) {
1466
- let i = 0;
1467
- while (i < this._array.length) {
1468
- let mappedItems = mapper(this._array[i]);
1469
- if (!Array.isArray(mappedItems))
1470
- mappedItems = Array.from(mappedItems);
1471
- this._array.splice(i, 1, ...mappedItems);
1472
- i += mappedItems.length;
1473
- }
1474
- return this;
1475
- }
1476
- tail(n) {
1477
- const start = this._array.length - n;
1478
- this._array.splice(0, start);
1479
- return this;
1480
- }
1481
- /**
1482
- * Appends one or more items to the array.
1483
- *
1484
- * @param {...T} items - The items to be appended to the array.
1485
- * @return {ArrayManipulator<T>} - The ArrayManipulator instance.
1486
- */
1487
- append(...items) {
1488
- this._array.push(...items);
1489
- return this;
1490
- }
1491
- /**
1492
- * Prepend items to the beginning of the array.
1493
- *
1494
- * @param {...T} items - The items to be prepended.
1495
- * @return {ArrayManipulator<T>} The ArrayManipulator instance.
1496
- */
1497
- prepend(...items) {
1498
- this._array.unshift(...items);
1499
- return this;
1500
- }
1501
- get array() {
1502
- return this._array;
1503
- }
1504
- }
1505
- /**
1506
- * Creates an instance of ArrayManipulator with the given array.
1507
- * @template T
1508
- * @param {T[]} array - The input array.
1509
- * @return {ArrayManipulator<T>} - An instance of the ArrayManipulator class.
1510
- */
1511
- function array(array) {
1512
- return new ArrayManipulator(array);
1513
- }
1514
-
1515
- class AsyncPoolExecutor {
1516
- get maxConcurrency() {
1517
- return this._maxConcurrency;
1518
- }
1519
- set maxConcurrency(value) {
1520
- this._maxConcurrency = value;
1521
- }
1522
- /**
1523
- * @param {number} maxConcurrency - The maximum number of concurrent tasks allowed.
1524
- * @param {number} [checkInterval=50] - The interval, in milliseconds, to check for capacity to run new tasks. Defaults to 50 ms.
1525
- */
1526
- constructor(maxConcurrency, checkInterval = 50) {
1527
- this._taskQueue = [];
1528
- this._maxConcurrency = maxConcurrency;
1529
- this._checkIntervalMs = checkInterval;
1530
- this._activeTasks = 0;
1531
- }
1532
- /**
1533
- * Submits a deferred task to a queue for asynchronous execution and returns a Promise resolving to its result.
1534
- * @template T
1535
- * @param {Supplier<T>} task - The deferred task to be executed asynchronously.
1536
- */
1537
- submit(task) {
1538
- this._taskQueue.push(task);
1539
- if (this._proccess != null)
1540
- return;
1541
- this._proccess = setTimeout(async () => {
1542
- while (this._taskQueue.length > 0) {
1543
- while (this._activeTasks >= this._maxConcurrency) {
1544
- await delay(this._checkIntervalMs);
1545
- }
1546
- const task = this._taskQueue.shift();
1547
- if (task) {
1548
- this._activeTasks++;
1549
- setTimeout(async () => {
1550
- try {
1551
- await task();
1552
- }
1553
- finally {
1554
- this._activeTasks--;
1555
- }
1556
- });
1557
- }
1558
- }
1559
- this._proccess = null;
1560
- }, 0);
1561
- }
1562
- /**
1563
- * Waits until all tasks (both queued and active) are completed.
1564
- * This method resolves only when there are no pending tasks.
1565
- *
1566
- * @return {Promise<void>} A promise that resolves when all tasks are complete.
1567
- */
1568
- async shutdown() {
1569
- while (this._taskQueue.length > 0 || this._activeTasks > 0) {
1570
- await delay(this._checkIntervalMs);
1571
- }
1572
- }
1573
- }
1574
-
1575
- class CleanURLSearchParams extends URLSearchParams {
1576
- constructor(params) {
1577
- // Filtrar `null` y `undefined` antes de pasarlos al constructor de URLSearchParams
1578
- const cleanParams = Object.fromEntries(Object.entries(params || {}).filter(([_, value]) => value !== null && value !== undefined));
1579
- super(cleanParams);
1580
- }
1581
- }
1582
-
1583
- class Stopwatch {
1584
- constructor() {
1585
- this.startTime = null;
1586
- this.elapsedTime = null;
1587
- }
1588
- /*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {
1589
- const stopwatch = new Stopwatch();
1590
- stopwatch.start();
1591
- try {
1592
- return callback();
1593
- } finally {
1594
- stopwatch.stop();
1595
- measure.value = stopwatch.getElapsedTime();
1596
- }
1597
- }*/
1598
- start() {
1599
- this.startTime = performance.now();
1600
- this.elapsedTime = null;
1601
- }
1602
- stop() {
1603
- if (this.startTime !== null) {
1604
- this.elapsedTime = performance.now() - this.startTime;
1605
- this.startTime = null;
1606
- }
1607
- }
1608
- resume() {
1609
- if (this.elapsedTime !== null) {
1610
- this.startTime = performance.now() - this.elapsedTime;
1611
- this.elapsedTime = null;
1612
- }
1613
- }
1614
- getElapsedTime() {
1615
- var _a;
1616
- if (this.startTime !== null) {
1617
- return TimeSpan.fromMilliseconds(performance.now() - this.startTime);
1618
- }
1619
- return TimeSpan.fromMilliseconds((_a = this.elapsedTime) !== null && _a !== void 0 ? _a : 0.0);
1620
- }
1621
- }
1622
-
1623
- /**
1624
- * Removes all given values from the provided array and returns the number of removed elements.
1625
- * The operation mutates the original array.
1626
- * @template T
1627
- * @param {Array<T>} array - The array to modify by removing specified items.
1628
- * @param {...T} items - The values to remove from the array.
1629
- * @return {number} The number of elements removed from the array.
1630
- */
1631
- function pull(array, ...items) {
1632
- let output = 0;
1633
- for (const item of items) {
1634
- const index = array.indexOf(item);
1635
- if (index !== -1) {
1636
- array.splice(index, 1);
1637
- output++;
1638
- }
1639
- }
1640
- return output;
1641
- }
1642
-
1643
- exports.ArrayManipulator = ArrayManipulator;
1644
- exports.AsyncPoolExecutor = AsyncPoolExecutor;
1645
- exports.CacheDictionary = CacheDictionary;
1646
- exports.CleanURLSearchParams = CleanURLSearchParams;
1647
- exports.From = From;
1648
- exports.KeyValuePair = KeyValuePair;
1649
- exports.Lazy = Lazy;
1650
- exports.Order = Order$1;
1651
- exports.Stopwatch = Stopwatch;
1652
- exports.TimeSpan = TimeSpan;
1653
- exports.Timer = Timer;
1654
- exports.ajaxSubmission = ajaxSubmission;
1655
- exports.ajaxSubmit = ajaxSubmit;
1656
- exports.array = array;
1657
- exports.clamp = clamp;
1658
- exports.deepClone = deepClone;
1659
- exports.deepEqual = deepEqual;
1660
- exports.delay = delay;
1661
- exports.ensurePrefix = ensurePrefix;
1662
- exports.ensureSuffix = ensureSuffix;
1663
- exports.formToObject = formToObject;
1664
- exports.format = format;
1665
- exports.from = from;
1666
- exports.getType = getType;
1667
- exports.isArray = isArray;
1668
- exports.isBigInt = isBigInt;
1669
- exports.isBoolean = isBoolean;
1670
- exports.isDefined = isDefined;
1671
- exports.isEmpty = isEmpty;
1672
- exports.isEmptyOrWhitespace = isEmptyOrWhitespace;
1673
- exports.isFunction = isFunction;
1674
- exports.isIterable = isIterable;
1675
- exports.isNull = isNull;
1676
- exports.isNullOrUndefined = isNullOrUndefined;
1677
- exports.isNumber = isNumber;
1678
- exports.isObject = isObject;
1679
- exports.isString = isString;
1680
- exports.isSymbol = isSymbol;
1681
- exports.isUndefined = isUndefined;
1682
- exports.lerp = lerp;
1683
- exports.objectToFormData = objectToFormData;
1684
- exports.promisify = promisify;
1685
- exports.pull = pull;
1686
- exports.shallowEqual = shallowEqual;
1687
- exports.submitForm = submitForm;
1688
- exports.toPairs = toPairs;
1689
-
1690
- })(this.window = this.window || {});