mol_time_all 1.1.724 → 1.1.726

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_time_all",
3
- "version": "1.1.724",
3
+ "version": "1.1.726",
4
4
  "exports": {
5
5
  "node": {
6
6
  "import": "./node.mjs",
package/web.test.js CHANGED
@@ -412,6 +412,298 @@ var $;
412
412
  ;
413
413
  "use strict";
414
414
  var $;
415
+ (function ($) {
416
+ function $mol_guid(length = 8, exists = () => false) {
417
+ for (;;) {
418
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
419
+ if (exists(id))
420
+ continue;
421
+ return id;
422
+ }
423
+ }
424
+ $.$mol_guid = $mol_guid;
425
+ })($ || ($ = {}));
426
+ //mol/guid/guid.ts
427
+ ;
428
+ "use strict";
429
+ var $;
430
+ (function ($) {
431
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
432
+ return new Proxy(new $mol_range2_array(), {
433
+ get(target, field) {
434
+ if (typeof field === 'string') {
435
+ if (field === 'length')
436
+ return size();
437
+ const index = Number(field);
438
+ if (index < 0)
439
+ return undefined;
440
+ if (index >= size())
441
+ return undefined;
442
+ if (index === Math.trunc(index))
443
+ return item(index);
444
+ }
445
+ return target[field];
446
+ },
447
+ set(target, field) {
448
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
449
+ },
450
+ ownKeys(target) {
451
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
452
+ },
453
+ getOwnPropertyDescriptor(target, field) {
454
+ if (field === "length")
455
+ return {
456
+ value: size(),
457
+ writable: true,
458
+ enumerable: false,
459
+ configurable: false,
460
+ };
461
+ const index = Number(field);
462
+ if (index === Math.trunc(index))
463
+ return {
464
+ get: () => this.get(target, field, this),
465
+ enumerable: true,
466
+ configurable: true,
467
+ };
468
+ return Object.getOwnPropertyDescriptor(target, field);
469
+ }
470
+ });
471
+ }
472
+ $.$mol_range2 = $mol_range2;
473
+ class $mol_range2_array extends Array {
474
+ concat(...tail) {
475
+ if (tail.length === 0)
476
+ return this;
477
+ if (tail.length > 1) {
478
+ let list = this;
479
+ for (let item of tail)
480
+ list = list.concat(item);
481
+ return list;
482
+ }
483
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
484
+ }
485
+ filter(check, context) {
486
+ const filtered = new $mol_range2_array();
487
+ for (let index = 0; index < this.length; ++index) {
488
+ const item = this[index];
489
+ if (check.call(context, item, index, this))
490
+ filtered.push(item);
491
+ }
492
+ return filtered;
493
+ }
494
+ forEach(proceed, context) {
495
+ for (let [key, value] of this.entries())
496
+ proceed.call(context, value, key, this);
497
+ }
498
+ map(proceed, context) {
499
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
500
+ }
501
+ reduce(merge, result) {
502
+ let index = 0;
503
+ if (arguments.length === 1) {
504
+ result = this[index++];
505
+ }
506
+ for (; index < this.length; ++index) {
507
+ result = merge(result, this[index], index, this);
508
+ }
509
+ return result;
510
+ }
511
+ toReversed() {
512
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
513
+ }
514
+ slice(from = 0, to = this.length) {
515
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
516
+ }
517
+ some(check, context) {
518
+ for (let index = 0; index < this.length; ++index) {
519
+ if (check.call(context, this[index], index, this))
520
+ return true;
521
+ }
522
+ return false;
523
+ }
524
+ every(check, context) {
525
+ for (let index = 0; index < this.length; ++index) {
526
+ if (!check.call(context, this[index], index, this))
527
+ return false;
528
+ }
529
+ return true;
530
+ }
531
+ reverse() {
532
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
533
+ }
534
+ sort() {
535
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
536
+ }
537
+ [Symbol.toPrimitive]() {
538
+ return $mol_guid();
539
+ }
540
+ }
541
+ $.$mol_range2_array = $mol_range2_array;
542
+ })($ || ($ = {}));
543
+ //mol/range2/range2.ts
544
+ ;
545
+ "use strict";
546
+ var $;
547
+ (function ($) {
548
+ $mol_test({
549
+ 'lazy calls'() {
550
+ let calls = 0;
551
+ const list = $mol_range2(index => (++calls, index), () => 10);
552
+ $mol_assert_ok(list instanceof Array);
553
+ $mol_assert_equal(list.length, 10);
554
+ $mol_assert_equal(list[-1], undefined);
555
+ $mol_assert_equal(list[0], 0);
556
+ $mol_assert_equal(list[9], 9);
557
+ $mol_assert_equal(list[9.5], undefined);
558
+ $mol_assert_equal(list[10], undefined);
559
+ $mol_assert_equal(calls, 2);
560
+ },
561
+ 'infinity list'() {
562
+ let calls = 0;
563
+ const list = $mol_range2(index => (++calls, index));
564
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
565
+ $mol_assert_equal(list[0], 0);
566
+ $mol_assert_equal(list[4], 4);
567
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
568
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
569
+ $mol_assert_equal(calls, 3);
570
+ },
571
+ 'stringify'() {
572
+ const list = $mol_range2(i => i, () => 5);
573
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
574
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
575
+ },
576
+ 'for-of'() {
577
+ let log = '';
578
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
579
+ log += i;
580
+ }
581
+ $mol_assert_equal(log, '12345');
582
+ },
583
+ 'for-in'() {
584
+ let log = '';
585
+ for (let i in $mol_range2(i => i, () => 5)) {
586
+ log += i;
587
+ }
588
+ $mol_assert_equal(log, '01234');
589
+ },
590
+ 'forEach'() {
591
+ let log = '';
592
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
593
+ $mol_assert_equal(log, '01234');
594
+ },
595
+ 'lazy concat'() {
596
+ let calls1 = 0;
597
+ let calls2 = 0;
598
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
599
+ $mol_assert_ok(list instanceof Array);
600
+ $mol_assert_equal(list.length, 15);
601
+ $mol_assert_equal(list[0], 0);
602
+ $mol_assert_equal(list[4], 4);
603
+ $mol_assert_equal(list[5], 0);
604
+ $mol_assert_equal(list[9], 4);
605
+ $mol_assert_equal(list[10], 0);
606
+ $mol_assert_equal(list[14], 4);
607
+ $mol_assert_equal(list[15], undefined);
608
+ $mol_assert_equal(calls1, 2);
609
+ $mol_assert_equal(calls2, 2);
610
+ },
611
+ 'filter'() {
612
+ let calls = 0;
613
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
614
+ $mol_assert_ok(list instanceof Array);
615
+ $mol_assert_equal(list.length, 3);
616
+ $mol_assert_equal(list[0], 1);
617
+ $mol_assert_equal(list[2], 5);
618
+ $mol_assert_equal(list[3], undefined);
619
+ $mol_assert_equal(calls, 10);
620
+ },
621
+ 'reverse'() {
622
+ let calls = 0;
623
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
624
+ $mol_assert_ok(list instanceof Array);
625
+ $mol_assert_equal(list.length, 3);
626
+ $mol_assert_equal(list[0], 9);
627
+ $mol_assert_equal(list[2], 7);
628
+ $mol_assert_equal(list[3], undefined);
629
+ $mol_assert_equal(calls, 2);
630
+ },
631
+ 'reduce'() {
632
+ let calls = 0;
633
+ const list = $mol_range2().slice(1, 6);
634
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
635
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
636
+ },
637
+ 'lazy map'() {
638
+ let calls1 = 0;
639
+ let calls2 = 0;
640
+ const source = $mol_range2(index => (++calls1, index), () => 5);
641
+ const target = source.map((item, index, self) => {
642
+ ++calls2;
643
+ $mol_assert_equal(source, self);
644
+ return index + 10;
645
+ }, () => 5);
646
+ $mol_assert_ok(target instanceof Array);
647
+ $mol_assert_equal(target.length, 5);
648
+ $mol_assert_equal(target[0], 10);
649
+ $mol_assert_equal(target[4], 14);
650
+ $mol_assert_equal(target[5], undefined);
651
+ $mol_assert_equal(calls1, 2);
652
+ $mol_assert_equal(calls2, 2);
653
+ },
654
+ 'lazy slice'() {
655
+ let calls = 0;
656
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
657
+ $mol_assert_ok(list instanceof Array);
658
+ $mol_assert_equal(list.length, 4);
659
+ $mol_assert_equal(list[0], 3);
660
+ $mol_assert_equal(list[3], 6);
661
+ $mol_assert_equal(list[4], undefined);
662
+ $mol_assert_equal(calls, 2);
663
+ },
664
+ 'lazy some'() {
665
+ let calls = 0;
666
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
667
+ $mol_assert_equal(calls, 3);
668
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
669
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
670
+ },
671
+ 'lazy every'() {
672
+ let calls = 0;
673
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
674
+ $mol_assert_equal(calls, 3);
675
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
676
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
677
+ },
678
+ 'lazyfy'() {
679
+ let calls = 0;
680
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
681
+ $mol_assert_ok(list instanceof Array);
682
+ $mol_assert_equal(list.length, 4);
683
+ $mol_assert_equal(calls, 0);
684
+ $mol_assert_equal(list[0], 12);
685
+ $mol_assert_equal(list[3], 15);
686
+ $mol_assert_equal(list[4], undefined);
687
+ $mol_assert_equal(calls, 2);
688
+ },
689
+ 'prevent modification'() {
690
+ const list = $mol_range2(i => i, () => 5);
691
+ $mol_assert_fail(() => list.push(4), TypeError);
692
+ $mol_assert_fail(() => list.pop(), TypeError);
693
+ $mol_assert_fail(() => list.unshift(4), TypeError);
694
+ $mol_assert_fail(() => list.shift(), TypeError);
695
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
696
+ $mol_assert_fail(() => list[1] = 2, TypeError);
697
+ $mol_assert_fail(() => list.reverse(), TypeError);
698
+ $mol_assert_fail(() => list.sort(), TypeError);
699
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
700
+ }
701
+ });
702
+ })($ || ($ = {}));
703
+ //mol/range2/range2.test.ts
704
+ ;
705
+ "use strict";
706
+ var $;
415
707
  (function ($) {
416
708
  $.$mol_compare_deep_cache = new WeakMap();
417
709
  function $mol_compare_deep(left, right) {
@@ -457,6 +749,8 @@ var $;
457
749
  result = compare_pojo(left, right);
458
750
  else if (!Reflect.getPrototypeOf(left_proto))
459
751
  result = compare_pojo(left, right);
752
+ else if (Symbol.toPrimitive in left)
753
+ result = compare_primitive(left, right);
460
754
  else if (Array.isArray(left))
461
755
  result = compare_array(left, right);
462
756
  else if (left instanceof Set)
@@ -467,8 +761,6 @@ var $;
467
761
  result = compare_buffer(left, right);
468
762
  else if (Symbol.iterator in left)
469
763
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
470
- else if (Symbol.toPrimitive in left)
471
- result = compare_primitive(left, right);
472
764
  else
473
765
  result = false;
474
766
  }
@@ -578,6 +870,8 @@ var $;
578
870
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
579
871
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
580
872
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
873
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
874
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
581
875
  },
582
876
  'Non POJO are different'() {
583
877
  class Thing extends Object {