UNPKG

tsc-path-fix

Version:

Zero-runtime TypeScript path resolver - converts aliases to relative paths at compile time. Fast, lightweight, with native watch mode.

85 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressBar = void 0; class ProgressBar { constructor(total, options = {}) { this.total = total; this.options = options; this.bar = ''; this.timer = null; this.startTime = Date.now(); this.lastRenderTime = 0; this.renderThrottleMs = 50; this.spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; this.spinnerIdx = 0; this.options = Object.assign({ showPercent: true, showCount: true, showElapsed: true, showSpinner: true, width: 25, barChar: '█', emptyChar: '░' }, options); } start() { process.stdout.write('\n'); this.update(0); if (this.options.showSpinner) { this.timer = setInterval(() => { this.spinnerIdx = (this.spinnerIdx + 1) % this.spinner.length; this.render(); }, 100); } } update(current) { const now = Date.now(); if (now - this.lastRenderTime < this.renderThrottleMs && current < this.total) { return; } this.lastRenderTime = now; const percent = Math.min(Math.floor((current / this.total) * 100), 100); const width = this.options.width; const completeLen = Math.round((percent / 100) * width); const emptyLen = width - completeLen; let output = ''; if (this.options.showSpinner) { output += `${this.spinner[this.spinnerIdx]} `; } output += '[' + this.options.barChar.repeat(completeLen) + this.options.emptyChar.repeat(emptyLen) + '] '; if (this.options.showPercent) { output += `${percent.toString().padStart(3)}% `; } if (this.options.showCount) { output += `(${current}/${this.total}) `; } if (this.options.showElapsed) { const elapsedSecs = Math.round((now - this.startTime) / 1000); output += `${formatTime(elapsedSecs)}`; } this.bar = output; this.render(); } render() { process.stdout.write(`\r${this.bar}`); } complete(message = 'Completed') { if (this.timer) { clearInterval(this.timer); this.timer = null; } this.update(this.total); const elapsedSecs = Math.round((Date.now() - this.startTime) / 1000); process.stdout.write(`\r${message} in ${formatTime(elapsedSecs)}\n\n`); } } exports.ProgressBar = ProgressBar; function formatTime(seconds) { if (seconds < 60) { return `${seconds}s`; } const mins = Math.floor(seconds / 60); const secs = seconds % 60; if (mins < 60) { return `${mins}m ${secs}s`; } const hours = Math.floor(mins / 60); const remainingMins = mins % 60; return `${hours}h ${remainingMins}m ${secs}s`; } //# sourceMappingURL=progress-bar.js.map