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