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