@trap_stevo/terminal-plus
Version:
Transform your CLI into a visually striking, feature-rich command layer. Blend animated gradients, stylish badges, dynamic progress bars, sleek tables, and precise formatting utilities — all turning terminal output into a powerful visual experience.
73 lines (72 loc) • 1.71 kB
JavaScript
;
class UniversalFormatUtilityManager {
static convertSeconds(seconds) {
if (seconds === 0) {
return "0 s";
}
const units = [{
name: "y",
seconds: 60 * 60 * 24 * 365
}, {
name: "mo",
seconds: 60 * 60 * 24 * 30
}, {
name: "w",
seconds: 60 * 60 * 24 * 7
}, {
name: "d",
seconds: 60 * 60 * 24
}, {
name: "h",
seconds: 60 * 60
}, {
name: "m",
seconds: 60
}, {
name: "s",
seconds: 1
}];
let remainingSeconds = seconds;
let result = "";
for (const unit of units) {
const count = Math.floor(remainingSeconds / unit.seconds);
if (count > 0) {
result += `${count}${unit.name}`;
remainingSeconds %= unit.seconds;
}
}
return result.trim();
}
static getFormattedSize(size, dynamicUnits = true) {
if (!dynamicUnits) {
return `${size.toFixed(1)} B`;
}
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
}
static getUnitData(size, dynamicUnits = true) {
if (!dynamicUnits) {
return {
current: size.toFixed(1),
unit: "B"
};
}
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return {
current: size.toFixed(2),
unit: units[unitIndex]
};
}
}
;
module.exports = UniversalFormatUtilityManager;