mol_tree2 1.0.443 → 1.0.445
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
|
@@ -1925,6 +1925,298 @@ var $;
|
|
|
1925
1925
|
;
|
|
1926
1926
|
"use strict";
|
|
1927
1927
|
var $;
|
|
1928
|
+
(function ($) {
|
|
1929
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
1930
|
+
for (;;) {
|
|
1931
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
1932
|
+
if (exists(id))
|
|
1933
|
+
continue;
|
|
1934
|
+
return id;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
$.$mol_guid = $mol_guid;
|
|
1938
|
+
})($ || ($ = {}));
|
|
1939
|
+
//mol/guid/guid.ts
|
|
1940
|
+
;
|
|
1941
|
+
"use strict";
|
|
1942
|
+
var $;
|
|
1943
|
+
(function ($) {
|
|
1944
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
1945
|
+
return new Proxy(new $mol_range2_array(), {
|
|
1946
|
+
get(target, field) {
|
|
1947
|
+
if (typeof field === 'string') {
|
|
1948
|
+
if (field === 'length')
|
|
1949
|
+
return size();
|
|
1950
|
+
const index = Number(field);
|
|
1951
|
+
if (index < 0)
|
|
1952
|
+
return undefined;
|
|
1953
|
+
if (index >= size())
|
|
1954
|
+
return undefined;
|
|
1955
|
+
if (index === Math.trunc(index))
|
|
1956
|
+
return item(index);
|
|
1957
|
+
}
|
|
1958
|
+
return target[field];
|
|
1959
|
+
},
|
|
1960
|
+
set(target, field) {
|
|
1961
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
1962
|
+
},
|
|
1963
|
+
ownKeys(target) {
|
|
1964
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
1965
|
+
},
|
|
1966
|
+
getOwnPropertyDescriptor(target, field) {
|
|
1967
|
+
if (field === "length")
|
|
1968
|
+
return {
|
|
1969
|
+
value: size(),
|
|
1970
|
+
writable: true,
|
|
1971
|
+
enumerable: false,
|
|
1972
|
+
configurable: false,
|
|
1973
|
+
};
|
|
1974
|
+
const index = Number(field);
|
|
1975
|
+
if (index === Math.trunc(index))
|
|
1976
|
+
return {
|
|
1977
|
+
get: () => this.get(target, field, this),
|
|
1978
|
+
enumerable: true,
|
|
1979
|
+
configurable: true,
|
|
1980
|
+
};
|
|
1981
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
$.$mol_range2 = $mol_range2;
|
|
1986
|
+
class $mol_range2_array extends Array {
|
|
1987
|
+
concat(...tail) {
|
|
1988
|
+
if (tail.length === 0)
|
|
1989
|
+
return this;
|
|
1990
|
+
if (tail.length > 1) {
|
|
1991
|
+
let list = this;
|
|
1992
|
+
for (let item of tail)
|
|
1993
|
+
list = list.concat(item);
|
|
1994
|
+
return list;
|
|
1995
|
+
}
|
|
1996
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
1997
|
+
}
|
|
1998
|
+
filter(check, context) {
|
|
1999
|
+
const filtered = new $mol_range2_array();
|
|
2000
|
+
for (let index = 0; index < this.length; ++index) {
|
|
2001
|
+
const item = this[index];
|
|
2002
|
+
if (check.call(context, item, index, this))
|
|
2003
|
+
filtered.push(item);
|
|
2004
|
+
}
|
|
2005
|
+
return filtered;
|
|
2006
|
+
}
|
|
2007
|
+
forEach(proceed, context) {
|
|
2008
|
+
for (let [key, value] of this.entries())
|
|
2009
|
+
proceed.call(context, value, key, this);
|
|
2010
|
+
}
|
|
2011
|
+
map(proceed, context) {
|
|
2012
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
2013
|
+
}
|
|
2014
|
+
reduce(merge, result) {
|
|
2015
|
+
let index = 0;
|
|
2016
|
+
if (arguments.length === 1) {
|
|
2017
|
+
result = this[index++];
|
|
2018
|
+
}
|
|
2019
|
+
for (; index < this.length; ++index) {
|
|
2020
|
+
result = merge(result, this[index], index, this);
|
|
2021
|
+
}
|
|
2022
|
+
return result;
|
|
2023
|
+
}
|
|
2024
|
+
toReversed() {
|
|
2025
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
2026
|
+
}
|
|
2027
|
+
slice(from = 0, to = this.length) {
|
|
2028
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
2029
|
+
}
|
|
2030
|
+
some(check, context) {
|
|
2031
|
+
for (let index = 0; index < this.length; ++index) {
|
|
2032
|
+
if (check.call(context, this[index], index, this))
|
|
2033
|
+
return true;
|
|
2034
|
+
}
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
every(check, context) {
|
|
2038
|
+
for (let index = 0; index < this.length; ++index) {
|
|
2039
|
+
if (!check.call(context, this[index], index, this))
|
|
2040
|
+
return false;
|
|
2041
|
+
}
|
|
2042
|
+
return true;
|
|
2043
|
+
}
|
|
2044
|
+
reverse() {
|
|
2045
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
2046
|
+
}
|
|
2047
|
+
sort() {
|
|
2048
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
2049
|
+
}
|
|
2050
|
+
[Symbol.toPrimitive]() {
|
|
2051
|
+
return $mol_guid();
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
2055
|
+
})($ || ($ = {}));
|
|
2056
|
+
//mol/range2/range2.ts
|
|
2057
|
+
;
|
|
2058
|
+
"use strict";
|
|
2059
|
+
var $;
|
|
2060
|
+
(function ($) {
|
|
2061
|
+
$mol_test({
|
|
2062
|
+
'lazy calls'() {
|
|
2063
|
+
let calls = 0;
|
|
2064
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
2065
|
+
$mol_assert_ok(list instanceof Array);
|
|
2066
|
+
$mol_assert_equal(list.length, 10);
|
|
2067
|
+
$mol_assert_equal(list[-1], undefined);
|
|
2068
|
+
$mol_assert_equal(list[0], 0);
|
|
2069
|
+
$mol_assert_equal(list[9], 9);
|
|
2070
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
2071
|
+
$mol_assert_equal(list[10], undefined);
|
|
2072
|
+
$mol_assert_equal(calls, 2);
|
|
2073
|
+
},
|
|
2074
|
+
'infinity list'() {
|
|
2075
|
+
let calls = 0;
|
|
2076
|
+
const list = $mol_range2(index => (++calls, index));
|
|
2077
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
2078
|
+
$mol_assert_equal(list[0], 0);
|
|
2079
|
+
$mol_assert_equal(list[4], 4);
|
|
2080
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
2081
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
2082
|
+
$mol_assert_equal(calls, 3);
|
|
2083
|
+
},
|
|
2084
|
+
'stringify'() {
|
|
2085
|
+
const list = $mol_range2(i => i, () => 5);
|
|
2086
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
2087
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
2088
|
+
},
|
|
2089
|
+
'for-of'() {
|
|
2090
|
+
let log = '';
|
|
2091
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
2092
|
+
log += i;
|
|
2093
|
+
}
|
|
2094
|
+
$mol_assert_equal(log, '12345');
|
|
2095
|
+
},
|
|
2096
|
+
'for-in'() {
|
|
2097
|
+
let log = '';
|
|
2098
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
2099
|
+
log += i;
|
|
2100
|
+
}
|
|
2101
|
+
$mol_assert_equal(log, '01234');
|
|
2102
|
+
},
|
|
2103
|
+
'forEach'() {
|
|
2104
|
+
let log = '';
|
|
2105
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
2106
|
+
$mol_assert_equal(log, '01234');
|
|
2107
|
+
},
|
|
2108
|
+
'lazy concat'() {
|
|
2109
|
+
let calls1 = 0;
|
|
2110
|
+
let calls2 = 0;
|
|
2111
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
2112
|
+
$mol_assert_ok(list instanceof Array);
|
|
2113
|
+
$mol_assert_equal(list.length, 15);
|
|
2114
|
+
$mol_assert_equal(list[0], 0);
|
|
2115
|
+
$mol_assert_equal(list[4], 4);
|
|
2116
|
+
$mol_assert_equal(list[5], 0);
|
|
2117
|
+
$mol_assert_equal(list[9], 4);
|
|
2118
|
+
$mol_assert_equal(list[10], 0);
|
|
2119
|
+
$mol_assert_equal(list[14], 4);
|
|
2120
|
+
$mol_assert_equal(list[15], undefined);
|
|
2121
|
+
$mol_assert_equal(calls1, 2);
|
|
2122
|
+
$mol_assert_equal(calls2, 2);
|
|
2123
|
+
},
|
|
2124
|
+
'filter'() {
|
|
2125
|
+
let calls = 0;
|
|
2126
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
2127
|
+
$mol_assert_ok(list instanceof Array);
|
|
2128
|
+
$mol_assert_equal(list.length, 3);
|
|
2129
|
+
$mol_assert_equal(list[0], 1);
|
|
2130
|
+
$mol_assert_equal(list[2], 5);
|
|
2131
|
+
$mol_assert_equal(list[3], undefined);
|
|
2132
|
+
$mol_assert_equal(calls, 10);
|
|
2133
|
+
},
|
|
2134
|
+
'reverse'() {
|
|
2135
|
+
let calls = 0;
|
|
2136
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
2137
|
+
$mol_assert_ok(list instanceof Array);
|
|
2138
|
+
$mol_assert_equal(list.length, 3);
|
|
2139
|
+
$mol_assert_equal(list[0], 9);
|
|
2140
|
+
$mol_assert_equal(list[2], 7);
|
|
2141
|
+
$mol_assert_equal(list[3], undefined);
|
|
2142
|
+
$mol_assert_equal(calls, 2);
|
|
2143
|
+
},
|
|
2144
|
+
'reduce'() {
|
|
2145
|
+
let calls = 0;
|
|
2146
|
+
const list = $mol_range2().slice(1, 6);
|
|
2147
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
2148
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
2149
|
+
},
|
|
2150
|
+
'lazy map'() {
|
|
2151
|
+
let calls1 = 0;
|
|
2152
|
+
let calls2 = 0;
|
|
2153
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
2154
|
+
const target = source.map((item, index, self) => {
|
|
2155
|
+
++calls2;
|
|
2156
|
+
$mol_assert_equal(source, self);
|
|
2157
|
+
return index + 10;
|
|
2158
|
+
}, () => 5);
|
|
2159
|
+
$mol_assert_ok(target instanceof Array);
|
|
2160
|
+
$mol_assert_equal(target.length, 5);
|
|
2161
|
+
$mol_assert_equal(target[0], 10);
|
|
2162
|
+
$mol_assert_equal(target[4], 14);
|
|
2163
|
+
$mol_assert_equal(target[5], undefined);
|
|
2164
|
+
$mol_assert_equal(calls1, 2);
|
|
2165
|
+
$mol_assert_equal(calls2, 2);
|
|
2166
|
+
},
|
|
2167
|
+
'lazy slice'() {
|
|
2168
|
+
let calls = 0;
|
|
2169
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
2170
|
+
$mol_assert_ok(list instanceof Array);
|
|
2171
|
+
$mol_assert_equal(list.length, 4);
|
|
2172
|
+
$mol_assert_equal(list[0], 3);
|
|
2173
|
+
$mol_assert_equal(list[3], 6);
|
|
2174
|
+
$mol_assert_equal(list[4], undefined);
|
|
2175
|
+
$mol_assert_equal(calls, 2);
|
|
2176
|
+
},
|
|
2177
|
+
'lazy some'() {
|
|
2178
|
+
let calls = 0;
|
|
2179
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
2180
|
+
$mol_assert_equal(calls, 3);
|
|
2181
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
2182
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
2183
|
+
},
|
|
2184
|
+
'lazy every'() {
|
|
2185
|
+
let calls = 0;
|
|
2186
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
2187
|
+
$mol_assert_equal(calls, 3);
|
|
2188
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
2189
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
2190
|
+
},
|
|
2191
|
+
'lazyfy'() {
|
|
2192
|
+
let calls = 0;
|
|
2193
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
2194
|
+
$mol_assert_ok(list instanceof Array);
|
|
2195
|
+
$mol_assert_equal(list.length, 4);
|
|
2196
|
+
$mol_assert_equal(calls, 0);
|
|
2197
|
+
$mol_assert_equal(list[0], 12);
|
|
2198
|
+
$mol_assert_equal(list[3], 15);
|
|
2199
|
+
$mol_assert_equal(list[4], undefined);
|
|
2200
|
+
$mol_assert_equal(calls, 2);
|
|
2201
|
+
},
|
|
2202
|
+
'prevent modification'() {
|
|
2203
|
+
const list = $mol_range2(i => i, () => 5);
|
|
2204
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
2205
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
2206
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
2207
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
2208
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
2209
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
2210
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
2211
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
2212
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
})($ || ($ = {}));
|
|
2216
|
+
//mol/range2/range2.test.ts
|
|
2217
|
+
;
|
|
2218
|
+
"use strict";
|
|
2219
|
+
var $;
|
|
1928
2220
|
(function ($) {
|
|
1929
2221
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1930
2222
|
function $mol_compare_deep(left, right) {
|
|
@@ -1970,6 +2262,8 @@ var $;
|
|
|
1970
2262
|
result = compare_pojo(left, right);
|
|
1971
2263
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
1972
2264
|
result = compare_pojo(left, right);
|
|
2265
|
+
else if (Symbol.toPrimitive in left)
|
|
2266
|
+
result = compare_primitive(left, right);
|
|
1973
2267
|
else if (Array.isArray(left))
|
|
1974
2268
|
result = compare_array(left, right);
|
|
1975
2269
|
else if (left instanceof Set)
|
|
@@ -1980,8 +2274,6 @@ var $;
|
|
|
1980
2274
|
result = compare_buffer(left, right);
|
|
1981
2275
|
else if (Symbol.iterator in left)
|
|
1982
2276
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
1983
|
-
else if (Symbol.toPrimitive in left)
|
|
1984
|
-
result = compare_primitive(left, right);
|
|
1985
2277
|
else
|
|
1986
2278
|
result = false;
|
|
1987
2279
|
}
|
|
@@ -2091,6 +2383,8 @@ var $;
|
|
|
2091
2383
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
2092
2384
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
2093
2385
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
2386
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
2387
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
2094
2388
|
},
|
|
2095
2389
|
'Non POJO are different'() {
|
|
2096
2390
|
class Thing extends Object {
|