@leofcoin/chain 1.6.0 → 1.6.1
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/exports/browser/chain.js +656 -673
- package/package.json +8 -8
package/exports/browser/chain.js
CHANGED
|
@@ -1432,781 +1432,764 @@ function requireIterator () {
|
|
|
1432
1432
|
return iterator;
|
|
1433
1433
|
}
|
|
1434
1434
|
|
|
1435
|
-
var yallist;
|
|
1436
|
-
var hasRequiredYallist;
|
|
1435
|
+
var yallist = Yallist$1;
|
|
1437
1436
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
hasRequiredYallist = 1;
|
|
1441
|
-
yallist = Yallist;
|
|
1437
|
+
Yallist$1.Node = Node;
|
|
1438
|
+
Yallist$1.create = Yallist$1;
|
|
1442
1439
|
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
if (!(self instanceof Yallist)) {
|
|
1449
|
-
self = new Yallist();
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
self.tail = null;
|
|
1453
|
-
self.head = null;
|
|
1454
|
-
self.length = 0;
|
|
1440
|
+
function Yallist$1 (list) {
|
|
1441
|
+
var self = this;
|
|
1442
|
+
if (!(self instanceof Yallist$1)) {
|
|
1443
|
+
self = new Yallist$1();
|
|
1444
|
+
}
|
|
1455
1445
|
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
});
|
|
1460
|
-
} else if (arguments.length > 0) {
|
|
1461
|
-
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1462
|
-
self.push(arguments[i]);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1446
|
+
self.tail = null;
|
|
1447
|
+
self.head = null;
|
|
1448
|
+
self.length = 0;
|
|
1465
1449
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1450
|
+
if (list && typeof list.forEach === 'function') {
|
|
1451
|
+
list.forEach(function (item) {
|
|
1452
|
+
self.push(item);
|
|
1453
|
+
});
|
|
1454
|
+
} else if (arguments.length > 0) {
|
|
1455
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1456
|
+
self.push(arguments[i]);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1468
1459
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
throw new Error('removing node which does not belong to this list')
|
|
1472
|
-
}
|
|
1460
|
+
return self
|
|
1461
|
+
}
|
|
1473
1462
|
|
|
1474
|
-
|
|
1475
|
-
|
|
1463
|
+
Yallist$1.prototype.removeNode = function (node) {
|
|
1464
|
+
if (node.list !== this) {
|
|
1465
|
+
throw new Error('removing node which does not belong to this list')
|
|
1466
|
+
}
|
|
1476
1467
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1468
|
+
var next = node.next;
|
|
1469
|
+
var prev = node.prev;
|
|
1480
1470
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1471
|
+
if (next) {
|
|
1472
|
+
next.prev = prev;
|
|
1473
|
+
}
|
|
1484
1474
|
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
if (node === this.tail) {
|
|
1489
|
-
this.tail = prev;
|
|
1490
|
-
}
|
|
1475
|
+
if (prev) {
|
|
1476
|
+
prev.next = next;
|
|
1477
|
+
}
|
|
1491
1478
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1479
|
+
if (node === this.head) {
|
|
1480
|
+
this.head = next;
|
|
1481
|
+
}
|
|
1482
|
+
if (node === this.tail) {
|
|
1483
|
+
this.tail = prev;
|
|
1484
|
+
}
|
|
1496
1485
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1486
|
+
node.list.length--;
|
|
1487
|
+
node.next = null;
|
|
1488
|
+
node.prev = null;
|
|
1489
|
+
node.list = null;
|
|
1499
1490
|
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
return
|
|
1503
|
-
}
|
|
1491
|
+
return next
|
|
1492
|
+
};
|
|
1504
1493
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1494
|
+
Yallist$1.prototype.unshiftNode = function (node) {
|
|
1495
|
+
if (node === this.head) {
|
|
1496
|
+
return
|
|
1497
|
+
}
|
|
1508
1498
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
if (head) {
|
|
1513
|
-
head.prev = node;
|
|
1514
|
-
}
|
|
1499
|
+
if (node.list) {
|
|
1500
|
+
node.list.removeNode(node);
|
|
1501
|
+
}
|
|
1515
1502
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1503
|
+
var head = this.head;
|
|
1504
|
+
node.list = this;
|
|
1505
|
+
node.next = head;
|
|
1506
|
+
if (head) {
|
|
1507
|
+
head.prev = node;
|
|
1508
|
+
}
|
|
1522
1509
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1510
|
+
this.head = node;
|
|
1511
|
+
if (!this.tail) {
|
|
1512
|
+
this.tail = node;
|
|
1513
|
+
}
|
|
1514
|
+
this.length++;
|
|
1515
|
+
};
|
|
1527
1516
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1517
|
+
Yallist$1.prototype.pushNode = function (node) {
|
|
1518
|
+
if (node === this.tail) {
|
|
1519
|
+
return
|
|
1520
|
+
}
|
|
1531
1521
|
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
if (tail) {
|
|
1536
|
-
tail.next = node;
|
|
1537
|
-
}
|
|
1522
|
+
if (node.list) {
|
|
1523
|
+
node.list.removeNode(node);
|
|
1524
|
+
}
|
|
1538
1525
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1526
|
+
var tail = this.tail;
|
|
1527
|
+
node.list = this;
|
|
1528
|
+
node.prev = tail;
|
|
1529
|
+
if (tail) {
|
|
1530
|
+
tail.next = node;
|
|
1531
|
+
}
|
|
1545
1532
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1533
|
+
this.tail = node;
|
|
1534
|
+
if (!this.head) {
|
|
1535
|
+
this.head = node;
|
|
1536
|
+
}
|
|
1537
|
+
this.length++;
|
|
1538
|
+
};
|
|
1552
1539
|
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1540
|
+
Yallist$1.prototype.push = function () {
|
|
1541
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1542
|
+
push(this, arguments[i]);
|
|
1543
|
+
}
|
|
1544
|
+
return this.length
|
|
1545
|
+
};
|
|
1559
1546
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1547
|
+
Yallist$1.prototype.unshift = function () {
|
|
1548
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1549
|
+
unshift(this, arguments[i]);
|
|
1550
|
+
}
|
|
1551
|
+
return this.length
|
|
1552
|
+
};
|
|
1564
1553
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
} else {
|
|
1570
|
-
this.head = null;
|
|
1571
|
-
}
|
|
1572
|
-
this.length--;
|
|
1573
|
-
return res
|
|
1574
|
-
};
|
|
1554
|
+
Yallist$1.prototype.pop = function () {
|
|
1555
|
+
if (!this.tail) {
|
|
1556
|
+
return undefined
|
|
1557
|
+
}
|
|
1575
1558
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1559
|
+
var res = this.tail.value;
|
|
1560
|
+
this.tail = this.tail.prev;
|
|
1561
|
+
if (this.tail) {
|
|
1562
|
+
this.tail.next = null;
|
|
1563
|
+
} else {
|
|
1564
|
+
this.head = null;
|
|
1565
|
+
}
|
|
1566
|
+
this.length--;
|
|
1567
|
+
return res
|
|
1568
|
+
};
|
|
1580
1569
|
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
} else {
|
|
1586
|
-
this.tail = null;
|
|
1587
|
-
}
|
|
1588
|
-
this.length--;
|
|
1589
|
-
return res
|
|
1590
|
-
};
|
|
1570
|
+
Yallist$1.prototype.shift = function () {
|
|
1571
|
+
if (!this.head) {
|
|
1572
|
+
return undefined
|
|
1573
|
+
}
|
|
1591
1574
|
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1575
|
+
var res = this.head.value;
|
|
1576
|
+
this.head = this.head.next;
|
|
1577
|
+
if (this.head) {
|
|
1578
|
+
this.head.prev = null;
|
|
1579
|
+
} else {
|
|
1580
|
+
this.tail = null;
|
|
1581
|
+
}
|
|
1582
|
+
this.length--;
|
|
1583
|
+
return res
|
|
1584
|
+
};
|
|
1599
1585
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1586
|
+
Yallist$1.prototype.forEach = function (fn, thisp) {
|
|
1587
|
+
thisp = thisp || this;
|
|
1588
|
+
for (var walker = this.head, i = 0; walker !== null; i++) {
|
|
1589
|
+
fn.call(thisp, walker.value, i, this);
|
|
1590
|
+
walker = walker.next;
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1607
1593
|
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
};
|
|
1594
|
+
Yallist$1.prototype.forEachReverse = function (fn, thisp) {
|
|
1595
|
+
thisp = thisp || this;
|
|
1596
|
+
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
|
1597
|
+
fn.call(thisp, walker.value, i, this);
|
|
1598
|
+
walker = walker.prev;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1617
1601
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1602
|
+
Yallist$1.prototype.get = function (n) {
|
|
1603
|
+
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
|
1604
|
+
// abort out of the list early if we hit a cycle
|
|
1605
|
+
walker = walker.next;
|
|
1606
|
+
}
|
|
1607
|
+
if (i === n && walker !== null) {
|
|
1608
|
+
return walker.value
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1627
1611
|
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1612
|
+
Yallist$1.prototype.getReverse = function (n) {
|
|
1613
|
+
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
|
1614
|
+
// abort out of the list early if we hit a cycle
|
|
1615
|
+
walker = walker.prev;
|
|
1616
|
+
}
|
|
1617
|
+
if (i === n && walker !== null) {
|
|
1618
|
+
return walker.value
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1637
1621
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1622
|
+
Yallist$1.prototype.map = function (fn, thisp) {
|
|
1623
|
+
thisp = thisp || this;
|
|
1624
|
+
var res = new Yallist$1();
|
|
1625
|
+
for (var walker = this.head; walker !== null;) {
|
|
1626
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1627
|
+
walker = walker.next;
|
|
1628
|
+
}
|
|
1629
|
+
return res
|
|
1630
|
+
};
|
|
1647
1631
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1658
|
-
}
|
|
1632
|
+
Yallist$1.prototype.mapReverse = function (fn, thisp) {
|
|
1633
|
+
thisp = thisp || this;
|
|
1634
|
+
var res = new Yallist$1();
|
|
1635
|
+
for (var walker = this.tail; walker !== null;) {
|
|
1636
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1637
|
+
walker = walker.prev;
|
|
1638
|
+
}
|
|
1639
|
+
return res
|
|
1640
|
+
};
|
|
1659
1641
|
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1642
|
+
Yallist$1.prototype.reduce = function (fn, initial) {
|
|
1643
|
+
var acc;
|
|
1644
|
+
var walker = this.head;
|
|
1645
|
+
if (arguments.length > 1) {
|
|
1646
|
+
acc = initial;
|
|
1647
|
+
} else if (this.head) {
|
|
1648
|
+
walker = this.head.next;
|
|
1649
|
+
acc = this.head.value;
|
|
1650
|
+
} else {
|
|
1651
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1652
|
+
}
|
|
1664
1653
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1654
|
+
for (var i = 0; walker !== null; i++) {
|
|
1655
|
+
acc = fn(acc, walker.value, i);
|
|
1656
|
+
walker = walker.next;
|
|
1657
|
+
}
|
|
1667
1658
|
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
var walker = this.tail;
|
|
1671
|
-
if (arguments.length > 1) {
|
|
1672
|
-
acc = initial;
|
|
1673
|
-
} else if (this.tail) {
|
|
1674
|
-
walker = this.tail.prev;
|
|
1675
|
-
acc = this.tail.value;
|
|
1676
|
-
} else {
|
|
1677
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1678
|
-
}
|
|
1659
|
+
return acc
|
|
1660
|
+
};
|
|
1679
1661
|
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1662
|
+
Yallist$1.prototype.reduceReverse = function (fn, initial) {
|
|
1663
|
+
var acc;
|
|
1664
|
+
var walker = this.tail;
|
|
1665
|
+
if (arguments.length > 1) {
|
|
1666
|
+
acc = initial;
|
|
1667
|
+
} else if (this.tail) {
|
|
1668
|
+
walker = this.tail.prev;
|
|
1669
|
+
acc = this.tail.value;
|
|
1670
|
+
} else {
|
|
1671
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1672
|
+
}
|
|
1684
1673
|
|
|
1685
|
-
|
|
1686
|
-
|
|
1674
|
+
for (var i = this.length - 1; walker !== null; i--) {
|
|
1675
|
+
acc = fn(acc, walker.value, i);
|
|
1676
|
+
walker = walker.prev;
|
|
1677
|
+
}
|
|
1687
1678
|
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
1691
|
-
arr[i] = walker.value;
|
|
1692
|
-
walker = walker.next;
|
|
1693
|
-
}
|
|
1694
|
-
return arr
|
|
1695
|
-
};
|
|
1679
|
+
return acc
|
|
1680
|
+
};
|
|
1696
1681
|
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1682
|
+
Yallist$1.prototype.toArray = function () {
|
|
1683
|
+
var arr = new Array(this.length);
|
|
1684
|
+
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
1685
|
+
arr[i] = walker.value;
|
|
1686
|
+
walker = walker.next;
|
|
1687
|
+
}
|
|
1688
|
+
return arr
|
|
1689
|
+
};
|
|
1705
1690
|
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
}
|
|
1715
|
-
var ret = new Yallist();
|
|
1716
|
-
if (to < from || to < 0) {
|
|
1717
|
-
return ret
|
|
1718
|
-
}
|
|
1719
|
-
if (from < 0) {
|
|
1720
|
-
from = 0;
|
|
1721
|
-
}
|
|
1722
|
-
if (to > this.length) {
|
|
1723
|
-
to = this.length;
|
|
1724
|
-
}
|
|
1725
|
-
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
1726
|
-
walker = walker.next;
|
|
1727
|
-
}
|
|
1728
|
-
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
1729
|
-
ret.push(walker.value);
|
|
1730
|
-
}
|
|
1731
|
-
return ret
|
|
1732
|
-
};
|
|
1691
|
+
Yallist$1.prototype.toArrayReverse = function () {
|
|
1692
|
+
var arr = new Array(this.length);
|
|
1693
|
+
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
|
1694
|
+
arr[i] = walker.value;
|
|
1695
|
+
walker = walker.prev;
|
|
1696
|
+
}
|
|
1697
|
+
return arr
|
|
1698
|
+
};
|
|
1733
1699
|
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1700
|
+
Yallist$1.prototype.slice = function (from, to) {
|
|
1701
|
+
to = to || this.length;
|
|
1702
|
+
if (to < 0) {
|
|
1703
|
+
to += this.length;
|
|
1704
|
+
}
|
|
1705
|
+
from = from || 0;
|
|
1706
|
+
if (from < 0) {
|
|
1707
|
+
from += this.length;
|
|
1708
|
+
}
|
|
1709
|
+
var ret = new Yallist$1();
|
|
1710
|
+
if (to < from || to < 0) {
|
|
1711
|
+
return ret
|
|
1712
|
+
}
|
|
1713
|
+
if (from < 0) {
|
|
1714
|
+
from = 0;
|
|
1715
|
+
}
|
|
1716
|
+
if (to > this.length) {
|
|
1717
|
+
to = this.length;
|
|
1718
|
+
}
|
|
1719
|
+
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
1720
|
+
walker = walker.next;
|
|
1721
|
+
}
|
|
1722
|
+
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
1723
|
+
ret.push(walker.value);
|
|
1724
|
+
}
|
|
1725
|
+
return ret
|
|
1726
|
+
};
|
|
1761
1727
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1728
|
+
Yallist$1.prototype.sliceReverse = function (from, to) {
|
|
1729
|
+
to = to || this.length;
|
|
1730
|
+
if (to < 0) {
|
|
1731
|
+
to += this.length;
|
|
1732
|
+
}
|
|
1733
|
+
from = from || 0;
|
|
1734
|
+
if (from < 0) {
|
|
1735
|
+
from += this.length;
|
|
1736
|
+
}
|
|
1737
|
+
var ret = new Yallist$1();
|
|
1738
|
+
if (to < from || to < 0) {
|
|
1739
|
+
return ret
|
|
1740
|
+
}
|
|
1741
|
+
if (from < 0) {
|
|
1742
|
+
from = 0;
|
|
1743
|
+
}
|
|
1744
|
+
if (to > this.length) {
|
|
1745
|
+
to = this.length;
|
|
1746
|
+
}
|
|
1747
|
+
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
|
1748
|
+
walker = walker.prev;
|
|
1749
|
+
}
|
|
1750
|
+
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
|
1751
|
+
ret.push(walker.value);
|
|
1752
|
+
}
|
|
1753
|
+
return ret
|
|
1754
|
+
};
|
|
1769
1755
|
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1756
|
+
Yallist$1.prototype.splice = function (start, deleteCount, ...nodes) {
|
|
1757
|
+
if (start > this.length) {
|
|
1758
|
+
start = this.length - 1;
|
|
1759
|
+
}
|
|
1760
|
+
if (start < 0) {
|
|
1761
|
+
start = this.length + start;
|
|
1762
|
+
}
|
|
1773
1763
|
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
walker = this.removeNode(walker);
|
|
1778
|
-
}
|
|
1779
|
-
if (walker === null) {
|
|
1780
|
-
walker = this.tail;
|
|
1781
|
-
}
|
|
1764
|
+
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
1765
|
+
walker = walker.next;
|
|
1766
|
+
}
|
|
1782
1767
|
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1768
|
+
var ret = [];
|
|
1769
|
+
for (var i = 0; walker && i < deleteCount; i++) {
|
|
1770
|
+
ret.push(walker.value);
|
|
1771
|
+
walker = this.removeNode(walker);
|
|
1772
|
+
}
|
|
1773
|
+
if (walker === null) {
|
|
1774
|
+
walker = this.tail;
|
|
1775
|
+
}
|
|
1786
1776
|
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
return ret;
|
|
1791
|
-
};
|
|
1777
|
+
if (walker !== this.head && walker !== this.tail) {
|
|
1778
|
+
walker = walker.prev;
|
|
1779
|
+
}
|
|
1792
1780
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
walker.prev = walker.next;
|
|
1799
|
-
walker.next = p;
|
|
1800
|
-
}
|
|
1801
|
-
this.head = tail;
|
|
1802
|
-
this.tail = head;
|
|
1803
|
-
return this
|
|
1804
|
-
};
|
|
1781
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1782
|
+
walker = insert(this, walker, nodes[i]);
|
|
1783
|
+
}
|
|
1784
|
+
return ret;
|
|
1785
|
+
};
|
|
1805
1786
|
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1787
|
+
Yallist$1.prototype.reverse = function () {
|
|
1788
|
+
var head = this.head;
|
|
1789
|
+
var tail = this.tail;
|
|
1790
|
+
for (var walker = head; walker !== null; walker = walker.prev) {
|
|
1791
|
+
var p = walker.prev;
|
|
1792
|
+
walker.prev = walker.next;
|
|
1793
|
+
walker.next = p;
|
|
1794
|
+
}
|
|
1795
|
+
this.head = tail;
|
|
1796
|
+
this.tail = head;
|
|
1797
|
+
return this
|
|
1798
|
+
};
|
|
1810
1799
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
self.head = inserted;
|
|
1816
|
-
}
|
|
1800
|
+
function insert (self, node, value) {
|
|
1801
|
+
var inserted = node === self.head ?
|
|
1802
|
+
new Node(value, null, node, self) :
|
|
1803
|
+
new Node(value, node, node.next, self);
|
|
1817
1804
|
|
|
1818
|
-
|
|
1805
|
+
if (inserted.next === null) {
|
|
1806
|
+
self.tail = inserted;
|
|
1807
|
+
}
|
|
1808
|
+
if (inserted.prev === null) {
|
|
1809
|
+
self.head = inserted;
|
|
1810
|
+
}
|
|
1819
1811
|
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1812
|
+
self.length++;
|
|
1822
1813
|
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
if (!self.head) {
|
|
1826
|
-
self.head = self.tail;
|
|
1827
|
-
}
|
|
1828
|
-
self.length++;
|
|
1829
|
-
}
|
|
1814
|
+
return inserted
|
|
1815
|
+
}
|
|
1830
1816
|
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1817
|
+
function push (self, item) {
|
|
1818
|
+
self.tail = new Node(item, self.tail, null, self);
|
|
1819
|
+
if (!self.head) {
|
|
1820
|
+
self.head = self.tail;
|
|
1821
|
+
}
|
|
1822
|
+
self.length++;
|
|
1823
|
+
}
|
|
1838
1824
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1825
|
+
function unshift (self, item) {
|
|
1826
|
+
self.head = new Node(item, null, self.head, self);
|
|
1827
|
+
if (!self.tail) {
|
|
1828
|
+
self.tail = self.head;
|
|
1829
|
+
}
|
|
1830
|
+
self.length++;
|
|
1831
|
+
}
|
|
1843
1832
|
|
|
1844
|
-
|
|
1845
|
-
|
|
1833
|
+
function Node (value, prev, next, list) {
|
|
1834
|
+
if (!(this instanceof Node)) {
|
|
1835
|
+
return new Node(value, prev, next, list)
|
|
1836
|
+
}
|
|
1846
1837
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
this.prev = prev;
|
|
1850
|
-
} else {
|
|
1851
|
-
this.prev = null;
|
|
1852
|
-
}
|
|
1838
|
+
this.list = list;
|
|
1839
|
+
this.value = value;
|
|
1853
1840
|
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1841
|
+
if (prev) {
|
|
1842
|
+
prev.next = this;
|
|
1843
|
+
this.prev = prev;
|
|
1844
|
+
} else {
|
|
1845
|
+
this.prev = null;
|
|
1846
|
+
}
|
|
1861
1847
|
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1848
|
+
if (next) {
|
|
1849
|
+
next.prev = this;
|
|
1850
|
+
this.next = next;
|
|
1851
|
+
} else {
|
|
1852
|
+
this.next = null;
|
|
1853
|
+
}
|
|
1867
1854
|
}
|
|
1868
1855
|
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
this.reset();
|
|
1923
|
-
}
|
|
1856
|
+
try {
|
|
1857
|
+
// add if support for Symbol.iterator is present
|
|
1858
|
+
requireIterator()(Yallist$1);
|
|
1859
|
+
} catch (er) {}
|
|
1860
|
+
|
|
1861
|
+
// A linked list to keep track of recently-used-ness
|
|
1862
|
+
const Yallist = yallist;
|
|
1863
|
+
|
|
1864
|
+
const MAX = Symbol('max');
|
|
1865
|
+
const LENGTH = Symbol('length');
|
|
1866
|
+
const LENGTH_CALCULATOR = Symbol('lengthCalculator');
|
|
1867
|
+
const ALLOW_STALE = Symbol('allowStale');
|
|
1868
|
+
const MAX_AGE = Symbol('maxAge');
|
|
1869
|
+
const DISPOSE = Symbol('dispose');
|
|
1870
|
+
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
|
|
1871
|
+
const LRU_LIST = Symbol('lruList');
|
|
1872
|
+
const CACHE = Symbol('cache');
|
|
1873
|
+
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
|
|
1874
|
+
|
|
1875
|
+
const naiveLength = () => 1;
|
|
1876
|
+
|
|
1877
|
+
// lruList is a yallist where the head is the youngest
|
|
1878
|
+
// item, and the tail is the oldest. the list contains the Hit
|
|
1879
|
+
// objects as the entries.
|
|
1880
|
+
// Each Hit object has a reference to its Yallist.Node. This
|
|
1881
|
+
// never changes.
|
|
1882
|
+
//
|
|
1883
|
+
// cache is a Map (or PseudoMap) that matches the keys to
|
|
1884
|
+
// the Yallist.Node object.
|
|
1885
|
+
class LRUCache {
|
|
1886
|
+
constructor (options) {
|
|
1887
|
+
if (typeof options === 'number')
|
|
1888
|
+
options = { max: options };
|
|
1889
|
+
|
|
1890
|
+
if (!options)
|
|
1891
|
+
options = {};
|
|
1892
|
+
|
|
1893
|
+
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
|
1894
|
+
throw new TypeError('max must be a non-negative number')
|
|
1895
|
+
// Kind of weird to have a default max of Infinity, but oh well.
|
|
1896
|
+
this[MAX] = options.max || Infinity;
|
|
1897
|
+
|
|
1898
|
+
const lc = options.length || naiveLength;
|
|
1899
|
+
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
|
|
1900
|
+
this[ALLOW_STALE] = options.stale || false;
|
|
1901
|
+
if (options.maxAge && typeof options.maxAge !== 'number')
|
|
1902
|
+
throw new TypeError('maxAge must be a number')
|
|
1903
|
+
this[MAX_AGE] = options.maxAge || 0;
|
|
1904
|
+
this[DISPOSE] = options.dispose;
|
|
1905
|
+
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
|
|
1906
|
+
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
|
|
1907
|
+
this.reset();
|
|
1908
|
+
}
|
|
1924
1909
|
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1910
|
+
// resize the cache when the max changes.
|
|
1911
|
+
set max (mL) {
|
|
1912
|
+
if (typeof mL !== 'number' || mL < 0)
|
|
1913
|
+
throw new TypeError('max must be a non-negative number')
|
|
1929
1914
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1915
|
+
this[MAX] = mL || Infinity;
|
|
1916
|
+
trim(this);
|
|
1917
|
+
}
|
|
1918
|
+
get max () {
|
|
1919
|
+
return this[MAX]
|
|
1920
|
+
}
|
|
1936
1921
|
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1922
|
+
set allowStale (allowStale) {
|
|
1923
|
+
this[ALLOW_STALE] = !!allowStale;
|
|
1924
|
+
}
|
|
1925
|
+
get allowStale () {
|
|
1926
|
+
return this[ALLOW_STALE]
|
|
1927
|
+
}
|
|
1943
1928
|
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1929
|
+
set maxAge (mA) {
|
|
1930
|
+
if (typeof mA !== 'number')
|
|
1931
|
+
throw new TypeError('maxAge must be a non-negative number')
|
|
1947
1932
|
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1933
|
+
this[MAX_AGE] = mA;
|
|
1934
|
+
trim(this);
|
|
1935
|
+
}
|
|
1936
|
+
get maxAge () {
|
|
1937
|
+
return this[MAX_AGE]
|
|
1938
|
+
}
|
|
1954
1939
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1940
|
+
// resize the cache when the lengthCalculator changes.
|
|
1941
|
+
set lengthCalculator (lC) {
|
|
1942
|
+
if (typeof lC !== 'function')
|
|
1943
|
+
lC = naiveLength;
|
|
1944
|
+
|
|
1945
|
+
if (lC !== this[LENGTH_CALCULATOR]) {
|
|
1946
|
+
this[LENGTH_CALCULATOR] = lC;
|
|
1947
|
+
this[LENGTH] = 0;
|
|
1948
|
+
this[LRU_LIST].forEach(hit => {
|
|
1949
|
+
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
|
|
1950
|
+
this[LENGTH] += hit.length;
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
trim(this);
|
|
1954
|
+
}
|
|
1955
|
+
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
|
1971
1956
|
|
|
1972
|
-
|
|
1973
|
-
|
|
1957
|
+
get length () { return this[LENGTH] }
|
|
1958
|
+
get itemCount () { return this[LRU_LIST].length }
|
|
1974
1959
|
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1960
|
+
rforEach (fn, thisp) {
|
|
1961
|
+
thisp = thisp || this;
|
|
1962
|
+
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
|
1963
|
+
const prev = walker.prev;
|
|
1964
|
+
forEachStep(this, fn, walker, thisp);
|
|
1965
|
+
walker = prev;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1983
1968
|
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1969
|
+
forEach (fn, thisp) {
|
|
1970
|
+
thisp = thisp || this;
|
|
1971
|
+
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
|
1972
|
+
const next = walker.next;
|
|
1973
|
+
forEachStep(this, fn, walker, thisp);
|
|
1974
|
+
walker = next;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1992
1977
|
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1978
|
+
keys () {
|
|
1979
|
+
return this[LRU_LIST].toArray().map(k => k.key)
|
|
1980
|
+
}
|
|
1996
1981
|
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1982
|
+
values () {
|
|
1983
|
+
return this[LRU_LIST].toArray().map(k => k.value)
|
|
1984
|
+
}
|
|
2000
1985
|
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
1986
|
+
reset () {
|
|
1987
|
+
if (this[DISPOSE] &&
|
|
1988
|
+
this[LRU_LIST] &&
|
|
1989
|
+
this[LRU_LIST].length) {
|
|
1990
|
+
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
|
|
1991
|
+
}
|
|
2007
1992
|
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
1993
|
+
this[CACHE] = new Map(); // hash of items by key
|
|
1994
|
+
this[LRU_LIST] = new Yallist(); // list of items in order of use recency
|
|
1995
|
+
this[LENGTH] = 0; // length of items in the list
|
|
1996
|
+
}
|
|
2012
1997
|
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
1998
|
+
dump () {
|
|
1999
|
+
return this[LRU_LIST].map(hit =>
|
|
2000
|
+
isStale(this, hit) ? false : {
|
|
2001
|
+
k: hit.key,
|
|
2002
|
+
v: hit.value,
|
|
2003
|
+
e: hit.now + (hit.maxAge || 0)
|
|
2004
|
+
}).toArray().filter(h => h)
|
|
2005
|
+
}
|
|
2021
2006
|
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2007
|
+
dumpLru () {
|
|
2008
|
+
return this[LRU_LIST]
|
|
2009
|
+
}
|
|
2025
2010
|
|
|
2026
|
-
|
|
2027
|
-
|
|
2011
|
+
set (key, value, maxAge) {
|
|
2012
|
+
maxAge = maxAge || this[MAX_AGE];
|
|
2028
2013
|
|
|
2029
|
-
|
|
2030
|
-
|
|
2014
|
+
if (maxAge && typeof maxAge !== 'number')
|
|
2015
|
+
throw new TypeError('maxAge must be a number')
|
|
2031
2016
|
|
|
2032
|
-
|
|
2033
|
-
|
|
2017
|
+
const now = maxAge ? Date.now() : 0;
|
|
2018
|
+
const len = this[LENGTH_CALCULATOR](value, key);
|
|
2034
2019
|
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2020
|
+
if (this[CACHE].has(key)) {
|
|
2021
|
+
if (len > this[MAX]) {
|
|
2022
|
+
del(this, this[CACHE].get(key));
|
|
2023
|
+
return false
|
|
2024
|
+
}
|
|
2040
2025
|
|
|
2041
|
-
|
|
2042
|
-
|
|
2026
|
+
const node = this[CACHE].get(key);
|
|
2027
|
+
const item = node.value;
|
|
2043
2028
|
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2029
|
+
// dispose of the old one before overwriting
|
|
2030
|
+
// split out into 2 ifs for better coverage tracking
|
|
2031
|
+
if (this[DISPOSE]) {
|
|
2032
|
+
if (!this[NO_DISPOSE_ON_SET])
|
|
2033
|
+
this[DISPOSE](key, item.value);
|
|
2034
|
+
}
|
|
2050
2035
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2036
|
+
item.now = now;
|
|
2037
|
+
item.maxAge = maxAge;
|
|
2038
|
+
item.value = value;
|
|
2039
|
+
this[LENGTH] += len - item.length;
|
|
2040
|
+
item.length = len;
|
|
2041
|
+
this.get(key);
|
|
2042
|
+
trim(this);
|
|
2043
|
+
return true
|
|
2044
|
+
}
|
|
2060
2045
|
|
|
2061
|
-
|
|
2046
|
+
const hit = new Entry(key, value, len, now, maxAge);
|
|
2062
2047
|
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2048
|
+
// oversized objects fall out of cache automatically.
|
|
2049
|
+
if (hit.length > this[MAX]) {
|
|
2050
|
+
if (this[DISPOSE])
|
|
2051
|
+
this[DISPOSE](key, value);
|
|
2067
2052
|
|
|
2068
|
-
|
|
2069
|
-
|
|
2053
|
+
return false
|
|
2054
|
+
}
|
|
2070
2055
|
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2056
|
+
this[LENGTH] += hit.length;
|
|
2057
|
+
this[LRU_LIST].unshift(hit);
|
|
2058
|
+
this[CACHE].set(key, this[LRU_LIST].head);
|
|
2059
|
+
trim(this);
|
|
2060
|
+
return true
|
|
2061
|
+
}
|
|
2077
2062
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2063
|
+
has (key) {
|
|
2064
|
+
if (!this[CACHE].has(key)) return false
|
|
2065
|
+
const hit = this[CACHE].get(key).value;
|
|
2066
|
+
return !isStale(this, hit)
|
|
2067
|
+
}
|
|
2083
2068
|
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2069
|
+
get (key) {
|
|
2070
|
+
return get(this, key, true)
|
|
2071
|
+
}
|
|
2087
2072
|
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2073
|
+
peek (key) {
|
|
2074
|
+
return get(this, key, false)
|
|
2075
|
+
}
|
|
2091
2076
|
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2077
|
+
pop () {
|
|
2078
|
+
const node = this[LRU_LIST].tail;
|
|
2079
|
+
if (!node)
|
|
2080
|
+
return null
|
|
2096
2081
|
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2082
|
+
del(this, node);
|
|
2083
|
+
return node.value
|
|
2084
|
+
}
|
|
2100
2085
|
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2086
|
+
del (key) {
|
|
2087
|
+
del(this, this[CACHE].get(key));
|
|
2088
|
+
}
|
|
2104
2089
|
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2090
|
+
load (arr) {
|
|
2091
|
+
// reset the cache
|
|
2092
|
+
this.reset();
|
|
2093
|
+
|
|
2094
|
+
const now = Date.now();
|
|
2095
|
+
// A previous serialized cache has the most recent items first
|
|
2096
|
+
for (let l = arr.length - 1; l >= 0; l--) {
|
|
2097
|
+
const hit = arr[l];
|
|
2098
|
+
const expiresAt = hit.e || 0;
|
|
2099
|
+
if (expiresAt === 0)
|
|
2100
|
+
// the item was created without expiration in a non aged cache
|
|
2101
|
+
this.set(hit.k, hit.v);
|
|
2102
|
+
else {
|
|
2103
|
+
const maxAge = expiresAt - now;
|
|
2104
|
+
// dont add already expired items
|
|
2105
|
+
if (maxAge > 0) {
|
|
2106
|
+
this.set(hit.k, hit.v, maxAge);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2126
2111
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2112
|
+
prune () {
|
|
2113
|
+
this[CACHE].forEach((value, key) => get(this, key, false));
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2131
2116
|
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2117
|
+
const get = (self, key, doUse) => {
|
|
2118
|
+
const node = self[CACHE].get(key);
|
|
2119
|
+
if (node) {
|
|
2120
|
+
const hit = node.value;
|
|
2121
|
+
if (isStale(self, hit)) {
|
|
2122
|
+
del(self, node);
|
|
2123
|
+
if (!self[ALLOW_STALE])
|
|
2124
|
+
return undefined
|
|
2125
|
+
} else {
|
|
2126
|
+
if (doUse) {
|
|
2127
|
+
if (self[UPDATE_AGE_ON_GET])
|
|
2128
|
+
node.value.now = Date.now();
|
|
2129
|
+
self[LRU_LIST].unshiftNode(node);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
return hit.value
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2150
2135
|
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2136
|
+
const isStale = (self, hit) => {
|
|
2137
|
+
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
|
2138
|
+
return false
|
|
2154
2139
|
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2140
|
+
const diff = Date.now() - hit.now;
|
|
2141
|
+
return hit.maxAge ? diff > hit.maxAge
|
|
2142
|
+
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
|
2143
|
+
};
|
|
2159
2144
|
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2145
|
+
const trim = self => {
|
|
2146
|
+
if (self[LENGTH] > self[MAX]) {
|
|
2147
|
+
for (let walker = self[LRU_LIST].tail;
|
|
2148
|
+
self[LENGTH] > self[MAX] && walker !== null;) {
|
|
2149
|
+
// We know that we're about to delete this one, and also
|
|
2150
|
+
// what the next least recently used key will be, so just
|
|
2151
|
+
// go ahead and set it now.
|
|
2152
|
+
const prev = walker.prev;
|
|
2153
|
+
del(self, walker);
|
|
2154
|
+
walker = prev;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2173
2158
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2159
|
+
const del = (self, node) => {
|
|
2160
|
+
if (node) {
|
|
2161
|
+
const hit = node.value;
|
|
2162
|
+
if (self[DISPOSE])
|
|
2163
|
+
self[DISPOSE](hit.key, hit.value);
|
|
2179
2164
|
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2165
|
+
self[LENGTH] -= hit.length;
|
|
2166
|
+
self[CACHE].delete(hit.key);
|
|
2167
|
+
self[LRU_LIST].removeNode(node);
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2185
2170
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2171
|
+
class Entry {
|
|
2172
|
+
constructor (key, value, length, now, maxAge) {
|
|
2173
|
+
this.key = key;
|
|
2174
|
+
this.value = value;
|
|
2175
|
+
this.length = length;
|
|
2176
|
+
this.now = now;
|
|
2177
|
+
this.maxAge = maxAge || 0;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2195
2180
|
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2181
|
+
const forEachStep = (self, fn, node, thisp) => {
|
|
2182
|
+
let hit = node.value;
|
|
2183
|
+
if (isStale(self, hit)) {
|
|
2184
|
+
del(self, node);
|
|
2185
|
+
if (!self[ALLOW_STALE])
|
|
2186
|
+
hit = undefined;
|
|
2187
|
+
}
|
|
2188
|
+
if (hit)
|
|
2189
|
+
fn.call(thisp, hit.value, hit.key, self);
|
|
2190
|
+
};
|
|
2206
2191
|
|
|
2207
|
-
|
|
2208
|
-
return lruCache;
|
|
2209
|
-
}
|
|
2192
|
+
var lruCache = LRUCache;
|
|
2210
2193
|
|
|
2211
2194
|
var range;
|
|
2212
2195
|
var hasRequiredRange;
|
|
@@ -2414,7 +2397,7 @@ function requireRange () {
|
|
|
2414
2397
|
|
|
2415
2398
|
range = Range;
|
|
2416
2399
|
|
|
2417
|
-
const LRU =
|
|
2400
|
+
const LRU = lruCache;
|
|
2418
2401
|
const cache = new LRU({ max: 1000 });
|
|
2419
2402
|
|
|
2420
2403
|
const parseOptions = parseOptions_1;
|