@lowentry/utils 1.4.1 → 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/LeUtils.js +33 -11
- package/package.json +1 -1
package/LeUtils.js
CHANGED
|
@@ -811,6 +811,21 @@ export const LeUtils = {
|
|
|
811
811
|
return (a.length < b.length) ? -1 : 1;
|
|
812
812
|
},
|
|
813
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Compares two strings generated by LeUtils.timestamp(). Primarily used for sorting.
|
|
816
|
+
*
|
|
817
|
+
* @param {string} a
|
|
818
|
+
* @param {string} b
|
|
819
|
+
* @returns {number}
|
|
820
|
+
*/
|
|
821
|
+
compareTimestampStrings:
|
|
822
|
+
(a, b) =>
|
|
823
|
+
{
|
|
824
|
+
a = LeUtils.base64ToHex(STRING(a));
|
|
825
|
+
b = LeUtils.base64ToHex(STRING(b));
|
|
826
|
+
return LeUtils.compare(a, b);
|
|
827
|
+
},
|
|
828
|
+
|
|
814
829
|
/**
|
|
815
830
|
* Returns true if the given object is empty, false otherwise.
|
|
816
831
|
*
|
|
@@ -1593,6 +1608,7 @@ export const LeUtils = {
|
|
|
1593
1608
|
/**
|
|
1594
1609
|
* Generates a base64 string (with +/ replaced by -_) of the current time (in milliseconds since 1970).
|
|
1595
1610
|
*
|
|
1611
|
+
* @param {number} [now] Optional time to use instead of the current time. If not set, the current time will be used.
|
|
1596
1612
|
* @returns {string}
|
|
1597
1613
|
*/
|
|
1598
1614
|
timestamp:
|
|
@@ -1612,21 +1628,27 @@ export const LeUtils = {
|
|
|
1612
1628
|
return bytes;
|
|
1613
1629
|
};
|
|
1614
1630
|
|
|
1615
|
-
return () =>
|
|
1631
|
+
return (now = null) =>
|
|
1616
1632
|
{
|
|
1617
|
-
|
|
1618
|
-
try
|
|
1633
|
+
if(ISSET(now))
|
|
1619
1634
|
{
|
|
1620
|
-
|
|
1621
|
-
now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
|
|
1622
|
-
if(typeof now !== 'number')
|
|
1623
|
-
{
|
|
1624
|
-
throw new Error();
|
|
1625
|
-
}
|
|
1635
|
+
now = FLOAT_LAX(now);
|
|
1626
1636
|
}
|
|
1627
|
-
|
|
1637
|
+
else
|
|
1628
1638
|
{
|
|
1629
|
-
|
|
1639
|
+
try
|
|
1640
|
+
{
|
|
1641
|
+
// noinspection JSDeprecatedSymbols
|
|
1642
|
+
now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
|
|
1643
|
+
if(typeof now !== 'number')
|
|
1644
|
+
{
|
|
1645
|
+
throw new Error();
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
catch(e)
|
|
1649
|
+
{
|
|
1650
|
+
now = (Date.now ? Date.now() : (new Date()).getTime());
|
|
1651
|
+
}
|
|
1630
1652
|
}
|
|
1631
1653
|
now = Math.round(now);
|
|
1632
1654
|
const nowBytes = numberToBytes(now);
|