-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
When passing a template function to BarItem, users usually do some really complicated formatting, it would be handy if the value and total could be passed as numbers.
bar.add(new BarItem(progress, {
options: Object.assign(presets.shades, {
width: 15,
}),
template: ({bar, value, total, etaHumanReadable}) => {
const valueNumber = parseInt(value);
const totalNumber = parseInt(total);
const name = (progress.getPayload() as any).name as string;
const isFinished = valueNumber >= totalNumber;
const eta = isFinished ? '' : ` | ETA: ${etaHumanReadable}`;
const bytesOptions = {
// Avoid jumping cursors around numbers like 1.9MB and 2MB.
minimumFractionDigits: valueNumber > 1024 * 1024 ? 1 : 0,
// Keep numbers compact.
maximumFractionDigits: 1,
space: false,
};
value = prettyBytes(valueNumber, bytesOptions);
total = prettyBytes(totalNumber, bytesOptions);
const percent = isFinished ? total : `${value}/${total}`;
return `${bar} | ${name} | ${percent}${eta}`;
},
}));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels