xprogress 0.17.1 → 0.18.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/dist/index.js CHANGED
@@ -24,35 +24,35 @@ var _speedometer = _interopRequireDefault(require("speedometer"));
24
24
 
25
25
  var _progressStream = _interopRequireDefault(require("progress-stream"));
26
26
 
27
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
28
28
 
29
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
29
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
30
30
 
31
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
32
32
 
33
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
33
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
34
34
 
35
35
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
36
 
37
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
37
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
38
38
 
39
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
40
40
 
41
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
41
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
42
42
 
43
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
43
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
44
44
 
45
45
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
46
46
 
47
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
47
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
48
48
 
49
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
49
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
50
50
 
51
51
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
52
52
 
53
53
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
54
54
 
55
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
55
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
56
56
 
57
57
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
58
58
 
@@ -60,17 +60,17 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
60
60
 
61
61
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
62
62
 
63
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
63
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
64
64
 
65
65
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
66
66
 
67
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
67
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
68
68
 
69
69
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
70
70
 
71
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
71
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
72
72
 
73
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
73
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
74
74
 
75
75
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
76
76
 
@@ -91,12 +91,12 @@ var globOpts = {
91
91
  flipper: ['|', '/', '-', '\\'],
92
92
  pulsate: !1,
93
93
  template: '',
94
- variables: _objectSpread({
94
+ variables: _objectSpread(_objectSpread({
95
95
  tag: function tag(_ref) {
96
96
  var _tag = _ref.tag;
97
97
  return _tag && typeof _tag !== 'function' ? "".concat(_tag, "\n") : '';
98
98
  }
99
- }, _stringdColors["default"].raw, {
99
+ }, _stringdColors["default"].raw), {}, {
100
100
  'color:bar:empty': ':{color:close}',
101
101
  'color:bar:header': ':{color(green)}',
102
102
  'color:bar:filled': ':{bgcolor(green)}:{color(black)}',
@@ -105,11 +105,11 @@ var globOpts = {
105
105
  forceFirst: !1
106
106
  };
107
107
 
108
- var defaultOptions = _objectSpread({}, globOpts, {
108
+ var defaultOptions = _objectSpread(_objectSpread({}, globOpts), {}, {
109
109
  template: ':{tag}[:{bar}] :{flipper} :{label} :3{percentage}% [:{completed}/:{total}]'
110
110
  });
111
111
 
112
- var streamOpts = _objectSpread({}, globOpts, {
112
+ var streamOpts = _objectSpread(_objectSpread({}, globOpts), {}, {
113
113
  pulsate: false,
114
114
  progress: {
115
115
  time: 100,
@@ -119,7 +119,7 @@ var streamOpts = _objectSpread({}, globOpts, {
119
119
  pulsateLength: 15
120
120
  },
121
121
  template: [':{label}', ' |:{slot:bar}| [:3{slot:percentage}%] (:{slot:eta}) [:{speed}] [:{slot:size}/:{slot:size:total}]', ' [:{bar}] [:3{percentage}%] (:{eta}) [:{size}/:{size:total}]'],
122
- variables: _objectSpread({}, globOpts.variables, {
122
+ variables: _objectSpread(_objectSpread({}, globOpts.variables), {}, {
123
123
  eta: null,
124
124
  size: null,
125
125
  speed: null,
@@ -259,7 +259,7 @@ var ProgressGen = /*#__PURE__*/function (_EventEmitter) {
259
259
  return _super.apply(this, arguments);
260
260
  }
261
261
 
262
- return ProgressGen;
262
+ return _createClass(ProgressGen);
263
263
  }(_events["default"]);
264
264
 
265
265
  var ProgressBar = /*#__PURE__*/function () {
@@ -284,9 +284,9 @@ var ProgressBar = /*#__PURE__*/function () {
284
284
  opts = _ref5[1];
285
285
  }
286
286
 
287
- this.opts = _objectSpread({}, defaultOptions, {}, opts, {
288
- bar: _objectSpread({}, defaultOptions.bar, {}, opts.bar),
289
- variables: _objectSpread({}, defaultOptions.variables, {}, opts.variables)
287
+ this.opts = _objectSpread(_objectSpread(_objectSpread({}, defaultOptions), opts), {}, {
288
+ bar: _objectSpread(_objectSpread({}, defaultOptions.bar), opts.bar),
289
+ variables: _objectSpread(_objectSpread({}, defaultOptions.variables), opts.variables)
290
290
  });
291
291
  this.cores = {
292
292
  total: total,
@@ -571,20 +571,20 @@ var ProgressBar = /*#__PURE__*/function () {
571
571
  }() : forcedFirst : pulsateBar(this, this.cores.pulsateSlots, this.opts.bar.pulsateSkip, this.opts.bar.separator);
572
572
  var templateString = Array.isArray(this.opts.template) ? this.opts.template.join('\n') : this.opts.template;
573
573
  var average = this.average();
574
- return this.parseString(templateString, _objectSpread({
574
+ return this.parseString(templateString, _objectSpread(_objectSpread({
575
575
  bar: bars.join(":{color:bar:separator}".concat(this.opts.bar.separator, ":{color:close}:{bgcolor:close}")),
576
576
  'bar:complete': forcedFirst.join(''),
577
577
  label: this.label(),
578
578
  total: this.total(),
579
579
  flipper: flipper(flipper.count += 1, this.opts.flipper)
580
- }, average, {
580
+ }, average), {}, {
581
581
  percentage: average.percentage.toFixed(0)
582
582
  }, template));
583
583
  }
584
584
  }, {
585
585
  key: "parseString",
586
586
  value: function parseString(str, template) {
587
- var variables = _objectSpread({}, template = _objectSpread({}, this.opts.variables, {}, template));
587
+ var variables = _objectSpread({}, template = _objectSpread(_objectSpread({}, this.opts.variables), template));
588
588
 
589
589
  Object.entries(this.opts.variables).forEach(function (_ref18) {
590
590
  var _ref19 = _slicedToArray(_ref18, 2),
@@ -611,14 +611,16 @@ var ProgressBar = /*#__PURE__*/function () {
611
611
  var cleanWrite = function cleanWrite(arr, dontClean) {
612
612
  var addons = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
613
613
  var ending = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
614
+ var normie = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
614
615
 
615
616
  if (!dontClean) {
617
+ // check https://github.com/freeall/single-line-log/blob/515b3b99b699396c2ad5f937e4b490b6f9fbff0e/index.js#L1-L3
616
618
  self.cores.stdout.moveCursor(0, -addons);
617
619
  self.cores.stdout.cursorTo(0);
618
620
  self.cores.stdout.clearScreenDown();
619
621
  }
620
622
 
621
- self.cores.stdout.write("".concat(dontClean && ending ? '\n' : '').concat(self.parseString(_util.format.apply(void 0, _toConsumableArray(arr))).replace(self.opts.bar.colorize ? '' : /\x1b\[\d+m/g, '')));
623
+ (normie ? process.stdout : self.cores.stdout).write("".concat(dontClean && ending && addons ? '\n' : '').concat(self.parseString(_util.format.apply(void 0, _toConsumableArray(arr))).replace(self.opts.bar.colorize ? '' : /\x1b\[\d+m/g, '')));
622
624
  };
623
625
 
624
626
  var addonPack;
@@ -628,7 +630,7 @@ var ProgressBar = /*#__PURE__*/function () {
628
630
  content[_key - 1] = arguments[_key];
629
631
  }
630
632
 
631
- this.justLogged = type === 'bar' && content.length === 1 ? !!cleanWrite(content, this.justLogged, addons) : (addonPack = type.match(/^bar\+(\d+)/)) !== null ? !!cleanWrite(content, this.justLogged, this.hasBarredOnce ? addonPack[1] : addons) : type === 'end' ? !!cleanWrite(content, !this.opts.clean, addons, true) : !cleanWrite([type.startsWith(':') && "".concat(type.slice(1)) || type].concat(content, ['\n']), this.justLogged, addons);
633
+ this.justLogged = type === 'bar' && content.length === 1 ? !!cleanWrite(content, this.justLogged, addons) : (addonPack = type.match(/^bar\+(\d+)/)) !== null ? !!cleanWrite(content, this.justLogged, this.hasBarredOnce ? addonPack[1] : addons) : type === 'end' ? !!cleanWrite(content, !this.opts.clean, addons, true, true) : !cleanWrite([type.startsWith(':') && "".concat(type.slice(1)) || type].concat(content, ['\n']), this.justLogged, addons, false, true);
632
634
  if (this.justLogged && this.hasBarredOnce) this.draw(this.oldBar);
633
635
  return this;
634
636
  }
@@ -704,20 +706,6 @@ var ProgressBar = /*#__PURE__*/function () {
704
706
  * Find out the progressbar is appended to another
705
707
  */
706
708
 
707
- }, {
708
- key: "slotStreamify",
709
-
710
- /**
711
- * Prepare a raw generator for use
712
- * @param {(slots:Number, total?:Number) => String} actor The performing function
713
- * @returns {Generator} New ProgressBar Generator
714
- * @yields The through instance or a cache model of the ProgressBar
715
- */
716
- value: function* slotStreamify(actor, args) {
717
- for (var level = -1; (level += 1) <= (this.opts.progress.infinite ? Infinity : this.slots.length);) {
718
- args = yield !level ? this : ((0, _lodash.merge)(this.opts, args[1]), actor(Math.floor(level - 1), args[0], this.opts.progress.infinite));
719
- }
720
- }
721
709
  }, {
722
710
  key: "isChild",
723
711
  get: function get() {
@@ -748,6 +736,20 @@ var ProgressBar = /*#__PURE__*/function () {
748
736
  * @param {ProgressBar} bar The progressbar to be checked
749
737
  */
750
738
 
739
+ }, {
740
+ key: "slotStreamify",
741
+ value:
742
+ /**
743
+ * Prepare a raw generator for use
744
+ * @param {(slots:Number, total?:Number) => String} actor The performing function
745
+ * @returns {Generator} New ProgressBar Generator
746
+ * @yields The through instance or a cache model of the ProgressBar
747
+ */
748
+ function* slotStreamify(actor, args) {
749
+ for (var level = -1; (level += 1) <= (this.opts.progress.infinite ? Infinity : this.slots.length);) {
750
+ args = yield !level ? this : ((0, _lodash.merge)(this.opts, args[1]), actor(Math.floor(level - 1), args[0], this.opts.progress.infinite));
751
+ }
752
+ }
751
753
  }], [{
752
754
  key: "isBar",
753
755
  value: function isBar(bar) {
@@ -836,10 +838,10 @@ var ProgressBar = /*#__PURE__*/function () {
836
838
  opts = _ref21[1];
837
839
  }
838
840
 
839
- opts = _objectSpread({}, total === Infinity ? {
841
+ opts = _objectSpread(_objectSpread(_objectSpread({}, total === Infinity ? {
840
842
  pulsate: !0,
841
843
  template: ':{tag}[:{bar}] [:{flipper}] :{label} (:{slot:runtime}) :{slot:size}'
842
- } : {}, {}, opts, {}, slots === Infinity ? (slots = total, {
844
+ } : {}), opts), slots === Infinity ? (slots = total, {
843
845
  progress: {
844
846
  infinite: !0
845
847
  }
@@ -878,41 +880,69 @@ var ProgressBar = /*#__PURE__*/function () {
878
880
  }), bar.opts.progress.pulsateSkip || bar.opts.bar.pulsateSkip],
879
881
  pulsateSlots = _ref23[0],
880
882
  pulsateSkips = _ref23[1];
881
- var speed = (0, _speedometer["default"])(5000);
883
+
884
+ var _defaultUnit;
885
+
882
886
  var progressGen = new ProgressGen();
887
+
888
+ var buildBytesWith = function buildBytesWith(bytes) {
889
+ var byteOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
890
+ return function (props, data) {
891
+ return _xbytes["default"].createRelativeSizer(data && (data.args[0] || data.matched.unit) || _defaultUnit, {
892
+ iec: data && 'iec' in data.matched ? data.matched.iec === 'true' : byteOpts.iec || !1,
893
+ bits: data && 'bits' in data.matched ? data.matched.bits === 'true' : byteOpts.bits || !1,
894
+ fixed: data && 'fixed' in data.matched ? parseInt(data.matched.fixed, 10) : byteOpts.fixed || 2,
895
+ "short": data && 'short' in data.matched ? data.matched["short"] === 'true' : byteOpts["short"] || !0,
896
+ space: data && 'space' in data.matched ? data.matched.space === 'true' : byteOpts.space || !0,
897
+ sticky: data && 'sticky' in data.matched ? data.matched.sticky === 'true' : byteOpts.sticky || !1
898
+ })(typeof bytes === 'function' ? bytes(props) : bytes);
899
+ };
900
+ };
901
+
902
+ var buildSpeedWith = function buildSpeedWith(speed) {
903
+ return function (_, data) {
904
+ return "".concat(buildBytesWith(speed, {
905
+ iec: !1,
906
+ bits: !0,
907
+ fixed: 2,
908
+ "short": !0,
909
+ space: !1,
910
+ sticky: !1
911
+ })(_, data)).concat(data && data.matched.metric || 'ps');
912
+ };
913
+ };
914
+
915
+ var totalSpeed = (0, _speedometer["default"])(5000);
883
916
  var streamGenerator = bar.slotStreamify(function (slotIndex, total, infinite) {
884
917
  var max = !infinite ? Math.round(bar.slots[slotIndex].level / 100 * bar.total()) : Infinity;
885
918
  total = typeof total === 'function' ? total(bar) : total || max;
886
919
  if (!infinite && total > max) throw Error("<size> slot must not be greater than maximum possible size for the slot [".concat(max, "], consider using infinite slots"));
887
920
  var through = (0, _progressStream["default"])(_objectSpread({
888
921
  length: total
889
- }, bar.opts.progress)) // eslint-disable-next-line consistent-return
890
- .on('progress', function (progress) {
891
- var xpeed = speed(progress.delta);
892
- if (bar.isEnded) return through.emit('error', Error('The <bar> being used has been ended'));
922
+ }, bar.opts.progress)).on('progress', function (progress) {
923
+ var speed = totalSpeed(progress.delta);
924
+
925
+ if (bar.isEnded) {
926
+ through.emit('error', Error('The <bar> being used has been ended'));
927
+ return;
928
+ }
929
+
893
930
  (actor || function (_bar, args, template) {
894
931
  return _bar.value.apply(_bar, _toConsumableArray(args)).draw(template);
895
932
  })(bar, bar.opts.progress.infinite ? [progress.delta + bar.average().completed] : [slotIndex, progress.transferred], {
896
933
  eta: function eta() {
897
- return xprettyMs(1000 * bar.average().remaining / xpeed);
898
- },
899
- size: function size() {
900
- return (0, _xbytes["default"])(bar.average().completed, {
901
- "short": !0
902
- });
934
+ return xprettyMs(1000 * bar.average().remaining / speed);
903
935
  },
904
- speed: function speed(_, unit) {
905
- if (!(unit && _xbytes["default"].parseUnit(unit))) unit = 'Mb'; // default to Megabits
906
-
907
- return "".concat(_xbytes["default"].createRelativeSizer(unit)(xpeed, {
908
- "short": !0,
909
- space: !1
910
- }), "ps");
911
- },
912
- 'speed:raw': xpeed,
936
+ size: buildBytesWith(function () {
937
+ return bar.average().completed;
938
+ }),
939
+ speed: buildSpeedWith(speed),
940
+ 'speed:raw': speed,
941
+ 'slot:speed': buildSpeedWith(progress.speed),
942
+ 'slot:speed:raw': progress.speed,
913
943
  progress: progress,
914
944
  'eta:raw': function etaRaw() {
915
- return Math.round(bar.average().remaining / xpeed);
945
+ return Math.round(bar.average().remaining / speed);
916
946
  },
917
947
  'slot:bar': function slotBar() {
918
948
  return bar.opts.progress.pulsate ? pulsateBar(bar, pulsateSlots, pulsateSkips, bar.opts.bar.separator).join('') : function () {
@@ -930,21 +960,15 @@ var ProgressBar = /*#__PURE__*/function () {
930
960
  },
931
961
  'slot:eta': xprettyMs(1000 * progress.eta),
932
962
  'slot:eta:raw': progress.eta,
933
- 'slot:size': (0, _xbytes["default"])(progress.transferred, {
934
- "short": !0
935
- }),
963
+ 'slot:size': buildBytesWith(progress.transferred),
936
964
  'slot:size:raw': progress.transferred,
937
- 'size:total': function sizeTotal() {
938
- return (0, _xbytes["default"])(bar.total(), {
939
- "short": !0
940
- });
941
- },
965
+ 'size:total': buildBytesWith(function () {
966
+ return bar.total();
967
+ }),
942
968
  'slot:runtime': xprettyMs(1000 * progress.runtime),
943
969
  'slot:runtime:raw': progress.runtime,
944
970
  'slot:percentage': progress.percentage.toFixed(0),
945
- 'slot:size:total': (0, _xbytes["default"])(progress.length, {
946
- "short": !0
947
- }),
971
+ 'slot:size:total': buildBytesWith(progress.length),
948
972
  'slot:size:total:raw': progress.length
949
973
  });
950
974
  [through, progressGen].map(function (emitter) {
@@ -990,6 +1014,17 @@ var ProgressBar = /*#__PURE__*/function () {
990
1014
  return bar.print.apply(bar, arguments);
991
1015
  },
992
1016
 
1017
+ /**
1018
+ * Set the default unit
1019
+ * @param {xbytes.AllUnitStacks} unit Preferred unit representation
1020
+ * @returns {ProgressBar} The ProgressBar
1021
+ */
1022
+ defaultUnit: function defaultUnit(unit) {
1023
+ if (!_xbytes["default"].isUnit(unit)) throw new Error("Invalid ByteString unit: ".concat(unit));
1024
+ _defaultUnit = unit;
1025
+ return this;
1026
+ },
1027
+
993
1028
  /**
994
1029
  * The ProgressBar Instance
995
1030
  * @type {ProgressBar} The ProgresBar
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "xprogress",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "Dynamic, Flexible, extensible progressive CLI bar for the terminal built with NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
7
7
  "scripts": {
8
- "push": "git push github master && git push gitlab master",
9
8
  "build": "babel lib -d dist",
10
- "version": "npm run build",
11
- "postversion": "npm run push"
9
+ "version": "npm run build"
12
10
  },
13
11
  "engines": {
14
12
  "node": ">=6"
@@ -76,9 +74,9 @@
76
74
  "pretty-ms": "^5.1.0",
77
75
  "progress-stream": "^2.0.0",
78
76
  "speedometer": "^1.1.0",
79
- "stringd": "^2.0.0",
80
- "stringd-colors": "^1.8.0",
81
- "xbytes": "^1.6.0"
77
+ "stringd": "^2.1.0",
78
+ "stringd-colors": "^1.9.0",
79
+ "xbytes": "^1.6.1"
82
80
  },
83
81
  "homepage": "https://github.com/miraclx/xprogress#readme",
84
82
  "directories": {
@@ -531,6 +531,8 @@ namespace ProgressBar {
531
531
  size: ByteString;
532
532
  speed: string;
533
533
  ['speed:raw']: string;
534
+ ['slot:speed']: string;
535
+ ['slot:speed:raw']: string;
534
536
  progress: ProgressStreamSlice;
535
537
  ['eta:raw']: number;
536
538
  ['slot:bar']: any;