@develia/commons 0.3.16 → 0.3.19

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.
@@ -0,0 +1,1092 @@
1
+ (function (exports) {
2
+ 'use strict';
3
+
4
+ var Type;
5
+ (function (Type) {
6
+ Type["Undefined"] = "undefined";
7
+ Type["Number"] = "number";
8
+ Type["String"] = "string";
9
+ Type["Boolean"] = "boolean";
10
+ Type["Object"] = "object";
11
+ Type["Function"] = "function";
12
+ Type["Symbol"] = "symbol";
13
+ Type["BigInt"] = "bigint";
14
+ })(Type || (Type = {}));
15
+ var Type$1 = Type;
16
+
17
+ class Pair {
18
+ get value() {
19
+ return this._value;
20
+ }
21
+ get key() {
22
+ return this._key;
23
+ }
24
+ constructor(key, value) {
25
+ this._key = key;
26
+ this._value = value;
27
+ }
28
+ }
29
+
30
+ // noinspection JSUnusedGlobalSymbols
31
+ function isIterable(obj) {
32
+ return obj[Symbol.iterator] === 'function';
33
+ }
34
+ function isString(value) {
35
+ return typeof value === 'string';
36
+ }
37
+ function isNumber(value) {
38
+ return typeof value === 'number';
39
+ }
40
+ function isBoolean(value) {
41
+ return typeof value === 'boolean';
42
+ }
43
+ function isObject(value) {
44
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
45
+ }
46
+ function isArray(value) {
47
+ return Array.isArray(value);
48
+ }
49
+ function isFunction(value) {
50
+ return typeof value === 'function';
51
+ }
52
+ function isUndefined(value) {
53
+ return typeof value === 'undefined';
54
+ }
55
+ function isDefined(value) {
56
+ return typeof value !== 'undefined';
57
+ }
58
+ function isNull(value) {
59
+ return value === null;
60
+ }
61
+ function isBigInt(value) {
62
+ return typeof value === 'bigint';
63
+ }
64
+ function isSymbol(value) {
65
+ return typeof value === 'symbol';
66
+ }
67
+ function isNullOrUndefined(value) {
68
+ return value === null || typeof value === 'undefined';
69
+ }
70
+ function isEmpty(value) {
71
+ return (Array.isArray(value) && value.length === 0) ||
72
+ (typeof value === 'string' && value === '') ||
73
+ value === null || typeof value === 'undefined';
74
+ }
75
+ function isEmptyOrWhitespace(value) {
76
+ return (Array.isArray(value) && value.length === 0) ||
77
+ (typeof value === 'string' && value.trim() === '') ||
78
+ value === null || typeof value === 'undefined';
79
+ }
80
+ async function ajaxSubmit(selectorOrElement) {
81
+ const form = typeof selectorOrElement === 'string'
82
+ ? document.querySelector(selectorOrElement)
83
+ : selectorOrElement;
84
+ if (!(form instanceof HTMLFormElement)) {
85
+ throw new Error("Invalid element.");
86
+ }
87
+ // Crear un objeto FormData a partir del formulario
88
+ return await fetch(form.action, {
89
+ method: form.method,
90
+ body: new FormData(form),
91
+ });
92
+ }
93
+ function toPairs(obj) {
94
+ let output = [];
95
+ for (const key in obj) {
96
+ output.push(new Pair(key, obj[key]));
97
+ }
98
+ return output;
99
+ }
100
+ function promisify(thing) {
101
+ if (thing instanceof Promise)
102
+ return thing;
103
+ if (isFunction(thing)) {
104
+ return new Promise((resolve, reject) => {
105
+ try {
106
+ const result = thing();
107
+ resolve(result);
108
+ }
109
+ catch (error) {
110
+ reject(error);
111
+ }
112
+ });
113
+ }
114
+ return Promise.resolve(thing);
115
+ }
116
+ function ajaxSubmission(selectorOrElement, onSuccess = null, onFailure = null) {
117
+ const form = typeof selectorOrElement === 'string'
118
+ ? document.querySelector(selectorOrElement)
119
+ : selectorOrElement;
120
+ if (!(form instanceof HTMLFormElement)) {
121
+ return;
122
+ }
123
+ form.addEventListener('submit', async (event) => {
124
+ event.preventDefault();
125
+ let promise = ajaxSubmit(form);
126
+ if (promise) {
127
+ if (onSuccess)
128
+ promise = promise.then(onSuccess);
129
+ if (onFailure)
130
+ promise.catch(onFailure);
131
+ }
132
+ });
133
+ }
134
+ function deepClone(obj) {
135
+ if (obj === null || typeof obj !== 'object') {
136
+ return obj;
137
+ }
138
+ if (Array.isArray(obj)) {
139
+ const copy = [];
140
+ for (const element of obj) {
141
+ copy.push(deepClone(element));
142
+ }
143
+ return copy;
144
+ }
145
+ const copy = {};
146
+ for (const key in obj) {
147
+ if (obj.hasOwnProperty(key)) {
148
+ copy[key] = deepClone(obj[key]);
149
+ }
150
+ }
151
+ return copy;
152
+ }
153
+ function _objectToFormData(data, formData, parentKey = '') {
154
+ for (const key in data) {
155
+ if (data.hasOwnProperty(key)) {
156
+ const value = data[key];
157
+ if (value instanceof Date) {
158
+ formData.append(parentKey ? `${parentKey}[${key}]` : key, value.toISOString());
159
+ }
160
+ else if (value instanceof File) {
161
+ formData.append(parentKey ? `${parentKey}[${key}]` : key, value);
162
+ }
163
+ else if (typeof value === 'object' && !Array.isArray(value)) {
164
+ _objectToFormData(value, formData, parentKey ? `${parentKey}[${key}]` : key);
165
+ }
166
+ else if (Array.isArray(value)) {
167
+ value.forEach((item, index) => {
168
+ const arrayKey = `${parentKey ? `${parentKey}[${key}]` : key}[${index}]`;
169
+ if (typeof item === 'object' && !Array.isArray(item)) {
170
+ _objectToFormData(item, formData, arrayKey);
171
+ }
172
+ else {
173
+ formData.append(arrayKey, item);
174
+ }
175
+ });
176
+ }
177
+ else {
178
+ formData.append(parentKey ? `${parentKey}[${key}]` : key, value);
179
+ }
180
+ }
181
+ }
182
+ return formData;
183
+ }
184
+ function objectToFormData(data) {
185
+ let formData = new FormData();
186
+ return _objectToFormData(data, formData);
187
+ }
188
+
189
+ /**
190
+ * Ensure prefix of a string
191
+ *
192
+ * @category String
193
+ */
194
+ function ensurePrefix(prefix, str) {
195
+ if (!str.startsWith(prefix))
196
+ return prefix + str;
197
+ return str;
198
+ }
199
+ /**
200
+ * Ensure suffix of a string
201
+ *
202
+ * @category String
203
+ */
204
+ function ensureSuffix(suffix, str) {
205
+ if (!str.endsWith(suffix))
206
+ return str + suffix;
207
+ return str;
208
+ }
209
+
210
+ /**
211
+ * Linearly remaps a value from its source range [`inMin`, `inMax`] to the destination range [`outMin`, `outMax`]
212
+ *
213
+ * @category Math
214
+ * @example
215
+ * ```
216
+ * const value = remap(0.5, 0, 1, 200, 400) // value will be 300
217
+ * ```
218
+ */
219
+ function lerp(n, inMin, inMax, outMin, outMax) {
220
+ return outMin + (outMax - outMin) * ((n - inMin) / (inMax - inMin));
221
+ }
222
+ function clamp(n, min, max) {
223
+ if (n <= min)
224
+ return min;
225
+ if (n >= max)
226
+ return max;
227
+ return n;
228
+ }
229
+
230
+ class CacheDictionary {
231
+ constructor(fallback = null, defaultDuration = null) {
232
+ this.fallback = fallback;
233
+ this.cache = {};
234
+ this.defaultDuration = defaultDuration;
235
+ this.expiration = {};
236
+ }
237
+ getExpiration(key) {
238
+ return this.expiration[key];
239
+ }
240
+ setExpiration(key, expiration) {
241
+ this.expiration[key] = expiration;
242
+ }
243
+ setDuration(key, duration) {
244
+ if (duration === null) {
245
+ delete this.expiration[key];
246
+ }
247
+ else {
248
+ const expiration = new Date();
249
+ expiration.setSeconds(expiration.getSeconds() + duration);
250
+ this.expiration[key] = expiration;
251
+ }
252
+ }
253
+ get(key) {
254
+ if (!this.cache.hasOwnProperty(key)) {
255
+ if (this.fallback) {
256
+ this.cache[key] = this.fallback(key);
257
+ this.expiration[key] = this.calculateExpiration(this.defaultDuration);
258
+ }
259
+ else {
260
+ return null;
261
+ }
262
+ }
263
+ if (this.isExpired(key)) {
264
+ this.remove(key);
265
+ return null;
266
+ }
267
+ return this.cache[key];
268
+ }
269
+ set(key, value, duration = null) {
270
+ this.cache[key] = value;
271
+ this.expiration[key] = this.calculateExpiration(duration);
272
+ }
273
+ remove(key) {
274
+ delete this.cache[key];
275
+ delete this.expiration[key];
276
+ }
277
+ isExpired(key) {
278
+ const expiration = this.expiration[key];
279
+ if (expiration instanceof Date) {
280
+ return expiration < new Date();
281
+ }
282
+ return false;
283
+ }
284
+ calculateExpiration(duration) {
285
+ if (duration === null) {
286
+ return undefined;
287
+ }
288
+ const expiration = new Date();
289
+ expiration.setSeconds(expiration.getSeconds() + duration);
290
+ return expiration;
291
+ }
292
+ }
293
+
294
+ function from(source) {
295
+ if (source == null)
296
+ throw "Source is null.";
297
+ if (typeof source === 'function')
298
+ return From.fn(source);
299
+ if (typeof source[Symbol.iterator] === 'function') {
300
+ return From.iterable(source);
301
+ }
302
+ else if (typeof source === 'object') {
303
+ return From.object(source);
304
+ }
305
+ throw "Invalid source.";
306
+ }
307
+ class From {
308
+ static object(obj) {
309
+ return new From(function () {
310
+ return toPairs(obj);
311
+ });
312
+ }
313
+ static _shallowEqual(obj1, obj2) {
314
+ const keys1 = Object.keys(obj1);
315
+ const keys2 = Object.keys(obj2);
316
+ if (keys1.length !== keys2.length) {
317
+ return false;
318
+ }
319
+ for (let key of keys1) {
320
+ if (obj1[key] !== obj2[key]) {
321
+ return false;
322
+ }
323
+ }
324
+ return true;
325
+ }
326
+ constructor(fn) {
327
+ this._fn = fn;
328
+ }
329
+ static fn(callable) {
330
+ return new From(callable);
331
+ }
332
+ ;
333
+ collect() {
334
+ const cache = Array.from(this);
335
+ return From.iterable(cache);
336
+ }
337
+ static iterable(iterable) {
338
+ return From.fn(function* () {
339
+ for (const item of iterable) {
340
+ yield item;
341
+ }
342
+ });
343
+ }
344
+ ;
345
+ map(mapper) {
346
+ const self = this;
347
+ return From.fn(function* () {
348
+ for (let item of self) {
349
+ yield mapper(item);
350
+ }
351
+ });
352
+ }
353
+ *[Symbol.iterator]() {
354
+ yield* this._fn();
355
+ }
356
+ all(predicate) {
357
+ for (let item of this._fn()) {
358
+ if (!predicate(item)) {
359
+ return false;
360
+ }
361
+ }
362
+ return true;
363
+ }
364
+ any(predicate) {
365
+ for (let item of this) {
366
+ if (predicate(item)) {
367
+ return true;
368
+ }
369
+ }
370
+ return false;
371
+ }
372
+ filter(predicate) {
373
+ const self = this;
374
+ return From.fn(function* () {
375
+ for (let item of self) {
376
+ if (predicate(item)) {
377
+ yield item;
378
+ }
379
+ }
380
+ });
381
+ }
382
+ contains(value) {
383
+ for (let item of this) {
384
+ if (item === value) {
385
+ return true;
386
+ }
387
+ }
388
+ return false;
389
+ }
390
+ // noinspection LoopStatementThatDoesntLoopJS
391
+ first(predicate) {
392
+ if (predicate) {
393
+ for (let item of this) {
394
+ if (!predicate || predicate(item)) {
395
+ return item;
396
+ }
397
+ }
398
+ }
399
+ else {
400
+ // noinspection LoopStatementThatDoesntLoopJS
401
+ for (let item of this) {
402
+ return item;
403
+ }
404
+ }
405
+ return undefined;
406
+ }
407
+ append(item) {
408
+ const self = this;
409
+ return From.fn(function* () {
410
+ for (let element of self) {
411
+ yield element;
412
+ }
413
+ yield item;
414
+ });
415
+ }
416
+ prepend(item) {
417
+ const self = this;
418
+ return From.fn(function* () {
419
+ yield item;
420
+ for (let element of self) {
421
+ yield element;
422
+ }
423
+ });
424
+ }
425
+ at(index) {
426
+ let idx = 0;
427
+ for (let item of this) {
428
+ if (idx++ === index) {
429
+ return item;
430
+ }
431
+ }
432
+ return undefined;
433
+ }
434
+ last(predicate) {
435
+ let last = undefined;
436
+ if (predicate)
437
+ for (let item of this) {
438
+ if (!predicate || predicate(item)) {
439
+ last = item;
440
+ }
441
+ }
442
+ else {
443
+ for (let item of this) {
444
+ last = item;
445
+ }
446
+ }
447
+ return last;
448
+ }
449
+ mapMany(mapper) {
450
+ const self = this;
451
+ return From.fn(function* () {
452
+ for (const item of self) {
453
+ const subitems = mapper(item);
454
+ for (const subitem of subitems) {
455
+ yield subitem;
456
+ }
457
+ }
458
+ });
459
+ }
460
+ flatten() {
461
+ const self = this;
462
+ return From.fn(function* () {
463
+ for (let item of self) {
464
+ let temp = item;
465
+ for (let subitem of temp) {
466
+ yield subitem;
467
+ }
468
+ }
469
+ });
470
+ }
471
+ sum(mapper) {
472
+ let total = 0;
473
+ if (mapper)
474
+ for (let item of this) {
475
+ total += mapper(item);
476
+ }
477
+ else
478
+ for (let item of this) {
479
+ total += item;
480
+ }
481
+ return total;
482
+ }
483
+ avg(mapper) {
484
+ let total = 0;
485
+ let count = 0;
486
+ if (mapper)
487
+ for (let item of this) {
488
+ total += mapper(item);
489
+ count++;
490
+ }
491
+ else
492
+ for (let item of this) {
493
+ total += item;
494
+ count++;
495
+ }
496
+ return count > 0 ? total / count : 0;
497
+ }
498
+ max(mapper) {
499
+ let max = -Infinity;
500
+ for (let item of this) {
501
+ let value = mapper(item);
502
+ max = value > max ? value : max;
503
+ }
504
+ return max;
505
+ }
506
+ min(mapper) {
507
+ let min = Infinity;
508
+ for (let item of this) {
509
+ let value = mapper(item);
510
+ min = value < min ? value : min;
511
+ }
512
+ return min;
513
+ }
514
+ maxBy(mapper) {
515
+ let max = -Infinity;
516
+ let maxItem;
517
+ for (let item of this) {
518
+ let value = mapper(item);
519
+ if (value > max) {
520
+ max = value;
521
+ maxItem = item;
522
+ }
523
+ }
524
+ return maxItem;
525
+ }
526
+ minBy(mapper) {
527
+ let min = Infinity;
528
+ let minItem;
529
+ for (let item of this) {
530
+ let value = mapper(item);
531
+ if (value < min) {
532
+ min = value;
533
+ minItem = item;
534
+ }
535
+ }
536
+ return minItem;
537
+ }
538
+ orderBy(mapper) {
539
+ const array = Array.from(this._fn());
540
+ array.sort((a, b) => {
541
+ const aValue = mapper(a);
542
+ const bValue = mapper(b);
543
+ return aValue > bValue ? 1 : aValue < bValue ? -1 : 0;
544
+ });
545
+ return From.iterable(array);
546
+ }
547
+ groupBy(keySelector, equalityComparer) {
548
+ equalityComparer = (equalityComparer == null ? From._shallowEqual : equalityComparer);
549
+ const self = this;
550
+ return From.fn(function* () {
551
+ const groups = [];
552
+ for (let item of self) {
553
+ const key = keySelector(item);
554
+ let found = false;
555
+ for (let [entryKey, group] of groups) {
556
+ if (equalityComparer(key, entryKey)) {
557
+ group.push(item);
558
+ found = true;
559
+ break;
560
+ }
561
+ }
562
+ if (!found) {
563
+ groups.push([key, [item]]);
564
+ }
565
+ }
566
+ yield* groups.map(([key, values]) => new Grouping(key, values));
567
+ });
568
+ }
569
+ head(n) {
570
+ const self = this;
571
+ return From.fn(function* () {
572
+ let count = 0;
573
+ for (let item of self) {
574
+ if (count++ < n) {
575
+ yield item;
576
+ }
577
+ else {
578
+ return;
579
+ }
580
+ }
581
+ });
582
+ }
583
+ tail(n) {
584
+ const self = this;
585
+ return From.fn(function* () {
586
+ let buffer = [];
587
+ for (let item of self) {
588
+ buffer.push(item);
589
+ if (buffer.length > n) {
590
+ buffer.shift();
591
+ }
592
+ }
593
+ yield* buffer;
594
+ });
595
+ }
596
+ forEach(action) {
597
+ for (let item of this) {
598
+ action(item);
599
+ }
600
+ }
601
+ toArray() {
602
+ return Array.from(this);
603
+ }
604
+ instancesOf(type) {
605
+ return this.filter(item => typeof item === type);
606
+ }
607
+ allInstanceOf(type) {
608
+ for (let item of this) {
609
+ if (!(item instanceof type)) {
610
+ return false;
611
+ }
612
+ }
613
+ return true;
614
+ }
615
+ distinct(eq_comparer) {
616
+ if (eq_comparer == null)
617
+ eq_comparer = From._shallowEqual;
618
+ const self = this;
619
+ return From.fn(function* () {
620
+ const included = [];
621
+ for (let item of self) {
622
+ if (!From.iterable(included).any(x => eq_comparer(x, item))) {
623
+ included.push(item);
624
+ yield item;
625
+ }
626
+ }
627
+ });
628
+ }
629
+ insert(item, index) {
630
+ const self = this;
631
+ return From.fn(function* () {
632
+ let i = 0;
633
+ let inserted = false;
634
+ for (let existingItem of self) {
635
+ if (i === index) {
636
+ yield item;
637
+ inserted = true;
638
+ }
639
+ yield existingItem;
640
+ i++;
641
+ }
642
+ if (!inserted) {
643
+ yield item;
644
+ }
645
+ });
646
+ }
647
+ skip(n) {
648
+ const self = this;
649
+ return From.fn(function* () {
650
+ let i = 0;
651
+ for (let item of self) {
652
+ if (i >= n) {
653
+ yield item;
654
+ }
655
+ i++;
656
+ }
657
+ });
658
+ }
659
+ union(other) {
660
+ const self = this;
661
+ return From.fn(function* () {
662
+ yield* self;
663
+ yield* other;
664
+ });
665
+ }
666
+ innerJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
667
+ const self = this;
668
+ return From.fn(() => {
669
+ const otherByKey = new Map();
670
+ for (let item of other) {
671
+ otherByKey.set(otherKeySelector(item), item);
672
+ }
673
+ return Array.from(self)
674
+ .filter(item => otherByKey.has(thisKeySelector(item)))
675
+ .map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
676
+ });
677
+ }
678
+ leftJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
679
+ const self = this;
680
+ return From.fn(() => {
681
+ const otherByKey = new Map();
682
+ for (let item of other) {
683
+ otherByKey.set(otherKeySelector(item), item);
684
+ }
685
+ return Array.from(self).map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
686
+ });
687
+ }
688
+ leftGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
689
+ const self = this;
690
+ return From.fn(() => {
691
+ const otherByKeys = new Map();
692
+ for (let item of other) {
693
+ const key = otherKeySelector(item);
694
+ if (!otherByKeys.has(key)) {
695
+ otherByKeys.set(key, []);
696
+ }
697
+ otherByKeys.get(key).push(item);
698
+ }
699
+ return Array.from(self).map(item => resultSelector(item, otherByKeys.get(thisKeySelector(item)) || []));
700
+ });
701
+ }
702
+ rightGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
703
+ const self = this;
704
+ return From.fn(() => {
705
+ const thisByKeys = new Map();
706
+ for (let item of self) {
707
+ const key = thisKeySelector(item);
708
+ if (!thisByKeys.has(key)) {
709
+ thisByKeys.set(key, []);
710
+ }
711
+ thisByKeys.get(key).push(item);
712
+ }
713
+ return Array.from(other).map(item => resultSelector(thisByKeys.get(otherKeySelector(item)) || [], item));
714
+ });
715
+ }
716
+ rightJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
717
+ const self = this;
718
+ return From.fn(() => {
719
+ const thisByKey = new Map();
720
+ for (let item of self) {
721
+ thisByKey.set(thisKeySelector(item), item);
722
+ }
723
+ return Array.from(other).map(item => resultSelector(thisByKey.get(otherKeySelector(item)), item));
724
+ });
725
+ }
726
+ }
727
+ class Grouping extends From {
728
+ get key() {
729
+ return this._key;
730
+ }
731
+ constructor(key, values) {
732
+ super(() => values);
733
+ this._key = key;
734
+ }
735
+ }
736
+
737
+ class Timer {
738
+ /**
739
+ * @param callback Callback
740
+ * @param interval Seconds between calls
741
+ */
742
+ constructor(callback, interval) {
743
+ this._callback = callback;
744
+ this._interval = interval;
745
+ this._intervalId = null;
746
+ }
747
+ get running() {
748
+ return this._intervalId !== null && this._intervalId !== undefined;
749
+ }
750
+ get interval() {
751
+ return this._interval;
752
+ }
753
+ set interval(value) {
754
+ if (value != this._interval) {
755
+ this._interval = value;
756
+ if (this.running)
757
+ this.restart();
758
+ }
759
+ }
760
+ get callback() {
761
+ return this._callback;
762
+ }
763
+ set callback(value) {
764
+ if (value != this._callback) {
765
+ this._callback = value;
766
+ }
767
+ }
768
+ start() {
769
+ if (this._intervalId === null) {
770
+ this._intervalId = setInterval(() => {
771
+ if (this._callback != null)
772
+ this._callback();
773
+ }, this._interval);
774
+ }
775
+ }
776
+ stop() {
777
+ if (this._intervalId !== null) {
778
+ clearInterval(this._intervalId);
779
+ this._intervalId = null;
780
+ }
781
+ }
782
+ restart() {
783
+ this.stop();
784
+ this.start();
785
+ }
786
+ }
787
+
788
+ class TimeSpan {
789
+ constructor(milliseconds) {
790
+ this.milliseconds = milliseconds;
791
+ }
792
+ // Obtener el intervalo de tiempo en segundos
793
+ seconds() {
794
+ return this.milliseconds / 1000;
795
+ }
796
+ // Obtener el intervalo de tiempo en minutos
797
+ minutes() {
798
+ return this.milliseconds / (1000 * 60);
799
+ }
800
+ // Obtener el intervalo de tiempo en horas
801
+ hours() {
802
+ return this.milliseconds / (1000 * 60 * 60);
803
+ }
804
+ // Obtener el intervalo de tiempo en días
805
+ days() {
806
+ return this.milliseconds / (1000 * 60 * 60 * 24);
807
+ }
808
+ // Obtener el intervalo de tiempo en semanas
809
+ weeks() {
810
+ return this.milliseconds / (1000 * 60 * 60 * 24 * 7);
811
+ }
812
+ // Constructor estático para crear un TimeSpan desde milisegundos
813
+ static fromMilliseconds(milliseconds) {
814
+ return new TimeSpan(milliseconds);
815
+ }
816
+ // Constructor estático para crear un TimeSpan desde segundos
817
+ static fromSeconds(seconds) {
818
+ return new TimeSpan(seconds * 1000);
819
+ }
820
+ // Constructor estático para crear un TimeSpan desde minutos
821
+ static fromMinutes(minutes) {
822
+ return new TimeSpan(minutes * 1000 * 60);
823
+ }
824
+ // Constructor estático para crear un TimeSpan desde horas
825
+ static fromHours(hours) {
826
+ return new TimeSpan(hours * 1000 * 60 * 60);
827
+ }
828
+ // Constructor estático para crear un TimeSpan desde días
829
+ static fromDays(days) {
830
+ return new TimeSpan(days * 1000 * 60 * 60 * 24);
831
+ }
832
+ // Constructor estático para crear un TimeSpan desde semanas
833
+ static fromWeeks(weeks) {
834
+ return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);
835
+ }
836
+ // Añadir un intervalo de tiempo
837
+ addMilliseconds(milliseconds) {
838
+ return new TimeSpan(this.milliseconds + milliseconds);
839
+ }
840
+ addSeconds(seconds) {
841
+ return this.addMilliseconds(seconds * 1000);
842
+ }
843
+ addMinutes(minutes) {
844
+ return this.addMilliseconds(minutes * 1000 * 60);
845
+ }
846
+ addHours(hours) {
847
+ return this.addMilliseconds(hours * 1000 * 60 * 60);
848
+ }
849
+ addDays(days) {
850
+ return this.addMilliseconds(days * 1000 * 60 * 60 * 24);
851
+ }
852
+ addWeeks(weeks) {
853
+ return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
854
+ }
855
+ // Restar un intervalo de tiempo
856
+ subtractMilliseconds(milliseconds) {
857
+ return new TimeSpan(this.milliseconds - milliseconds);
858
+ }
859
+ subtractSeconds(seconds) {
860
+ return this.subtractMilliseconds(seconds * 1000);
861
+ }
862
+ subtractMinutes(minutes) {
863
+ return this.subtractMilliseconds(minutes * 1000 * 60);
864
+ }
865
+ subtractHours(hours) {
866
+ return this.subtractMilliseconds(hours * 1000 * 60 * 60);
867
+ }
868
+ subtractDays(days) {
869
+ return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);
870
+ }
871
+ subtractWeeks(weeks) {
872
+ return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
873
+ }
874
+ // Añadir otro TimeSpan
875
+ add(other) {
876
+ return new TimeSpan(this.milliseconds + other.milliseconds);
877
+ }
878
+ // Restar otro TimeSpan
879
+ subtract(other) {
880
+ return new TimeSpan(this.milliseconds - other.milliseconds);
881
+ }
882
+ // Añadir un intervalo de tiempo a una fecha
883
+ addTo(date) {
884
+ return new Date(date.getTime() + this.milliseconds);
885
+ }
886
+ // Restar un intervalo de tiempo de una fecha
887
+ subtractFrom(date) {
888
+ return new Date(date.getTime() - this.milliseconds);
889
+ }
890
+ static fromDifference(earlierDate, laterDate) {
891
+ return new TimeSpan(laterDate.getTime() - earlierDate.getTime());
892
+ }
893
+ format(format = 'hh:mm:ss') {
894
+ const formatLower = format.toLowerCase();
895
+ const hasHours = formatLower.includes("h");
896
+ const hasMinutes = formatLower.includes("m");
897
+ let hours = 0, minutes = 0, seconds = Math.floor(this.milliseconds / 1000);
898
+ if (hasHours) {
899
+ hours = Math.floor(seconds / 3600);
900
+ seconds -= hours * 3600;
901
+ }
902
+ if (hasMinutes) {
903
+ minutes = Math.floor(seconds / 60);
904
+ seconds -= minutes * 60;
905
+ }
906
+ const hoursPadded = String(hours).padStart(2, '0');
907
+ const minutesPadded = String(minutes).padStart(2, '0');
908
+ const secondsPadded = String(seconds).padStart(2, '0');
909
+ return formatLower
910
+ .replace('hh', hoursPadded)
911
+ .replace('h', hours.toString())
912
+ .replace('mm', minutesPadded)
913
+ .replace('m', minutes.toString())
914
+ .replace('ss', secondsPadded)
915
+ .replace('s', seconds.toString());
916
+ }
917
+ eq(other) {
918
+ return this.milliseconds === other.milliseconds;
919
+ }
920
+ le(other) {
921
+ return this.milliseconds <= other.milliseconds;
922
+ }
923
+ lt(other) {
924
+ return this.milliseconds < other.milliseconds;
925
+ }
926
+ ge(other) {
927
+ return this.milliseconds >= other.milliseconds;
928
+ }
929
+ gt(other) {
930
+ return this.milliseconds > other.milliseconds;
931
+ }
932
+ multiply(number) {
933
+ return new TimeSpan(this.milliseconds * number);
934
+ }
935
+ divide(number) {
936
+ return new TimeSpan(this.milliseconds / number);
937
+ }
938
+ abs() {
939
+ return new TimeSpan(Math.abs(this.milliseconds));
940
+ }
941
+ isInfinite() {
942
+ return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY;
943
+ }
944
+ // Determinar si es un TimeSpan infinitamente positivo
945
+ isPositiveInfinite() {
946
+ return this.milliseconds === Number.POSITIVE_INFINITY;
947
+ }
948
+ // Determinar si es un TimeSpan infinitamente negativo
949
+ isNegativeInfinite() {
950
+ return this.milliseconds === Number.NEGATIVE_INFINITY;
951
+ }
952
+ }
953
+ TimeSpan.INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);
954
+ TimeSpan.NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);
955
+
956
+ class Lazy {
957
+ constructor(getter) {
958
+ this._valueCreated = false;
959
+ this._value = null;
960
+ this._factoryMethod = getter;
961
+ }
962
+ get valueCreated() {
963
+ return this._valueCreated;
964
+ }
965
+ async getValue() {
966
+ if (!this._valueCreated) {
967
+ this._value = await promisify(this._factoryMethod);
968
+ this._valueCreated = true;
969
+ }
970
+ return this._value;
971
+ }
972
+ reset() {
973
+ this._valueCreated = false;
974
+ this._value = null;
975
+ }
976
+ }
977
+
978
+ class ArrayManipulator {
979
+ constructor(array) {
980
+ this._array = array;
981
+ }
982
+ [Symbol.iterator]() {
983
+ return this._array[Symbol.iterator]();
984
+ }
985
+ at(n, item = undefined) {
986
+ if (item === undefined)
987
+ return this._array[n];
988
+ else
989
+ this._array[n] = item;
990
+ }
991
+ remove(item) {
992
+ const index = this._array.indexOf(item);
993
+ if (index !== -1) {
994
+ this._array.splice(index, 1);
995
+ }
996
+ return this;
997
+ }
998
+ map(mapFn) {
999
+ for (let i = 0; i < this._array.length; i++) {
1000
+ this._array[i] = mapFn(this._array[i]);
1001
+ }
1002
+ return this;
1003
+ }
1004
+ filter(filterFn) {
1005
+ for (let i = 0; i < this._array.length; i++) {
1006
+ if (!filterFn(this._array[i])) {
1007
+ this._array.splice(i, 1);
1008
+ i--;
1009
+ }
1010
+ }
1011
+ return this;
1012
+ }
1013
+ head(n) {
1014
+ this._array.splice(n);
1015
+ return this;
1016
+ }
1017
+ slice(start, count = undefined) {
1018
+ this._array.splice(0, start); // Eliminar los primeros elementos hasta `start`
1019
+ if (count !== undefined) {
1020
+ this._array.splice(count); // Mantener solo `count` elementos restantes
1021
+ }
1022
+ return this;
1023
+ }
1024
+ mapMany(mapper) {
1025
+ let i = 0;
1026
+ while (i < this._array.length) {
1027
+ let mappedItems = mapper(this._array[i]);
1028
+ if (!Array.isArray(mappedItems))
1029
+ mappedItems = Array.from(mappedItems);
1030
+ this._array.splice(i, 1, ...mappedItems);
1031
+ i += mappedItems.length;
1032
+ }
1033
+ return this;
1034
+ }
1035
+ tail(n) {
1036
+ const start = this._array.length - n;
1037
+ this._array.splice(0, start);
1038
+ return this;
1039
+ }
1040
+ append(...items) {
1041
+ this._array.push(...items);
1042
+ return this;
1043
+ }
1044
+ prepend(...items) {
1045
+ this._array.unshift(...items);
1046
+ return this;
1047
+ }
1048
+ get array() {
1049
+ return this._array;
1050
+ }
1051
+ }
1052
+ function array(array) {
1053
+ return new ArrayManipulator(array);
1054
+ }
1055
+
1056
+ exports.ArrayManipulator = ArrayManipulator;
1057
+ exports.CacheDictionary = CacheDictionary;
1058
+ exports.From = From;
1059
+ exports.Lazy = Lazy;
1060
+ exports.Pair = Pair;
1061
+ exports.TimeSpan = TimeSpan;
1062
+ exports.Timer = Timer;
1063
+ exports.Type = Type$1;
1064
+ exports.ajaxSubmission = ajaxSubmission;
1065
+ exports.ajaxSubmit = ajaxSubmit;
1066
+ exports.array = array;
1067
+ exports.clamp = clamp;
1068
+ exports.deepClone = deepClone;
1069
+ exports.ensurePrefix = ensurePrefix;
1070
+ exports.ensureSuffix = ensureSuffix;
1071
+ exports.from = from;
1072
+ exports.isArray = isArray;
1073
+ exports.isBigInt = isBigInt;
1074
+ exports.isBoolean = isBoolean;
1075
+ exports.isDefined = isDefined;
1076
+ exports.isEmpty = isEmpty;
1077
+ exports.isEmptyOrWhitespace = isEmptyOrWhitespace;
1078
+ exports.isFunction = isFunction;
1079
+ exports.isIterable = isIterable;
1080
+ exports.isNull = isNull;
1081
+ exports.isNullOrUndefined = isNullOrUndefined;
1082
+ exports.isNumber = isNumber;
1083
+ exports.isObject = isObject;
1084
+ exports.isString = isString;
1085
+ exports.isSymbol = isSymbol;
1086
+ exports.isUndefined = isUndefined;
1087
+ exports.lerp = lerp;
1088
+ exports.objectToFormData = objectToFormData;
1089
+ exports.promisify = promisify;
1090
+ exports.toPairs = toPairs;
1091
+
1092
+ })(this.window = this.window || {});