format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -45,7 +45,7 @@ exports = module.exports = ProgressBar;
function ProgressBar(fmt, options) {
this.stream = options.stream || process.stderr;
if (typeof(options) == 'number') {
if (typeof options == 'number') {
var total = options;
options = {};
options.total = total;
@ -59,13 +59,14 @@ function ProgressBar(fmt, options) {
this.curr = options.curr || 0;
this.total = options.total;
this.width = options.width || this.total;
this.clear = options.clear
this.clear = options.clear;
this.chars = {
complete : options.complete || '=',
incomplete : options.incomplete || '-',
head : options.head || (options.complete || '=')
complete: options.complete || '=',
incomplete: options.incomplete || '-',
head: options.head || options.complete || '=',
};
this.renderThrottle = options.renderThrottle !== 0 ? (options.renderThrottle || 16) : 0;
this.renderThrottle =
options.renderThrottle !== 0 ? options.renderThrottle || 16 : 0;
this.lastRender = -Infinity;
this.callback = options.callback || function () {};
this.tokens = {};
@ -80,18 +81,17 @@ function ProgressBar(fmt, options) {
* @api public
*/
ProgressBar.prototype.tick = function(len, tokens){
if (len !== 0)
len = len || 1;
ProgressBar.prototype.tick = function (len, tokens) {
if (len !== 0) len = len || 1;
// swap tokens
if ('object' == typeof len) tokens = len, len = 1;
if ('object' == typeof len) (tokens = len), (len = 1);
if (tokens) this.tokens = tokens;
// start time for eta
if (0 == this.curr) this.start = new Date;
if (0 == this.curr) this.start = new Date();
this.curr += len
this.curr += len;
// try to render
this.render();
@ -122,7 +122,7 @@ ProgressBar.prototype.render = function (tokens, force) {
var now = Date.now();
var delta = now - this.lastRender;
if (!force && (delta < this.renderThrottle)) {
if (!force && delta < this.renderThrottle) {
return;
} else {
this.lastRender = now;
@ -133,8 +133,8 @@ ProgressBar.prototype.render = function (tokens, force) {
var percent = Math.floor(ratio * 100);
var incomplete, complete, completeLength;
var elapsed = new Date - this.start;
var eta = (percent == 100) ? 0 : elapsed * (this.total / this.curr - 1);
var elapsed = new Date() - this.start;
var eta = percent == 100 ? 0 : elapsed * (this.total / this.curr - 1);
var rate = this.curr / (elapsed / 1000);
/* populate the bar template with percentages and timestamps */
@ -142,14 +142,19 @@ ProgressBar.prototype.render = function (tokens, force) {
.replace(':current', this.curr)
.replace(':total', this.total)
.replace(':elapsed', isNaN(elapsed) ? '0.0' : (elapsed / 1000).toFixed(1))
.replace(':eta', (isNaN(eta) || !isFinite(eta)) ? '0.0' : (eta / 1000)
.toFixed(1))
.replace(
':eta',
isNaN(eta) || !isFinite(eta) ? '0.0' : (eta / 1000).toFixed(1)
)
.replace(':percent', percent.toFixed(0) + '%')
.replace(':rate', Math.round(rate));
/* compute the available space (non-zero) for the bar */
var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length);
if(availableSpace && process.platform === 'win32'){
var availableSpace = Math.max(
0,
this.stream.columns - str.replace(':bar', '').length
);
if (availableSpace && process.platform === 'win32') {
availableSpace = availableSpace - 1;
}
@ -158,17 +163,19 @@ ProgressBar.prototype.render = function (tokens, force) {
/* TODO: the following assumes the user has one ':bar' token */
completeLength = Math.round(width * ratio);
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete);
incomplete = Array(Math.max(0, width - completeLength + 1)).join(
this.chars.incomplete
);
/* add head to the complete string */
if(completeLength > 0)
complete = complete.slice(0, -1) + this.chars.head;
if (completeLength > 0) complete = complete.slice(0, -1) + this.chars.head;
/* fill in the actual progress bar */
str = str.replace(':bar', complete + incomplete);
/* replace the extra tokens */
if (this.tokens) for (var key in this.tokens) str = str.replace(':' + key, this.tokens[key]);
if (this.tokens)
for (var key in this.tokens) str = str.replace(':' + key, this.tokens[key]);
if (this.lastDraw !== str) {
this.stream.cursorTo(0);