Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

uploadProgress.ts

6 lines380 Bytes

1export function wholeUploadPercent(progress: number): number {
2 const bounded = Math.max(0, Math.min(1, Number.isFinite(progress) ? progress : 0));
3 const nearestPercent = Math.round(bounded * 100);
4 // `bounded * 100` undercounts exact ratios (0.57 * 100 = 56.99…), so compare in ratio space.
5 return bounded < nearestPercent / 100 ? nearestPercent - 1 : nearestPercent;
6}