@vbarbarosh/node-helpers 3.43.0 → 3.45.0
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/package.json +1 -1
- package/src/assert_valid_expires_at.js +14 -0
- package/src/format_hrtime.js +10 -0
- package/src/perf_end_human.js +1 -1
- package/src/random_hex.js +11 -0
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that the provided value is a date pointing to the future.
|
|
3
|
+
*/
|
|
4
|
+
function assert_valid_expires_at(expires_at)
|
|
5
|
+
{
|
|
6
|
+
if (expires_at instanceof Date) {
|
|
7
|
+
if (expires_at.getTime() > Date.now()) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
throw new Error('Invalid value for expires_at; it should be a Date object pointing to the future.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = assert_valid_expires_at;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return a human-readable representation of hrtime (the return value from `process.hrtime(hrtime0)`).
|
|
3
|
+
*/
|
|
4
|
+
function format_hrtime(hrtime, digits = 6)
|
|
5
|
+
{
|
|
6
|
+
const [u, v] = hrtime; // process.hrtime(hrtime0)
|
|
7
|
+
return (u + v/1E9).toFixed(digits) + 's';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = format_hrtime;
|
package/src/perf_end_human.js
CHANGED