import React from 'react'; const format = { eta: (eta) => { if (eta === 'Infinity') { return '∞'; } else if (eta.years > 0) { return ( {eta.years}yr {eta.weeks}wk ); } else if (eta.weeks > 0) { return ( {eta.weeks}wk {eta.days}d ); } else if (eta.days > 0) { return ( {eta.days}d {eta.hours}hr ); } else if (eta.hours > 0) { return ( {eta.hours}hr {eta.minutes}m ); } else if (eta.minutes > 0) { return ( {eta.minutes}m {eta.seconds}s ); } else { return ( {eta.seconds}s ); } }, data: (bytes, extraUnits, precision = 2) => { let kilobyte = 1024, megabyte = kilobyte * 1024, gigabyte = megabyte * 1024, terabyte = gigabyte * 1024, value = 0, unit = ''; if ((bytes >= 0) && (bytes < kilobyte)) { value = bytes; unit = 'B'; } else if ((bytes >= kilobyte) && (bytes < megabyte)) { value = (bytes / kilobyte); unit = 'KB'; } else if ((bytes >= megabyte) && (bytes < gigabyte)) { value = (bytes / megabyte); unit = 'MB'; } else if ((bytes >= gigabyte) && (bytes < terabyte)) { value = (bytes / gigabyte); unit = 'GB'; } else if (bytes >= terabyte) { value = (bytes / terabyte); unit = 'TB'; } else { value = bytes; unit = 'B'; } value = Number(value); if (!!value && value < 10) { value = value.toFixed(precision); } else if (!!value && value > 10 && value < 100) { value = value.toFixed(precision - 1); } else if (!!value && value > 100) { value = Math.floor(value); } if (extraUnits) { unit += extraUnits; } return { value, unit }; }, ratio: (ratio) => { ratio = ratio / 1000; let precision = 1; if (ratio < 10) { precision = 2; } else if (ratio < 100) { precision = 0; } return ratio.toFixed(precision); } }; export default format;