@lowentry/utils 1.4.1 → 1.5.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.
Files changed (2) hide show
  1. package/LeUtils.js +18 -11
  2. package/package.json +1 -1
package/LeUtils.js CHANGED
@@ -1593,6 +1593,7 @@ export const LeUtils = {
1593
1593
  /**
1594
1594
  * Generates a base64 string (with +/ replaced by -_) of the current time (in milliseconds since 1970).
1595
1595
  *
1596
+ * @param {number} [now] Optional time to use instead of the current time. If not set, the current time will be used.
1596
1597
  * @returns {string}
1597
1598
  */
1598
1599
  timestamp:
@@ -1612,21 +1613,27 @@ export const LeUtils = {
1612
1613
  return bytes;
1613
1614
  };
1614
1615
 
1615
- return () =>
1616
+ return (now = null) =>
1616
1617
  {
1617
- let now;
1618
- try
1618
+ if(ISSET(now))
1619
1619
  {
1620
- // noinspection JSDeprecatedSymbols
1621
- now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
1622
- if(typeof now !== 'number')
1623
- {
1624
- throw new Error();
1625
- }
1620
+ now = FLOAT_LAX(now);
1626
1621
  }
1627
- catch(e)
1622
+ else
1628
1623
  {
1629
- now = (Date.now ? Date.now() : (new Date()).getTime());
1624
+ try
1625
+ {
1626
+ // noinspection JSDeprecatedSymbols
1627
+ now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
1628
+ if(typeof now !== 'number')
1629
+ {
1630
+ throw new Error();
1631
+ }
1632
+ }
1633
+ catch(e)
1634
+ {
1635
+ now = (Date.now ? Date.now() : (new Date()).getTime());
1636
+ }
1630
1637
  }
1631
1638
  now = Math.round(now);
1632
1639
  const nowBytes = numberToBytes(now);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/utils",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Provides utilities for general JavaScript development.",