mol_regexp 0.0.897 → 0.0.899
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
|
@@ -941,6 +941,298 @@ var $;
|
|
|
941
941
|
;
|
|
942
942
|
"use strict";
|
|
943
943
|
var $;
|
|
944
|
+
(function ($) {
|
|
945
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
946
|
+
for (;;) {
|
|
947
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
948
|
+
if (exists(id))
|
|
949
|
+
continue;
|
|
950
|
+
return id;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
$.$mol_guid = $mol_guid;
|
|
954
|
+
})($ || ($ = {}));
|
|
955
|
+
//mol/guid/guid.ts
|
|
956
|
+
;
|
|
957
|
+
"use strict";
|
|
958
|
+
var $;
|
|
959
|
+
(function ($) {
|
|
960
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
961
|
+
return new Proxy(new $mol_range2_array(), {
|
|
962
|
+
get(target, field) {
|
|
963
|
+
if (typeof field === 'string') {
|
|
964
|
+
if (field === 'length')
|
|
965
|
+
return size();
|
|
966
|
+
const index = Number(field);
|
|
967
|
+
if (index < 0)
|
|
968
|
+
return undefined;
|
|
969
|
+
if (index >= size())
|
|
970
|
+
return undefined;
|
|
971
|
+
if (index === Math.trunc(index))
|
|
972
|
+
return item(index);
|
|
973
|
+
}
|
|
974
|
+
return target[field];
|
|
975
|
+
},
|
|
976
|
+
set(target, field) {
|
|
977
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
978
|
+
},
|
|
979
|
+
ownKeys(target) {
|
|
980
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
981
|
+
},
|
|
982
|
+
getOwnPropertyDescriptor(target, field) {
|
|
983
|
+
if (field === "length")
|
|
984
|
+
return {
|
|
985
|
+
value: size(),
|
|
986
|
+
writable: true,
|
|
987
|
+
enumerable: false,
|
|
988
|
+
configurable: false,
|
|
989
|
+
};
|
|
990
|
+
const index = Number(field);
|
|
991
|
+
if (index === Math.trunc(index))
|
|
992
|
+
return {
|
|
993
|
+
get: () => this.get(target, field, this),
|
|
994
|
+
enumerable: true,
|
|
995
|
+
configurable: true,
|
|
996
|
+
};
|
|
997
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
$.$mol_range2 = $mol_range2;
|
|
1002
|
+
class $mol_range2_array extends Array {
|
|
1003
|
+
concat(...tail) {
|
|
1004
|
+
if (tail.length === 0)
|
|
1005
|
+
return this;
|
|
1006
|
+
if (tail.length > 1) {
|
|
1007
|
+
let list = this;
|
|
1008
|
+
for (let item of tail)
|
|
1009
|
+
list = list.concat(item);
|
|
1010
|
+
return list;
|
|
1011
|
+
}
|
|
1012
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
1013
|
+
}
|
|
1014
|
+
filter(check, context) {
|
|
1015
|
+
const filtered = new $mol_range2_array();
|
|
1016
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1017
|
+
const item = this[index];
|
|
1018
|
+
if (check.call(context, item, index, this))
|
|
1019
|
+
filtered.push(item);
|
|
1020
|
+
}
|
|
1021
|
+
return filtered;
|
|
1022
|
+
}
|
|
1023
|
+
forEach(proceed, context) {
|
|
1024
|
+
for (let [key, value] of this.entries())
|
|
1025
|
+
proceed.call(context, value, key, this);
|
|
1026
|
+
}
|
|
1027
|
+
map(proceed, context) {
|
|
1028
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
1029
|
+
}
|
|
1030
|
+
reduce(merge, result) {
|
|
1031
|
+
let index = 0;
|
|
1032
|
+
if (arguments.length === 1) {
|
|
1033
|
+
result = this[index++];
|
|
1034
|
+
}
|
|
1035
|
+
for (; index < this.length; ++index) {
|
|
1036
|
+
result = merge(result, this[index], index, this);
|
|
1037
|
+
}
|
|
1038
|
+
return result;
|
|
1039
|
+
}
|
|
1040
|
+
toReversed() {
|
|
1041
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
1042
|
+
}
|
|
1043
|
+
slice(from = 0, to = this.length) {
|
|
1044
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
1045
|
+
}
|
|
1046
|
+
some(check, context) {
|
|
1047
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1048
|
+
if (check.call(context, this[index], index, this))
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
every(check, context) {
|
|
1054
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1055
|
+
if (!check.call(context, this[index], index, this))
|
|
1056
|
+
return false;
|
|
1057
|
+
}
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
1060
|
+
reverse() {
|
|
1061
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
1062
|
+
}
|
|
1063
|
+
sort() {
|
|
1064
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
1065
|
+
}
|
|
1066
|
+
[Symbol.toPrimitive]() {
|
|
1067
|
+
return $mol_guid();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
1071
|
+
})($ || ($ = {}));
|
|
1072
|
+
//mol/range2/range2.ts
|
|
1073
|
+
;
|
|
1074
|
+
"use strict";
|
|
1075
|
+
var $;
|
|
1076
|
+
(function ($) {
|
|
1077
|
+
$mol_test({
|
|
1078
|
+
'lazy calls'() {
|
|
1079
|
+
let calls = 0;
|
|
1080
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
1081
|
+
$mol_assert_ok(list instanceof Array);
|
|
1082
|
+
$mol_assert_equal(list.length, 10);
|
|
1083
|
+
$mol_assert_equal(list[-1], undefined);
|
|
1084
|
+
$mol_assert_equal(list[0], 0);
|
|
1085
|
+
$mol_assert_equal(list[9], 9);
|
|
1086
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
1087
|
+
$mol_assert_equal(list[10], undefined);
|
|
1088
|
+
$mol_assert_equal(calls, 2);
|
|
1089
|
+
},
|
|
1090
|
+
'infinity list'() {
|
|
1091
|
+
let calls = 0;
|
|
1092
|
+
const list = $mol_range2(index => (++calls, index));
|
|
1093
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
1094
|
+
$mol_assert_equal(list[0], 0);
|
|
1095
|
+
$mol_assert_equal(list[4], 4);
|
|
1096
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
1097
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
1098
|
+
$mol_assert_equal(calls, 3);
|
|
1099
|
+
},
|
|
1100
|
+
'stringify'() {
|
|
1101
|
+
const list = $mol_range2(i => i, () => 5);
|
|
1102
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
1103
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
1104
|
+
},
|
|
1105
|
+
'for-of'() {
|
|
1106
|
+
let log = '';
|
|
1107
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
1108
|
+
log += i;
|
|
1109
|
+
}
|
|
1110
|
+
$mol_assert_equal(log, '12345');
|
|
1111
|
+
},
|
|
1112
|
+
'for-in'() {
|
|
1113
|
+
let log = '';
|
|
1114
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
1115
|
+
log += i;
|
|
1116
|
+
}
|
|
1117
|
+
$mol_assert_equal(log, '01234');
|
|
1118
|
+
},
|
|
1119
|
+
'forEach'() {
|
|
1120
|
+
let log = '';
|
|
1121
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
1122
|
+
$mol_assert_equal(log, '01234');
|
|
1123
|
+
},
|
|
1124
|
+
'lazy concat'() {
|
|
1125
|
+
let calls1 = 0;
|
|
1126
|
+
let calls2 = 0;
|
|
1127
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
1128
|
+
$mol_assert_ok(list instanceof Array);
|
|
1129
|
+
$mol_assert_equal(list.length, 15);
|
|
1130
|
+
$mol_assert_equal(list[0], 0);
|
|
1131
|
+
$mol_assert_equal(list[4], 4);
|
|
1132
|
+
$mol_assert_equal(list[5], 0);
|
|
1133
|
+
$mol_assert_equal(list[9], 4);
|
|
1134
|
+
$mol_assert_equal(list[10], 0);
|
|
1135
|
+
$mol_assert_equal(list[14], 4);
|
|
1136
|
+
$mol_assert_equal(list[15], undefined);
|
|
1137
|
+
$mol_assert_equal(calls1, 2);
|
|
1138
|
+
$mol_assert_equal(calls2, 2);
|
|
1139
|
+
},
|
|
1140
|
+
'filter'() {
|
|
1141
|
+
let calls = 0;
|
|
1142
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
1143
|
+
$mol_assert_ok(list instanceof Array);
|
|
1144
|
+
$mol_assert_equal(list.length, 3);
|
|
1145
|
+
$mol_assert_equal(list[0], 1);
|
|
1146
|
+
$mol_assert_equal(list[2], 5);
|
|
1147
|
+
$mol_assert_equal(list[3], undefined);
|
|
1148
|
+
$mol_assert_equal(calls, 10);
|
|
1149
|
+
},
|
|
1150
|
+
'reverse'() {
|
|
1151
|
+
let calls = 0;
|
|
1152
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
1153
|
+
$mol_assert_ok(list instanceof Array);
|
|
1154
|
+
$mol_assert_equal(list.length, 3);
|
|
1155
|
+
$mol_assert_equal(list[0], 9);
|
|
1156
|
+
$mol_assert_equal(list[2], 7);
|
|
1157
|
+
$mol_assert_equal(list[3], undefined);
|
|
1158
|
+
$mol_assert_equal(calls, 2);
|
|
1159
|
+
},
|
|
1160
|
+
'reduce'() {
|
|
1161
|
+
let calls = 0;
|
|
1162
|
+
const list = $mol_range2().slice(1, 6);
|
|
1163
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
1164
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
1165
|
+
},
|
|
1166
|
+
'lazy map'() {
|
|
1167
|
+
let calls1 = 0;
|
|
1168
|
+
let calls2 = 0;
|
|
1169
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
1170
|
+
const target = source.map((item, index, self) => {
|
|
1171
|
+
++calls2;
|
|
1172
|
+
$mol_assert_equal(source, self);
|
|
1173
|
+
return index + 10;
|
|
1174
|
+
}, () => 5);
|
|
1175
|
+
$mol_assert_ok(target instanceof Array);
|
|
1176
|
+
$mol_assert_equal(target.length, 5);
|
|
1177
|
+
$mol_assert_equal(target[0], 10);
|
|
1178
|
+
$mol_assert_equal(target[4], 14);
|
|
1179
|
+
$mol_assert_equal(target[5], undefined);
|
|
1180
|
+
$mol_assert_equal(calls1, 2);
|
|
1181
|
+
$mol_assert_equal(calls2, 2);
|
|
1182
|
+
},
|
|
1183
|
+
'lazy slice'() {
|
|
1184
|
+
let calls = 0;
|
|
1185
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
1186
|
+
$mol_assert_ok(list instanceof Array);
|
|
1187
|
+
$mol_assert_equal(list.length, 4);
|
|
1188
|
+
$mol_assert_equal(list[0], 3);
|
|
1189
|
+
$mol_assert_equal(list[3], 6);
|
|
1190
|
+
$mol_assert_equal(list[4], undefined);
|
|
1191
|
+
$mol_assert_equal(calls, 2);
|
|
1192
|
+
},
|
|
1193
|
+
'lazy some'() {
|
|
1194
|
+
let calls = 0;
|
|
1195
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
1196
|
+
$mol_assert_equal(calls, 3);
|
|
1197
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
1198
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
1199
|
+
},
|
|
1200
|
+
'lazy every'() {
|
|
1201
|
+
let calls = 0;
|
|
1202
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
1203
|
+
$mol_assert_equal(calls, 3);
|
|
1204
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
1205
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
1206
|
+
},
|
|
1207
|
+
'lazyfy'() {
|
|
1208
|
+
let calls = 0;
|
|
1209
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
1210
|
+
$mol_assert_ok(list instanceof Array);
|
|
1211
|
+
$mol_assert_equal(list.length, 4);
|
|
1212
|
+
$mol_assert_equal(calls, 0);
|
|
1213
|
+
$mol_assert_equal(list[0], 12);
|
|
1214
|
+
$mol_assert_equal(list[3], 15);
|
|
1215
|
+
$mol_assert_equal(list[4], undefined);
|
|
1216
|
+
$mol_assert_equal(calls, 2);
|
|
1217
|
+
},
|
|
1218
|
+
'prevent modification'() {
|
|
1219
|
+
const list = $mol_range2(i => i, () => 5);
|
|
1220
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
1221
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
1222
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
1223
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
1224
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
1225
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
1226
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
1227
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
1228
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
})($ || ($ = {}));
|
|
1232
|
+
//mol/range2/range2.test.ts
|
|
1233
|
+
;
|
|
1234
|
+
"use strict";
|
|
1235
|
+
var $;
|
|
944
1236
|
(function ($) {
|
|
945
1237
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
946
1238
|
function $mol_compare_deep(left, right) {
|
|
@@ -986,6 +1278,8 @@ var $;
|
|
|
986
1278
|
result = compare_pojo(left, right);
|
|
987
1279
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
988
1280
|
result = compare_pojo(left, right);
|
|
1281
|
+
else if (Symbol.toPrimitive in left)
|
|
1282
|
+
result = compare_primitive(left, right);
|
|
989
1283
|
else if (Array.isArray(left))
|
|
990
1284
|
result = compare_array(left, right);
|
|
991
1285
|
else if (left instanceof Set)
|
|
@@ -996,8 +1290,6 @@ var $;
|
|
|
996
1290
|
result = compare_buffer(left, right);
|
|
997
1291
|
else if (Symbol.iterator in left)
|
|
998
1292
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
999
|
-
else if (Symbol.toPrimitive in left)
|
|
1000
|
-
result = compare_primitive(left, right);
|
|
1001
1293
|
else
|
|
1002
1294
|
result = false;
|
|
1003
1295
|
}
|
|
@@ -1107,6 +1399,8 @@ var $;
|
|
|
1107
1399
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
1108
1400
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
1109
1401
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
1402
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
1403
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
1110
1404
|
},
|
|
1111
1405
|
'Non POJO are different'() {
|
|
1112
1406
|
class Thing extends Object {
|