@vbarbarosh/node-helpers 3.44.0 → 3.46.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/README.md +2 -0
- package/package.json +1 -1
- package/src/assert_valid_expires_at.js +14 -0
- package/src/random_hex.js +11 -0
- package/src/stream_progress.js +3 -1
package/README.md
CHANGED
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;
|
package/src/stream_progress.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const format_progress_bytes = require('./format_progress_bytes');
|
|
2
|
+
const format_progress_kilo = require('./format_progress_kilo');
|
|
2
3
|
const make_progress = require('./make_progress');
|
|
3
4
|
const stream = require('stream');
|
|
4
5
|
|
|
@@ -12,6 +13,7 @@ function stream_progress({objectMode = false, total, user_friendly_status = s =>
|
|
|
12
13
|
let done = 0;
|
|
13
14
|
const timer = setInterval(tick, 1000);
|
|
14
15
|
const progress = make_progress(total);
|
|
16
|
+
const format_progress = objectMode ? format_progress_kilo : format_progress_bytes;
|
|
15
17
|
return new stream.Transform({
|
|
16
18
|
objectMode,
|
|
17
19
|
destroy: function (error, callback) {
|
|
@@ -33,7 +35,7 @@ function stream_progress({objectMode = false, total, user_friendly_status = s =>
|
|
|
33
35
|
});
|
|
34
36
|
function tick() {
|
|
35
37
|
progress.update(done);
|
|
36
|
-
user_friendly_status(
|
|
38
|
+
user_friendly_status(format_progress(progress));
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|