mol_jsx_lib 0.0.613 → 0.0.615

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/node.mjs CHANGED
@@ -1743,6 +1743,8 @@ var $;
1743
1743
  result = compare_pojo(left, right);
1744
1744
  else if (!Reflect.getPrototypeOf(left_proto))
1745
1745
  result = compare_pojo(left, right);
1746
+ else if (Symbol.toPrimitive in left)
1747
+ result = compare_primitive(left, right);
1746
1748
  else if (Array.isArray(left))
1747
1749
  result = compare_array(left, right);
1748
1750
  else if (left instanceof Set)
@@ -1753,8 +1755,6 @@ var $;
1753
1755
  result = compare_buffer(left, right);
1754
1756
  else if (Symbol.iterator in left)
1755
1757
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1756
- else if (Symbol.toPrimitive in left)
1757
- result = compare_primitive(left, right);
1758
1758
  else
1759
1759
  result = false;
1760
1760
  }
package/node.test.js CHANGED
@@ -1735,6 +1735,8 @@ var $;
1735
1735
  result = compare_pojo(left, right);
1736
1736
  else if (!Reflect.getPrototypeOf(left_proto))
1737
1737
  result = compare_pojo(left, right);
1738
+ else if (Symbol.toPrimitive in left)
1739
+ result = compare_primitive(left, right);
1738
1740
  else if (Array.isArray(left))
1739
1741
  result = compare_array(left, right);
1740
1742
  else if (left instanceof Set)
@@ -1745,8 +1747,6 @@ var $;
1745
1747
  result = compare_buffer(left, right);
1746
1748
  else if (Symbol.iterator in left)
1747
1749
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1748
- else if (Symbol.toPrimitive in left)
1749
- result = compare_primitive(left, right);
1750
1750
  else
1751
1751
  result = false;
1752
1752
  }
@@ -3628,6 +3628,283 @@ var $;
3628
3628
  ;
3629
3629
  "use strict";
3630
3630
  var $;
