mol_crypto_lib 0.0.859 → 0.0.860
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
|
@@ -1525,6 +1525,298 @@ var $;
|
|
|
1525
1525
|
;
|
|
1526
1526
|
"use strict";
|
|
1527
1527
|
var $;
|
|
1528
|
+
(function ($) {
|
|
1529
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
1530
|
+
for (;;) {
|
|
1531
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
1532
|
+
if (exists(id))
|
|
1533
|
+
continue;
|
|
1534
|
+
return id;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
$.$mol_guid = $mol_guid;
|
|
1538
|
+
})($ || ($ = {}));
|
|
1539
|
+
//mol/guid/guid.ts
|
|
1540
|
+
;
|
|
1541
|
+
"use strict";
|
|
1542
|
+
var $;
|
|
1543
|
+
(function ($) {
|
|
1544
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
1545
|
+
return new Proxy(new $mol_range2_array(), {
|
|
1546
|
+
get(target, field) {
|
|
1547
|
+
if (typeof field === 'string') {
|
|
1548
|
+
if (field === 'length')
|
|
1549
|
+
return size();
|
|
1550
|
+
const index = Number(field);
|
|
1551
|
+
if (index < 0)
|
|
1552
|
+
return undefined;
|
|
1553
|
+
if (index >= size())
|
|
1554
|
+
return undefined;
|
|
1555
|
+
if (index === Math.trunc(index))
|
|
1556
|
+
return item(index);
|
|
1557
|
+
}
|
|
1558
|
+
return target[field];
|
|
1559
|
+
},
|
|
1560
|
+
set(target, field) {
|
|
1561
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
1562
|
+
},
|
|
1563
|
+
ownKeys(target) {
|
|
1564
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
1565
|
+
},
|
|
1566
|
+
getOwnPropertyDescriptor(target, field) {
|
|
1567
|
+
if (field === "length")
|
|
1568
|
+
return {
|
|
1569
|
+
value: size(),
|
|
1570
|
+
writable: true,
|
|
1571
|
+
enumerable: false,
|
|
1572
|
+
configurable: false,
|
|
1573
|
+
};
|
|
1574
|
+
const index = Number(field);
|
|
1575
|
+
if (index === Math.trunc(index))
|
|
1576
|
+
return {
|
|
1577
|
+
get: () => this.get(target, field, this),
|
|
1578
|
+
enumerable: true,
|
|
1579
|
+
configurable: true,
|
|
1580
|
+
};
|
|
1581
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
$.$mol_range2 = $mol_range2;
|
|
1586
|
+
class $mol_range2_array extends Array {
|
|
1587
|
+
concat(...tail) {
|
|
1588
|
+
if (tail.length === 0)
|
|
1589
|
+
return this;
|
|
1590
|
+
if (tail.length > 1) {
|
|
1591
|
+
let list = this;
|
|
1592
|
+
for (let item of tail)
|
|
1593
|
+
list = list.concat(item);
|
|
1594
|
+
return list;
|
|
1595
|
+
}
|
|
1596
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
1597
|
+
}
|
|
1598
|
+
filter(check, context) {
|
|
1599
|
+
const filtered = new $mol_range2_array();
|
|
1600
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1601
|
+
const item = this[index];
|
|
1602
|
+
if (check.call(context, item, index, this))
|
|
1603
|
+
filtered.push(item);
|
|
1604
|
+
}
|
|
1605
|
+
return filtered;
|
|
1606
|
+
}
|
|
1607
|
+
forEach(proceed, context) {
|
|
1608
|
+
for (let [key, value] of this.entries())
|
|
1609
|
+
proceed.call(context, value, key, this);
|
|
1610
|
+
}
|
|
1611
|
+
map(proceed, context) {
|
|
1612
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
1613
|
+
}
|
|
1614
|
+
reduce(merge, result) {
|
|
1615
|
+
let index = 0;
|
|
1616
|
+
if (arguments.length === 1) {
|
|
1617
|
+
result = this[index++];
|
|
1618
|
+
}
|
|
1619
|
+
for (; index < this.length; ++index) {
|
|
1620
|
+
result = merge(result, this[index], index, this);
|
|
1621
|
+
}
|
|
1622
|
+
return result;
|
|
1623
|
+
}
|
|
1624
|
+
toReversed() {
|
|
1625
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
1626
|
+
}
|
|
1627
|
+
slice(from = 0, to = this.length) {
|
|
1628
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
1629
|
+
}
|
|
1630
|
+
some(check, context) {
|
|
1631
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1632
|
+
if (check.call(context, this[index], index, this))
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
every(check, context) {
|
|
1638
|
+
for (let index = 0; index < this.length; ++index) {
|
|
1639
|
+
if (!check.call(context, this[index], index, this))
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
return true;
|
|
1643
|
+
}
|
|
1644
|
+
reverse() {
|
|
1645
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
1646
|
+
}
|
|
1647
|
+
sort() {
|
|
1648
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
1649
|
+
}
|
|
1650
|
+
[Symbol.toPrimitive]() {
|
|
1651
|
+
return $mol_guid();
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
1655
|
+
})($ || ($ = {}));
|
|
1656
|
+
//mol/range2/range2.ts
|
|
1657
|
+
;
|
|
1658
|
+
"use strict";
|
|
1659
|
+
var $;
|
|
1660
|
+
(function ($) {
|
|
1661
|
+
$mol_test({
|
|
1662
|
+
'lazy calls'() {
|
|
1663
|
+
let calls = 0;
|
|
1664
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
1665
|
+
$mol_assert_ok(list instanceof Array);
|
|
1666
|
+
$mol_assert_equal(list.length, 10);
|
|
1667
|
+
$mol_assert_equal(list[-1], undefined);
|
|
1668
|
+
$mol_assert_equal(list[0], 0);
|
|
1669
|
+
$mol_assert_equal(list[9], 9);
|
|
1670
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
1671
|
+
$mol_assert_equal(list[10], undefined);
|
|
1672
|
+
$mol_assert_equal(calls, 2);
|
|
1673
|
+
},
|
|
1674
|
+
'infinity list'() {
|
|
1675
|
+
let calls = 0;
|
|
1676
|
+
const list = $mol_range2(index => (++calls, index));
|
|
1677
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
1678
|
+
$mol_assert_equal(list[0], 0);
|
|
1679
|
+
$mol_assert_equal(list[4], 4);
|
|
1680
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
1681
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
1682
|
+
$mol_assert_equal(calls, 3);
|
|
1683
|
+
},
|
|
1684
|
+
'stringify'() {
|
|
1685
|
+
const list = $mol_range2(i => i, () => 5);
|
|
1686
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
1687
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
1688
|
+
},
|
|
1689
|
+
'for-of'() {
|
|
1690
|
+
let log = '';
|
|
1691
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
1692
|
+
log += i;
|
|
1693
|
+
}
|
|
1694
|
+
$mol_assert_equal(log, '12345');
|
|
1695
|
+
},
|
|
1696
|
+
'for-in'() {
|
|
1697
|
+
let log = '';
|
|
1698
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
1699
|
+
log += i;
|
|
1700
|
+
}
|
|
1701
|
+
$mol_assert_equal(log, '01234');
|
|
1702
|
+
},
|
|
1703
|
+
'forEach'() {
|
|
1704
|
+
let log = '';
|
|
1705
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
1706
|
+
$mol_assert_equal(log, '01234');
|
|
1707
|
+
},
|
|
1708
|
+
'lazy concat'() {
|
|
1709
|
+
let calls1 = 0;
|
|
1710
|
+
let calls2 = 0;
|
|
1711
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
1712
|
+
$mol_assert_ok(list instanceof Array);
|
|
1713
|
+
$mol_assert_equal(list.length, 15);
|
|
1714
|
+
$mol_assert_equal(list[0], 0);
|
|
1715
|
+
$mol_assert_equal(list[4], 4);
|
|
1716
|
+
$mol_assert_equal(list[5], 0);
|
|
1717
|
+
$mol_assert_equal(list[9], 4);
|
|
1718
|
+
$mol_assert_equal(list[10], 0);
|
|
1719
|
+
$mol_assert_equal(list[14], 4);
|
|
1720
|
+
$mol_assert_equal(list[15], undefined);
|
|
1721
|
+
$mol_assert_equal(calls1, 2);
|
|
1722
|
+
$mol_assert_equal(calls2, 2);
|
|
1723
|
+
},
|
|
1724
|
+
'filter'() {
|
|
1725
|
+
let calls = 0;
|
|
1726
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
1727
|
+
$mol_assert_ok(list instanceof Array);
|
|
1728
|
+
$mol_assert_equal(list.length, 3);
|
|
1729
|
+
$mol_assert_equal(list[0], 1);
|
|
1730
|
+
$mol_assert_equal(list[2], 5);
|
|
1731
|
+
$mol_assert_equal(list[3], undefined);
|
|
1732
|
+
$mol_assert_equal(calls, 10);
|
|
1733
|
+
},
|
|
1734
|
+
'reverse'() {
|
|
1735
|
+
let calls = 0;
|
|
1736
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
1737
|
+
$mol_assert_ok(list instanceof Array);
|
|
1738
|
+
$mol_assert_equal(list.length, 3);
|
|
1739
|
+
$mol_assert_equal(list[0], 9);
|
|
1740
|
+
$mol_assert_equal(list[2], 7);
|
|
1741
|
+
$mol_assert_equal(list[3], undefined);
|
|
1742
|
+
$mol_assert_equal(calls, 2);
|
|
1743
|
+
},
|
|
1744
|
+
'reduce'() {
|
|
1745
|
+
let calls = 0;
|
|
1746
|
+
const list = $mol_range2().slice(1, 6);
|
|
1747
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
1748
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
1749
|
+
},
|
|
1750
|
+
'lazy map'() {
|
|
1751
|
+
let calls1 = 0;
|
|
1752
|
+
let calls2 = 0;
|
|
1753
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
1754
|
+
const target = source.map((item, index, self) => {
|
|
1755
|
+
++calls2;
|
|
1756
|
+
$mol_assert_equal(source, self);
|
|
1757
|
+
return index + 10;
|
|
1758
|
+
}, () => 5);
|
|
1759
|
+
$mol_assert_ok(target instanceof Array);
|
|
1760
|
+
$mol_assert_equal(target.length, 5);
|
|
1761
|
+
$mol_assert_equal(target[0], 10);
|
|
1762
|
+
$mol_assert_equal(target[4], 14);
|
|
1763
|
+
$mol_assert_equal(target[5], undefined);
|
|
1764
|
+
$mol_assert_equal(calls1, 2);
|
|
1765
|
+
$mol_assert_equal(calls2, 2);
|
|
1766
|
+
},
|
|
1767
|
+
'lazy slice'() {
|
|
1768
|
+
let calls = 0;
|
|
1769
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
1770
|
+
$mol_assert_ok(list instanceof Array);
|
|
1771
|
+
$mol_assert_equal(list.length, 4);
|
|
1772
|
+
$mol_assert_equal(list[0], 3);
|
|
1773
|
+
$mol_assert_equal(list[3], 6);
|
|
1774
|
+
$mol_assert_equal(list[4], undefined);
|
|
1775
|
+
$mol_assert_equal(calls, 2);
|
|
1776
|
+
},
|
|
1777
|
+
'lazy some'() {
|
|
1778
|
+
let calls = 0;
|
|
1779
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
1780
|
+
$mol_assert_equal(calls, 3);
|
|
1781
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
1782
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
1783
|
+
},
|
|
1784
|
+
'lazy every'() {
|
|
1785
|
+
let calls = 0;
|
|
1786
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
1787
|
+
$mol_assert_equal(calls, 3);
|
|
1788
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
1789
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
1790
|
+
},
|
|
1791
|
+
'lazyfy'() {
|
|
1792
|
+
let calls = 0;
|
|
1793
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
1794
|
+
$mol_assert_ok(list instanceof Array);
|
|
1795
|
+
$mol_assert_equal(list.length, 4);
|
|
1796
|
+
$mol_assert_equal(calls, 0);
|
|
1797
|
+
$mol_assert_equal(list[0], 12);
|
|
1798
|
+
$mol_assert_equal(list[3], 15);
|
|
1799
|
+
$mol_assert_equal(list[4], undefined);
|
|
1800
|
+
$mol_assert_equal(calls, 2);
|
|
1801
|
+
},
|
|
1802
|
+
'prevent modification'() {
|
|
1803
|
+
const list = $mol_range2(i => i, () => 5);
|
|
1804
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
1805
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
1806
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
1807
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
1808
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
1809
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
1810
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
1811
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
1812
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
})($ || ($ = {}));
|
|
1816
|
+
//mol/range2/range2.test.ts
|
|
1817
|
+
;
|
|
1818
|
+
"use strict";
|
|
1819
|
+
var $;
|
|
1528
1820
|
(function ($) {
|
|
1529
1821
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1530
1822
|
function $mol_compare_deep(left, right) {
|
|
@@ -1570,6 +1862,8 @@ var $;
|
|
|
1570
1862
|
result = compare_pojo(left, right);
|
|
1571
1863
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
1572
1864
|
result = compare_pojo(left, right);
|
|
1865
|
+
else if (Symbol.toPrimitive in left)
|
|
1866
|
+
result = compare_primitive(left, right);
|
|
1573
1867
|
else if (Array.isArray(left))
|
|
1574
1868
|
result = compare_array(left, right);
|
|
1575
1869
|
else if (left instanceof Set)
|
|
@@ -1580,8 +1874,6 @@ var $;
|
|
|
1580
1874
|
result = compare_buffer(left, right);
|
|
1581
1875
|
else if (Symbol.iterator in left)
|
|
1582
1876
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
1583
|
-
else if (Symbol.toPrimitive in left)
|
|
1584
|
-
result = compare_primitive(left, right);
|
|
1585
1877
|
else
|
|
1586
1878
|
result = false;
|
|
1587
1879
|
}
|
|
@@ -1691,6 +1983,8 @@ var $;
|
|
|
1691
1983
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
1692
1984
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
1693
1985
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
1986
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
1987
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
1694
1988
|
},
|
|
1695
1989
|
'Non POJO are different'() {
|
|
1696
1990
|
class Thing extends Object {
|