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