@vbarbarosh/node-helpers 3.23.0 → 3.23.2

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.23.0",
5
+ "version": "3.23.2",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -1,6 +1,6 @@
1
1
  function format_percents(v)
2
2
  {
3
- return (v*100).toFixed(2).replace(/\.0+$/, '') + '%';
3
+ return (v*100).toFixed(2).replace(/^(0|100).00$/, '$1') + '%';
4
4
  }
5
5
 
6
6
  module.exports = format_percents;
@@ -4,7 +4,12 @@ const format_percents = require('./format_percents');
4
4
  const items = [
5
5
  ['', '0%'],
6
6
  [0, '0%'],
7
- [0.5, '50%'],
7
+ [0.01, '1.00%'],
8
+ [0.0101, '1.01%'],
9
+ [0.1, '10.00%'],
10
+ [0.5, '50.00%'],
11
+ [0.99, '99.00%'],
12
+ [0.9901, '99.01%'],
8
13
  [1, '100%'],
9
14
  ];
10
15
 
@@ -6,6 +6,9 @@ const is_number_gt = require('./is_number_gt');
6
6
  function format_progress({percents, total, done, rate, eta, duration})
7
7
  {
8
8
  const bps = is_number_gt(rate, 0) ? `${format_bytes(rate)}/s` : '~';
9
+ if (done > total) {
10
+ return `${format_bytes(done)} at ${bps} duration=${format_seconds(duration)}`;
11
+ }
9
12
  if (is_number_gt(total, 0)) {
10
13
  const eta_str = is_number_gt(eta, 0) ? format_seconds(eta) : '~';
11
14
  return `${format_percents(percents)} | ${format_bytes(done)} of ${format_bytes(total)} at ${bps} ETA ${eta_str} duration=${format_seconds(duration)}`;
@@ -6,6 +6,8 @@ const items = [
6
6
  ['~ duration=00:00:01', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 1}],
7
7
  ['25.25% | 5.0MB of 15.0MB at ~ ETA ~ duration=00:00:01', {percents: 0.2525, total: 15*1024*1024, done: 5*1024*1024, rate: 0, eta: 0, duration: 1}],
8
8
  ['25.25% | 5.0MB of 15.0MB at 10.0MB/s ETA 00:00:05 duration=00:00:01', {percents: 0.2525, total: 15*1024*1024, done: 5*1024*1024, rate: 10*1024*1024, eta: 5, duration: 1}],
9
+ // edge case: done > total
10
+ ['15.0MB at 10.0MB/s duration=00:00:01', {percents: 5.2525, total: 5*1024*1024, done: 15*1024*1024, rate: 10*1024*1024, eta: 5, duration: 1}],
9
11
  ];
10
12
 
11
13
  describe('format_progress', function () {