mol_key 0.0.616 → 0.0.617

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_key",
3
- "version": "0.0.616",
3
+ "version": "0.0.617",
4
4
  "exports": {
5
5
  "node": {
6
6
  "import": "./node.mjs",
package/web.test.js CHANGED
@@ -684,6 +684,283 @@ var $;
684
684
  ;
685
685
  "use strict";
686
686
  var $;
687
+ (function ($) {
688
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
689
+ return new Proxy(new $mol_range2_array(), {
690
+ get(target, field) {
691
+ if (typeof field === 'string') {
692
+ if (field === 'length')
693
+ return size();
694
+ const index = Number(field);
695
+ if (index < 0)
696
+ return undefined;
697
+ if (index >= size())
698
+ return undefined;
699
+ if (index === Math.trunc(index))
700
+ return item(index);
701
+ }
702
+ return target[field];
703
+ },
704
+ set(target, field) {
705
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
706
+ },
707
+ ownKeys(target) {
708
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
709
+ },
710
+ getOwnPropertyDescriptor(target, field) {
711
+ if (field === "length")
712
+ return {
713
+ value: size(),
714
+ writable: true,
715
+ enumerable: false,
716
+ configurable: false,
717
+ };
718
+ const index = Number(field);
719
+ if (index === Math.trunc(index))
720
+ return {
721
+ get: () => this.get(target, field, this),
722
+ enumerable: true,
723
+ configurable: true,
724
+ };
725
+ return Object.getOwnPropertyDescriptor(target, field);
726
+ }
727
+ });
728
+ }
729
+ $.$mol_range2 = $mol_range2;
730
+ class $mol_range2_array extends Array {
731
+ concat(...tail) {
732
+ if (tail.length === 0)
733
+ return this;
734
+ if (tail.length > 1) {
735
+ let list = this;
736
+ for (let item of tail)
737
+ list = list.concat(item);
738
+ return list;
739
+ }
740
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
741
+ }
742
+ filter(check, context) {
743
+ const filtered = new $mol_range2_array();
744
+ for (let index = 0; index < this.length; ++index) {
745
+ const item = this[index];
746
+ if (check.call(context, item, index, this))
747
+ filtered.push(item);
748
+ }
749
+ return filtered;
750
+ }
751
+ forEach(proceed, context) {
752
+ for (let [key, value] of this.entries())
753
+ proceed.call(context, value, key, this);
754
+ }
755
+ map(proceed, context) {
756
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
757
+ }
758
+ reduce(merge, result) {
759
+ let index = 0;
760
+ if (arguments.length === 1) {
761
+ result = this[index++];
762
+ }
763
+ for (; index < this.length; ++index) {
764
+ result = merge(result, this[index], index, this);
765
+ }
766
+ return result;
767
+ }
768
+ toReversed() {
769
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
770
+ }
771
+ slice(from = 0, to = this.length) {
772
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
773
+ }
774
+ some(check, context) {
775
+ for (let index = 0; index < this.length; ++index) {
776
+ if (check.call(context, this[index], index, this))
777
+ return true;
778
+ }
779
+ return false;
780
+ }
781
+ every(check, context) {
782
+ for (let index = 0; index < this.length; ++index) {
783
+ if (!check.call(context, this[index], index, this))
784
+ return false;
785
+ }
786
+ return true;
787
+ }
788
+ reverse() {
789
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
790
+ }
791
+ sort() {
792
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
793
+ }
794
+ [Symbol.toPrimitive]() {
795
+ return $mol_guid();
796
+ }
797
+ }
798
+ $.$mol_range2_array = $mol_range2_array;
799
+ })($ || ($ = {}));
800
+ //mol/range2/range2.ts
801
+ ;
802
+ "use strict";
803
+ var $;
804
+ (function ($) {
805
+ $mol_test({
806
+ 'lazy calls'() {
807
+ let calls = 0;
808
+ const list = $mol_range2(index => (++calls, index), () => 10);
809
+ $mol_assert_ok(list instanceof Array);
810
+ $mol_assert_equal(list.length, 10);
811
+ $mol_assert_equal(list[-1], undefined);
812
+ $mol_assert_equal(list[0], 0);
813
+ $mol_assert_equal(list[9], 9);
814
+ $mol_assert_equal(list[9.5], undefined);
815
+ $mol_assert_equal(list[10], undefined);
816
+ $mol_assert_equal(calls, 2);
817
+ },
818
+ 'infinity list'() {
819
+ let calls = 0;
820
+ const list = $mol_range2(index => (++calls, index));
821
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
822
+ $mol_assert_equal(list[0], 0);
823
+ $mol_assert_equal(list[4], 4);
824
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
825
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
826
+ $mol_assert_equal(calls, 3);
827
+ },
828
+ 'stringify'() {
829
+ const list = $mol_range2(i => i, () => 5);
830
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
831
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
832
+ },
833
+ 'for-of'() {
834
+ let log = '';
835
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
836
+ log += i;
837
+ }
838
+ $mol_assert_equal(log, '12345');
839
+ },
840
+ 'for-in'() {
841
+ let log = '';
842
+ for (let i in $mol_range2(i => i, () => 5)) {
843
+ log += i;
844
+ }
845
+ $mol_assert_equal(log, '01234');
846
+ },
847
+ 'forEach'() {
848
+ let log = '';
849
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
850
+ $mol_assert_equal(log, '01234');
851
+ },
852
+ 'lazy concat'() {
853
+ let calls1 = 0;
854
+ let calls2 = 0;
855
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
856
+ $mol_assert_ok(list instanceof Array);
857
+ $mol_assert_equal(list.length, 15);
858
+ $mol_assert_equal(list[0], 0);
859
+ $mol_assert_equal(list[4], 4);
860
+ $mol_assert_equal(list[5], 0);
861
+ $mol_assert_equal(list[9], 4);
862
+ $mol_assert_equal(list[10], 0);
863
+ $mol_assert_equal(list[14], 4);
864
+ $mol_assert_equal(list[15], undefined);
865
+ $mol_assert_equal(calls1, 2);
866
+ $mol_assert_equal(calls2, 2);
867
+ },
868
+ 'filter'() {
869
+ let calls = 0;
870
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
871
+ $mol_assert_ok(list instanceof Array);
872
+ $mol_assert_equal(list.length, 3);
873
+ $mol_assert_equal(list[0], 1);
874
+ $mol_assert_equal(list[2], 5);
875
+ $mol_assert_equal(list[3], undefined);
876
+ $mol_assert_equal(calls, 10);
877
+ },
878
+ 'reverse'() {
879
+ let calls = 0;
880
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
881
+ $mol_assert_ok(list instanceof Array);
882
+ $mol_assert_equal(list.length, 3);
883
+ $mol_assert_equal(list[0], 9);
884
+ $mol_assert_equal(list[2], 7);
885
+ $mol_assert_equal(list[3], undefined);
886
+ $mol_assert_equal(calls, 2);
887
+ },
888
+ 'reduce'() {
889
+ let calls = 0;
890
+ const list = $mol_range2().slice(1, 6);
891
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
892
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
893
+ },
894
+ 'lazy map'() {
895
+ let calls1 = 0;
896
+ let calls2 = 0;
897
+ const source = $mol_range2(index => (++calls1, index), () => 5);
898
+ const target = source.map((item, index, self) => {
899
+ ++calls2;
900
+ $mol_assert_equal(source, self);
901
+ return index + 10;
902
+ }, () => 5);
903
+ $mol_assert_ok(target instanceof Array);
904
+ $mol_assert_equal(target.length, 5);
905
+ $mol_assert_equal(target[0], 10);
906
+ $mol_assert_equal(target[4], 14);
907
+ $mol_assert_equal(target[5], undefined);
908
+ $mol_assert_equal(calls1, 2);
909
+ $mol_assert_equal(calls2, 2);
910
+ },
911
+ 'lazy slice'() {
912
+ let calls = 0;
913
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
914
+ $mol_assert_ok(list instanceof Array);
915
+ $mol_assert_equal(list.length, 4);
916
+ $mol_assert_equal(list[0], 3);
917
+ $mol_assert_equal(list[3], 6);
918
+ $mol_assert_equal(list[4], undefined);
919
+ $mol_assert_equal(calls, 2);
920
+ },
921
+ 'lazy some'() {
922
+ let calls = 0;
923
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
924
+ $mol_assert_equal(calls, 3);
925
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
926
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
927
+ },
928
+ 'lazy every'() {
929
+ let calls = 0;
930
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
931
+ $mol_assert_equal(calls, 3);
932
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
933
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
934
+ },
935
+ 'lazyfy'() {
936
+ let calls = 0;
937
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
938
+ $mol_assert_ok(list instanceof Array);
939
+ $mol_assert_equal(list.length, 4);
940
+ $mol_assert_equal(calls, 0);
941
+ $mol_assert_equal(list[0], 12);
942
+ $mol_assert_equal(list[3], 15);
943
+ $mol_assert_equal(list[4], undefined);
944
+ $mol_assert_equal(calls, 2);
945
+ },
946
+ 'prevent modification'() {
947
+ const list = $mol_range2(i => i, () => 5);
948
+ $mol_assert_fail(() => list.push(4), TypeError);
949
+ $mol_assert_fail(() => list.pop(), TypeError);
950
+ $mol_assert_fail(() => list.unshift(4), TypeError);
951
+ $mol_assert_fail(() => list.shift(), TypeError);
952
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
953
+ $mol_assert_fail(() => list[1] = 2, TypeError);
954
+ $mol_assert_fail(() => list.reverse(), TypeError);
955
+ $mol_assert_fail(() => list.sort(), TypeError);
956
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
957
+ }
958
+ });
959
+ })($ || ($ = {}));
960
+ //mol/range2/range2.test.ts
961
+ ;
962
+ "use strict";
963
+ var $;
687
964
  (function ($) {
688
965
  $.$mol_compare_deep_cache = new WeakMap();
689
966
  function $mol_compare_deep(left, right) {
@@ -729,6 +1006,8 @@ var $;
729
1006
  result = compare_pojo(left, right);
730
1007
  else if (!Reflect.getPrototypeOf(left_proto))
731
1008
  result = compare_pojo(left, right);
1009
+ else if (Symbol.toPrimitive in left)
1010
+ result = compare_primitive(left, right);
732
1011
  else if (Array.isArray(left))
733
1012
  result = compare_array(left, right);
734
1013
  else if (left instanceof Set)
@@ -739,8 +1018,6 @@ var $;
739
1018
  result = compare_buffer(left, right);
740
1019
  else if (Symbol.iterator in left)
741
1020
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
742
- else if (Symbol.toPrimitive in left)
743
- result = compare_primitive(left, right);
744
1021
  else
745
1022
  result = false;
746
1023
  }
@@ -850,6 +1127,8 @@ var $;
850
1127
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
851
1128
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
852
1129
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
1130
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
1131
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
853
1132
  },
854
1133
  'Non POJO are different'() {
855
1134
  class Thing extends Object {