3631
+ (function ($) {
3632
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
3633
+ return new Proxy(new $mol_range2_array(), {
3634
+ get(target, field) {
3635
+ if (typeof field === 'string') {
3636
+ if (field === 'length')
3637
+ return size();
3638
+ const index = Number(field);
3639
+ if (index < 0)
3640
+ return undefined;
3641
+ if (index >= size())
3642
+ return undefined;
3643
+ if (index === Math.trunc(index))
3644
+ return item(index);
3645
+ }
3646
+ return target[field];
3647
+ },
3648
+ set(target, field) {
3649
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
3650
+ },
3651
+ ownKeys(target) {
3652
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
3653
+ },
3654
+ getOwnPropertyDescriptor(target, field) {
3655
+ if (field === "length")
3656
+ return {
3657
+ value: size(),
3658
+ writable: true,
3659
+ enumerable: false,
3660
+ configurable: false,
3661
+ };
3662
+ const index = Number(field);
3663
+ if (index === Math.trunc(index))
3664
+ return {
3665
+ get: () => this.get(target, field, this),
3666
+ enumerable: true,
3667
+ configurable: true,
3668
+ };
3669
+ return Object.getOwnPropertyDescriptor(target, field);
3670
+ }
3671
+ });
3672
+ }
3673
+ $.$mol_range2 = $mol_range2;
3674
+ class $mol_range2_array extends Array {
3675
+ concat(...tail) {
3676
+ if (tail.length === 0)
3677
+ return this;
3678
+ if (tail.length > 1) {
3679
+ let list = this;
3680
+ for (let item of tail)
3681
+ list = list.concat(item);
3682
+ return list;
3683
+ }
3684
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
3685
+ }
3686
+ filter(check, context) {
3687
+ const filtered = new $mol_range2_array();
3688
+ for (let index = 0; index < this.length; ++index) {
3689
+ const item = this[index];
3690
+ if (check.call(context, item, index, this))
3691
+ filtered.push(item);
3692
+ }
3693
+ return filtered;
3694
+ }
3695
+ forEach(proceed, context) {
3696
+ for (let [key, value] of this.entries())
3697
+ proceed.call(context, value, key, this);
3698
+ }
3699
+ map(proceed, context) {
3700
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
3701
+ }
3702
+ reduce(merge, result) {
3703
+ let index = 0;
3704
+ if (arguments.length === 1) {
3705
+ result = this[index++];
3706
+ }
3707
+ for (; index < this.length; ++index) {
3708
+ result = merge(result, this[index], index, this);
3709
+ }
3710
+ return result;
3711
+ }
3712
+ toReversed() {
3713
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
3714
+ }
3715
+ slice(from = 0, to = this.length) {
3716
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
3717
+ }
3718
+ some(check, context) {
3719
+ for (let index = 0; index < this.length; ++index) {
3720
+ if (check.call(context, this[index], index, this))
3721
+ return true;
3722
+ }
3723
+ return false;
3724
+ }
3725
+ every(check, context) {
3726
+ for (let index = 0; index < this.length; ++index) {
3727
+ if (!check.call(context, this[index], index, this))
3728
+ return false;
3729
+ }
3730
+ return true;
3731
+ }
3732
+ reverse() {
3733
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
3734
+ }
3735
+ sort() {
3736
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
3737
+ }
3738
+ [Symbol.toPrimitive]() {
3739
+ return $mol_guid();
3740
+ }
3741
+ }
3742
+ $.$mol_range2_array = $mol_range2_array;
3743
+ })($ || ($ = {}));
3744
+ //mol/range2/range2.ts
3745
+ ;
3746
+ "use strict";
3747
+ var $;
3748
+ (function ($) {
3749
+ $mol_test({
3750
+ 'lazy calls'() {
3751
+ let calls = 0;
3752
+ const list = $mol_range2(index => (++calls, index), () => 10);
3753
+ $mol_assert_ok(list instanceof Array);
3754
+ $mol_assert_equal(list.length, 10);
3755
+ $mol_assert_equal(list[-1], undefined);
3756
+ $mol_assert_equal(list[0], 0);
3757
+ $mol_assert_equal(list[9], 9);
3758
+ $mol_assert_equal(list[9.5], undefined);
3759
+ $mol_assert_equal(list[10], undefined);
3760
+ $mol_assert_equal(calls, 2);
3761
+ },
3762
+ 'infinity list'() {
3763
+ let calls = 0;
3764
+ const list = $mol_range2(index => (++calls, index));
3765
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
3766
+ $mol_assert_equal(list[0], 0);
3767
+ $mol_assert_equal(list[4], 4);
3768
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
3769
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
3770
+ $mol_assert_equal(calls, 3);
3771
+ },
3772
+ 'stringify'() {
3773
+ const list = $mol_range2(i => i, () => 5);
3774
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3775
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
3776
+ },
3777
+ 'for-of'() {
3778
+ let log = '';
3779
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
3780
+ log += i;
3781
+ }
3782
+ $mol_assert_equal(log, '12345');
3783
+ },
3784
+ 'for-in'() {
3785
+ let log = '';
3786
+ for (let i in $mol_range2(i => i, () => 5)) {
3787
+ log += i;
3788
+ }
3789
+ $mol_assert_equal(log, '01234');
3790
+ },
3791
+ 'forEach'() {
3792
+ let log = '';
3793
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
3794
+ $mol_assert_equal(log, '01234');
3795
+ },
3796
+ 'lazy concat'() {
3797
+ let calls1 = 0;
3798
+ let calls2 = 0;
3799
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
3800
+ $mol_assert_ok(list instanceof Array);
3801
+ $mol_assert_equal(list.length, 15);
3802
+ $mol_assert_equal(list[0], 0);
3803
+ $mol_assert_equal(list[4], 4);
3804
+ $mol_assert_equal(list[5], 0);
3805
+ $mol_assert_equal(list[9], 4);
3806
+ $mol_assert_equal(list[10], 0);
3807
+ $mol_assert_equal(list[14], 4);
3808
+ $mol_assert_equal(list[15], undefined);
3809
+ $mol_assert_equal(calls1, 2);
3810
+ $mol_assert_equal(calls2, 2);
3811
+ },
3812
+ 'filter'() {
3813
+ let calls = 0;
3814
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
3815
+ $mol_assert_ok(list instanceof Array);
3816
+ $mol_assert_equal(list.length, 3);
3817
+ $mol_assert_equal(list[0], 1);
3818
+ $mol_assert_equal(list[2], 5);
3819
+ $mol_assert_equal(list[3], undefined);
3820
+ $mol_assert_equal(calls, 10);
3821
+ },
3822
+ 'reverse'() {
3823
+ let calls = 0;
3824
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
3825
+ $mol_assert_ok(list instanceof Array);
3826
+ $mol_assert_equal(list.length, 3);
3827
+ $mol_assert_equal(list[0], 9);
3828
+ $mol_assert_equal(list[2], 7);
3829
+ $mol_assert_equal(list[3], undefined);
3830
+ $mol_assert_equal(calls, 2);
3831
+ },
3832
+ 'reduce'() {
3833
+ let calls = 0;
3834
+ const list = $mol_range2().slice(1, 6);
3835
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
3836
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
3837
+ },
3838
+ 'lazy map'() {
3839
+ let calls1 = 0;
3840
+ let calls2 = 0;
3841
+ const source = $mol_range2(index => (++calls1, index), () => 5);
3842
+ const target = source.map((item, index, self) => {
3843
+ ++calls2;
3844
+ $mol_assert_equal(source, self);
3845
+ return index + 10;
3846
+ }, () => 5);
3847
+ $mol_assert_ok(target instanceof Array);
3848
+ $mol_assert_equal(target.length, 5);
3849
+ $mol_assert_equal(target[0], 10);
3850
+ $mol_assert_equal(target[4], 14);
3851
+ $mol_assert_equal(target[5], undefined);
3852
+ $mol_assert_equal(calls1, 2);
3853
+ $mol_assert_equal(calls2, 2);
3854
+ },
3855
+ 'lazy slice'() {
3856
+ let calls = 0;
3857
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
3858
+ $mol_assert_ok(list instanceof Array);
3859
+ $mol_assert_equal(list.length, 4);
3860
+ $mol_assert_equal(list[0], 3);
3861
+ $mol_assert_equal(list[3], 6);
3862
+ $mol_assert_equal(list[4], undefined);
3863
+ $mol_assert_equal(calls, 2);
3864
+ },
3865
+ 'lazy some'() {
3866
+ let calls = 0;
3867
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
3868
+ $mol_assert_equal(calls, 3);
3869
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
3870
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
3871
+ },
3872
+ 'lazy every'() {
3873
+ let calls = 0;
3874
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
3875
+ $mol_assert_equal(calls, 3);
3876
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
3877
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
3878
+ },
3879
+ 'lazyfy'() {
3880
+ let calls = 0;
3881
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
3882
+ $mol_assert_ok(list instanceof Array);
3883
+ $mol_assert_equal(list.length, 4);
3884
+ $mol_assert_equal(calls, 0);
3885
+ $mol_assert_equal(list[0], 12);
3886
+ $mol_assert_equal(list[3], 15);
3887
+ $mol_assert_equal(list[4], undefined);
3888
+ $mol_assert_equal(calls, 2);
3889
+ },
3890
+ 'prevent modification'() {
3891
+ const list = $mol_range2(i => i, () => 5);
3892
+ $mol_assert_fail(() => list.push(4), TypeError);
3893
+ $mol_assert_fail(() => list.pop(), TypeError);
3894
+ $mol_assert_fail(() => list.unshift(4), TypeError);
3895
+ $mol_assert_fail(() => list.shift(), TypeError);
3896
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3897
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3898
+ $mol_assert_fail(() => list.reverse(), TypeError);
3899
+ $mol_assert_fail(() => list.sort(), TypeError);
3900
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3901
+ }
3902
+ });
3903
+ })($ || ($ = {}));
3904
+ //mol/range2/range2.test.ts
3905
+ ;
3906
+ "use strict";
3907
+ var $;
3631
3908
  (function ($) {
3632
3909
  $mol_test({
3633
3910
  'nulls & undefineds'() {
@@ -3657,6 +3934,8 @@ var $;
3657
3934
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
3658
3935
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
3659
3936
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
3937
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
3938
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
3660
3939
  },
3661
3940
  'Non POJO are different'() {
3662
3941
  class Thing extends Object {