@vbarbarosh/node-helpers 3.18.0 → 3.18.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.18.0",
5
+ "version": "3.18.1",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -21,10 +21,9 @@ function make_progress(total)
21
21
  progress: null,
22
22
  percents: null,
23
23
  add: function (delta = 0) {
24
- const now_minus_5sec = Date.now() - 5000;
24
+ const now_minus_10sec = Date.now() - 10000;
25
+ history.splice(0, history.findLastIndex(v => v.time < now_minus_10sec));
25
26
  history.push({time: Date.now(), delta});
26
- // Keep last 5 seconds
27
- history.splice(0, history.findLastIndex(v => v.time < now_minus_5sec));
28
27
  out.done += delta;
29
28
  out.refresh();
30
29
  },
@@ -32,19 +31,17 @@ function make_progress(total)
32
31
  out.add(done - out.done);
33
32
  },
34
33
  refresh: function () {
35
- const now_minus_2sec = Date.now() - 2000;
36
- const tmp = history.filter(v => v.time >= now_minus_2sec);
37
- if (tmp.length > 1) {
38
- const items = tmp.reduce((a,v) => a + v.delta, 0);
39
- const time_sec = (tmp.pop().time - tmp[0].time)/1000;
40
- out.rate = items/time_sec;
34
+ out.duration = (Date.now() - time0)/1000;
35
+ out.percents = !out.total ? null : out.done/out.total;
36
+ out.eta = !out.total ? null : (out.total - out.done)/out.rate;
37
+ if (history.length) {
38
+ const delta = history.reduce((a,v) => a + v.delta, 0);
39
+ const time_sec = (Date.now() - history[0].time)/1000;
40
+ out.rate = delta/time_sec;
41
41
  }
42
42
  else {
43
43
  out.rate = out.done/out.duration;
44
44
  }
45
- out.duration = (Date.now() - time0)/1000;
46
- out.percents = !out.total ? null : out.done/out.total;
47
- out.eta = !out.total ? null : (out.total - out.done)/out.rate;
48
45
  },
49
46
  };
50
47
  return out;