mol_jsx_lib 0.0.745 → 0.0.747
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 +41 -33
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +41 -33
- package/web.test.js.map +1 -1
package/package.json
CHANGED
package/web.test.js
CHANGED
|
@@ -717,7 +717,12 @@ var $;
|
|
|
717
717
|
var $;
|
|
718
718
|
(function ($) {
|
|
719
719
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
720
|
-
|
|
720
|
+
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
721
|
+
if (typeof item !== 'function') {
|
|
722
|
+
item = index => source[index];
|
|
723
|
+
size = () => source.length;
|
|
724
|
+
}
|
|
725
|
+
return new Proxy(source, {
|
|
721
726
|
get(target, field) {
|
|
722
727
|
if (typeof field === 'string') {
|
|
723
728
|
if (field === 'length')
|
|
@@ -730,7 +735,7 @@ var $;
|
|
|
730
735
|
if (index === Math.trunc(index))
|
|
731
736
|
return item(index);
|
|
732
737
|
}
|
|
733
|
-
return
|
|
738
|
+
return $mol_range2_array.prototype[field];
|
|
734
739
|
},
|
|
735
740
|
set(target, field) {
|
|
736
741
|
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
@@ -771,13 +776,16 @@ var $;
|
|
|
771
776
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
772
777
|
}
|
|
773
778
|
filter(check, context) {
|
|
774
|
-
const filtered =
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
779
|
+
const filtered = [];
|
|
780
|
+
let cursor = -1;
|
|
781
|
+
return $mol_range2(index => {
|
|
782
|
+
while (cursor < this.length && index >= filtered.length - 1) {
|
|
783
|
+
const val = this[++cursor];
|
|
784
|
+
if (check(val, cursor, this))
|
|
785
|
+
filtered.push(val);
|
|
786
|
+
}
|
|
787
|
+
return filtered[index];
|
|
788
|
+
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
781
789
|
}
|
|
782
790
|
forEach(proceed, context) {
|
|
783
791
|
for (let [key, value] of this.entries())
|
|
@@ -837,7 +845,7 @@ var $;
|
|
|
837
845
|
'lazy calls'() {
|
|
838
846
|
let calls = 0;
|
|
839
847
|
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
840
|
-
$
|
|
848
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
841
849
|
$mol_assert_equal(list.length, 10);
|
|
842
850
|
$mol_assert_equal(list[-1], undefined);
|
|
843
851
|
$mol_assert_equal(list[0], 0);
|
|
@@ -880,11 +888,17 @@ var $;
|
|
|
880
888
|
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
881
889
|
$mol_assert_equal(log, '01234');
|
|
882
890
|
},
|
|
891
|
+
'reduce'() {
|
|
892
|
+
let calls = 0;
|
|
893
|
+
const list = $mol_range2().slice(1, 6);
|
|
894
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
895
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
896
|
+
},
|
|
883
897
|
'lazy concat'() {
|
|
884
898
|
let calls1 = 0;
|
|
885
899
|
let calls2 = 0;
|
|
886
900
|
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
887
|
-
$
|
|
901
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
888
902
|
$mol_assert_equal(list.length, 15);
|
|
889
903
|
$mol_assert_equal(list[0], 0);
|
|
890
904
|
$mol_assert_equal(list[4], 4);
|
|
@@ -896,32 +910,26 @@ var $;
|
|
|
896
910
|
$mol_assert_equal(calls1, 2);
|
|
897
911
|
$mol_assert_equal(calls2, 2);
|
|
898
912
|
},
|
|
899
|
-
'filter'() {
|
|
913
|
+
'lazy filter'() {
|
|
900
914
|
let calls = 0;
|
|
901
|
-
const list = $mol_range2(index => (++calls, index), () =>
|
|
902
|
-
$
|
|
915
|
+
const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
|
|
916
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
903
917
|
$mol_assert_equal(list.length, 3);
|
|
904
918
|
$mol_assert_equal(list[0], 1);
|
|
905
919
|
$mol_assert_equal(list[2], 5);
|
|
906
920
|
$mol_assert_equal(list[3], undefined);
|
|
907
|
-
$mol_assert_equal(calls,
|
|
921
|
+
$mol_assert_equal(calls, 8);
|
|
908
922
|
},
|
|
909
|
-
'reverse'() {
|
|
923
|
+
'lazy reverse'() {
|
|
910
924
|
let calls = 0;
|
|
911
925
|
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
912
|
-
$
|
|
926
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
913
927
|
$mol_assert_equal(list.length, 3);
|
|
914
928
|
$mol_assert_equal(list[0], 9);
|
|
915
929
|
$mol_assert_equal(list[2], 7);
|
|
916
930
|
$mol_assert_equal(list[3], undefined);
|
|
917
931
|
$mol_assert_equal(calls, 2);
|
|
918
932
|
},
|
|
919
|
-
'reduce'() {
|
|
920
|
-
let calls = 0;
|
|
921
|
-
const list = $mol_range2().slice(1, 6);
|
|
922
|
-
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
923
|
-
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
924
|
-
},
|
|
925
933
|
'lazy map'() {
|
|
926
934
|
let calls1 = 0;
|
|
927
935
|
let calls2 = 0;
|
|
@@ -931,7 +939,7 @@ var $;
|
|
|
931
939
|
$mol_assert_equal(source, self);
|
|
932
940
|
return index + 10;
|
|
933
941
|
}, () => 5);
|
|
934
|
-
$
|
|
942
|
+
$mol_assert_equal(true, target instanceof Array);
|
|
935
943
|
$mol_assert_equal(target.length, 5);
|
|
936
944
|
$mol_assert_equal(target[0], 10);
|
|
937
945
|
$mol_assert_equal(target[4], 14);
|
|
@@ -942,7 +950,7 @@ var $;
|
|
|
942
950
|
'lazy slice'() {
|
|
943
951
|
let calls = 0;
|
|
944
952
|
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
945
|
-
$
|
|
953
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
946
954
|
$mol_assert_equal(list.length, 4);
|
|
947
955
|
$mol_assert_equal(list[0], 3);
|
|
948
956
|
$mol_assert_equal(list[3], 6);
|
|
@@ -951,22 +959,22 @@ var $;
|
|
|
951
959
|
},
|
|
952
960
|
'lazy some'() {
|
|
953
961
|
let calls = 0;
|
|
954
|
-
$
|
|
962
|
+
$mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
955
963
|
$mol_assert_equal(calls, 3);
|
|
956
|
-
$
|
|
957
|
-
$
|
|
964
|
+
$mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
|
|
965
|
+
$mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
|
|
958
966
|
},
|
|
959
967
|
'lazy every'() {
|
|
960
968
|
let calls = 0;
|
|
961
|
-
$
|
|
969
|
+
$mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
962
970
|
$mol_assert_equal(calls, 3);
|
|
963
|
-
$
|
|
964
|
-
$
|
|
971
|
+
$mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
|
|
972
|
+
$mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
|
|
965
973
|
},
|
|
966
974
|
'lazyfy'() {
|
|
967
975
|
let calls = 0;
|
|
968
|
-
const list =
|
|
969
|
-
$
|
|
976
|
+
const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
977
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
970
978
|
$mol_assert_equal(list.length, 4);
|
|
971
979
|
$mol_assert_equal(calls, 0);
|
|
972
980
|
$mol_assert_equal(list[0], 12);
|