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