mol_jsx_lib 0.0.613 → 0.0.614
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.js +2 -2
- package/node.js.map +1 -1
- package/node.mjs +2 -2
- package/node.test.js +281 -2
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.js +2 -2
- package/web.js.map +1 -1
- package/web.mjs +2 -2
- package/web.test.js +279 -0
- package/web.test.js.map +1 -1
package/web.mjs
CHANGED
|
@@ -1146,6 +1146,8 @@ var $;
|
|
|
1146
1146
|
result = compare_pojo(left, right);
|
|
1147
1147
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
1148
1148
|
result = compare_pojo(left, right);
|
|
1149
|
+
else if (Symbol.toPrimitive in left)
|
|
1150
|
+
result = compare_primitive(left, right);
|
|
1149
1151
|
else if (Array.isArray(left))
|
|
1150
1152
|
result = compare_array(left, right);
|
|
1151
1153
|
else if (left instanceof Set)
|
|
@@ -1156,8 +1158,6 @@ var $;
|
|
|
1156
1158
|
result = compare_buffer(left, right);
|
|
1157
1159
|
else if (Symbol.iterator in left)
|
|
1158
1160
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
1159
|
-
else if (Symbol.toPrimitive in left)
|
|
1160
|
-
result = compare_primitive(left, right);
|
|
1161
1161
|
else
|
|
1162
1162
|
result = false;
|
|
1163
1163
|
}
|
package/web.test.js
CHANGED
|
@@ -723,6 +723,283 @@ var $;
|
|
|
723
723
|
;
|
|
724
724
|
"use strict";
|
|
725
725
|
var $;
|
|
726
|
+
(function ($) {
|
|
727
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
728
|
+
return new Proxy(new $mol_range2_array(), {
|
|
729
|
+
get(target, field) {
|
|
730
|
+
if (typeof field === 'string') {
|
|
731
|
+
if (field === 'length')
|
|
732
|
+
return size();
|
|
733
|
+
const index = Number(field);
|
|
734
|
+
if (index < 0)
|
|
735
|
+
return undefined;
|
|
736
|
+
if (index >= size())
|
|
737
|
+
return undefined;
|
|
738
|
+
if (index === Math.trunc(index))
|
|
739
|
+
return item(index);
|
|
740
|
+
}
|
|
741
|
+
return target[field];
|
|
742
|
+
},
|
|
743
|
+
set(target, field) {
|
|
744
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
745
|
+
},
|
|
746
|
+
ownKeys(target) {
|
|
747
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
748
|
+
},
|
|
749
|
+
getOwnPropertyDescriptor(target, field) {
|
|
750
|
+
if (field === "length")
|
|
751
|
+
return {
|
|
752
|
+
value: size(),
|
|
753
|
+
writable: true,
|
|
754
|
+
enumerable: false,
|
|
755
|
+
configurable: false,
|
|
756
|
+
};
|
|
757
|
+
const index = Number(field);
|
|
758
|
+
if (index === Math.trunc(index))
|
|
759
|
+
return {
|
|
760
|
+
get: () => this.get(target, field, this),
|
|
761
|
+
enumerable: true,
|
|
762
|
+
configurable: true,
|
|
763
|
+
};
|
|
764
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
$.$mol_range2 = $mol_range2;
|
|
769
|
+
class $mol_range2_array extends Array {
|
|
770
|
+
concat(...tail) {
|
|
771
|
+
if (tail.length === 0)
|
|
772
|
+
return this;
|
|
773
|
+
if (tail.length > 1) {
|
|
774
|
+
let list = this;
|
|
775
|
+
for (let item of tail)
|
|
776
|
+
list = list.concat(item);
|
|
777
|
+
return list;
|
|
778
|
+
}
|
|
779
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
780
|
+
}
|
|
781
|
+
filter(check, context) {
|
|
782
|
+
const filtered = new $mol_range2_array();
|
|
783
|
+
for (let index = 0; index < this.length; ++index) {
|
|
784
|
+
const item = this[index];
|
|
785
|
+
if (check.call(context, item, index, this))
|
|
786
|
+
filtered.push(item);
|
|
787
|
+
}
|
|
788
|
+
return filtered;
|
|
789
|
+
}
|
|
790
|
+
forEach(proceed, context) {
|
|
791
|
+
for (let [key, value] of this.entries())
|
|
792
|
+
proceed.call(context, value, key, this);
|
|
793
|
+
}
|
|
794
|
+
map(proceed, context) {
|
|
795
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
796
|
+
}
|
|
797
|
+
reduce(merge, result) {
|
|
798
|
+
let index = 0;
|
|
799
|
+
if (arguments.length === 1) {
|
|
800
|
+
result = this[index++];
|
|
801
|
+
}
|
|
802
|
+
for (; index < this.length; ++index) {
|
|
803
|
+
result = merge(result, this[index], index, this);
|
|
804
|
+
}
|
|
805
|
+
return result;
|
|
806
|
+
}
|
|
807
|
+
toReversed() {
|
|
808
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
809
|
+
}
|
|
810
|
+
slice(from = 0, to = this.length) {
|
|
811
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
812
|
+
}
|
|
813
|
+
some(check, context) {
|
|
814
|
+
for (let index = 0; index < this.length; ++index) {
|
|
815
|
+
if (check.call(context, this[index], index, this))
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
every(check, context) {
|
|
821
|
+
for (let index = 0; index < this.length; ++index) {
|
|
822
|
+
if (!check.call(context, this[index], index, this))
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
return true;
|
|
826
|
+
}
|
|
827
|
+
reverse() {
|
|
828
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
829
|
+
}
|
|
830
|
+
sort() {
|
|
831
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
832
|
+
}
|
|
833
|
+
[Symbol.toPrimitive]() {
|
|
834
|
+
return $mol_guid();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
838
|
+
})($ || ($ = {}));
|
|
839
|
+
//mol/range2/range2.ts
|
|
840
|
+
;
|
|
841
|
+
"use strict";
|
|
842
|
+
var $;
|
|
843
|
+
(function ($) {
|
|
844
|
+
$mol_test({
|
|
845
|
+
'lazy calls'() {
|
|
846
|
+
let calls = 0;
|
|
847
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
848
|
+
$mol_assert_ok(list instanceof Array);
|
|
849
|
+
$mol_assert_equal(list.length, 10);
|
|
850
|
+
$mol_assert_equal(list[-1], undefined);
|
|
851
|
+
$mol_assert_equal(list[0], 0);
|
|
852
|
+
$mol_assert_equal(list[9], 9);
|
|
853
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
854
|
+
$mol_assert_equal(list[10], undefined);
|
|
855
|
+
$mol_assert_equal(calls, 2);
|
|
856
|
+
},
|
|
857
|
+
'infinity list'() {
|
|
858
|
+
let calls = 0;
|
|
859
|
+
const list = $mol_range2(index => (++calls, index));
|
|
860
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
861
|
+
$mol_assert_equal(list[0], 0);
|
|
862
|
+
$mol_assert_equal(list[4], 4);
|
|
863
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
864
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
865
|
+
$mol_assert_equal(calls, 3);
|
|
866
|
+
},
|
|
867
|
+
'stringify'() {
|
|
868
|
+
const list = $mol_range2(i => i, () => 5);
|
|
869
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
870
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
871
|
+
},
|
|
872
|
+
'for-of'() {
|
|
873
|
+
let log = '';
|
|
874
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
875
|
+
log += i;
|
|
876
|
+
}
|
|
877
|
+
$mol_assert_equal(log, '12345');
|
|
878
|
+
},
|
|
879
|
+
'for-in'() {
|
|
880
|
+
let log = '';
|
|
881
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
882
|
+
log += i;
|
|
883
|
+
}
|
|
884
|
+
$mol_assert_equal(log, '01234');
|
|
885
|
+
},
|
|
886
|
+
'forEach'() {
|
|
887
|
+
let log = '';
|
|
888
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
889
|
+
$mol_assert_equal(log, '01234');
|
|
890
|
+
},
|
|
891
|
+
'lazy concat'() {
|
|
892
|
+
let calls1 = 0;
|
|
893
|
+
let calls2 = 0;
|
|
894
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
895
|
+
$mol_assert_ok(list instanceof Array);
|
|
896
|
+
$mol_assert_equal(list.length, 15);
|
|
897
|
+
$mol_assert_equal(list[0], 0);
|
|
898
|
+
$mol_assert_equal(list[4], 4);
|
|
899
|
+
$mol_assert_equal(list[5], 0);
|
|
900
|
+
$mol_assert_equal(list[9], 4);
|
|
901
|
+
$mol_assert_equal(list[10], 0);
|
|
902
|
+
$mol_assert_equal(list[14], 4);
|
|
903
|
+
$mol_assert_equal(list[15], undefined);
|
|
904
|
+
$mol_assert_equal(calls1, 2);
|
|
905
|
+
$mol_assert_equal(calls2, 2);
|
|
906
|
+
},
|
|
907
|
+
'filter'() {
|
|
908
|
+
let calls = 0;
|
|
909
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
910
|
+
$mol_assert_ok(list instanceof Array);
|
|
911
|
+
$mol_assert_equal(list.length, 3);
|
|
912
|
+
$mol_assert_equal(list[0], 1);
|
|
913
|
+
$mol_assert_equal(list[2], 5);
|
|
914
|
+
$mol_assert_equal(list[3], undefined);
|
|
915
|
+
$mol_assert_equal(calls, 10);
|
|
916
|
+
},
|
|
917
|
+
'reverse'() {
|
|
918
|
+
let calls = 0;
|
|
919
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
920
|
+
$mol_assert_ok(list instanceof Array);
|
|
921
|
+
$mol_assert_equal(list.length, 3);
|
|
922
|
+
$mol_assert_equal(list[0], 9);
|
|
923
|
+
$mol_assert_equal(list[2], 7);
|
|
924
|
+
$mol_assert_equal(list[3], undefined);
|
|
925
|
+
$mol_assert_equal(calls, 2);
|
|
926
|
+
},
|
|
927
|
+
'reduce'() {
|
|
928
|
+
let calls = 0;
|
|
929
|
+
const list = $mol_range2().slice(1, 6);
|
|
930
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
931
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
932
|
+
},
|
|
933
|
+
'lazy map'() {
|
|
934
|
+
let calls1 = 0;
|
|
935
|
+
let calls2 = 0;
|
|
936
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
937
|
+
const target = source.map((item, index, self) => {
|
|
938
|
+
++calls2;
|
|
939
|
+
$mol_assert_equal(source, self);
|
|
940
|
+
return index + 10;
|
|
941
|
+
}, () => 5);
|
|
942
|
+
$mol_assert_ok(target instanceof Array);
|
|
943
|
+
$mol_assert_equal(target.length, 5);
|
|
944
|
+
$mol_assert_equal(target[0], 10);
|
|
945
|
+
$mol_assert_equal(target[4], 14);
|
|
946
|
+
$mol_assert_equal(target[5], undefined);
|
|
947
|
+
$mol_assert_equal(calls1, 2);
|
|
948
|
+
$mol_assert_equal(calls2, 2);
|
|
949
|
+
},
|
|
950
|
+
'lazy slice'() {
|
|
951
|
+
let calls = 0;
|
|
952
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
953
|
+
$mol_assert_ok(list instanceof Array);
|
|
954
|
+
$mol_assert_equal(list.length, 4);
|
|
955
|
+
$mol_assert_equal(list[0], 3);
|
|
956
|
+
$mol_assert_equal(list[3], 6);
|
|
957
|
+
$mol_assert_equal(list[4], undefined);
|
|
958
|
+
$mol_assert_equal(calls, 2);
|
|
959
|
+
},
|
|
960
|
+
'lazy some'() {
|
|
961
|
+
let calls = 0;
|
|
962
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
963
|
+
$mol_assert_equal(calls, 3);
|
|
964
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
965
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
966
|
+
},
|
|
967
|
+
'lazy every'() {
|
|
968
|
+
let calls = 0;
|
|
969
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
970
|
+
$mol_assert_equal(calls, 3);
|
|
971
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
972
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
973
|
+
},
|
|
974
|
+
'lazyfy'() {
|
|
975
|
+
let calls = 0;
|
|
976
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
977
|
+
$mol_assert_ok(list instanceof Array);
|
|
978
|
+
$mol_assert_equal(list.length, 4);
|
|
979
|
+
$mol_assert_equal(calls, 0);
|
|
980
|
+
$mol_assert_equal(list[0], 12);
|
|
981
|
+
$mol_assert_equal(list[3], 15);
|
|
982
|
+
$mol_assert_equal(list[4], undefined);
|
|
983
|
+
$mol_assert_equal(calls, 2);
|
|
984
|
+
},
|
|
985
|
+
'prevent modification'() {
|
|
986
|
+
const list = $mol_range2(i => i, () => 5);
|
|
987
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
988
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
989
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
990
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
991
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
992
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
993
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
994
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
995
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
})($ || ($ = {}));
|
|
999
|
+
//mol/range2/range2.test.ts
|
|
1000
|
+
;
|
|
1001
|
+
"use strict";
|
|
1002
|
+
var $;
|
|
726
1003
|
(function ($) {
|
|
727
1004
|
$mol_test({
|
|
728
1005
|
'nulls & undefineds'() {
|
|
@@ -752,6 +1029,8 @@ var $;
|
|
|
752
1029
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
753
1030
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
754
1031
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
1032
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
1033
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
755
1034
|
},
|
|
756
1035
|
'Non POJO are different'() {
|
|
757
1036
|
class Thing extends Object {
|