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