import React from 'react'; const format = { eta: function(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: function(bytes, extraUnits, precision = 2) { let kilobyte = 1024, megabyte = kilobyte * 1024, gigabyte = megabyte * 1024, terabyte = gigabyte * 1024, value = '', unit = ''; if ((bytes >= 0) && (bytes < kilobyte)) { value = bytes; unit = 'B'; } else if ((bytes >= kilobyte) && (bytes < megabyte)) { value = (bytes / kilobyte).toFixed(precision); unit = 'KB'; } else if ((bytes >= megabyte) && (bytes < gigabyte)) { value = (bytes / megabyte).toFixed(precision); unit = 'MB'; } else if ((bytes >= gigabyte) && (bytes < terabyte)) { value = (bytes / gigabyte).toFixed(precision); unit = 'GB'; } else if (bytes >= terabyte) { value = (bytes / terabyte).toFixed(precision); unit = 'TB'; } else { value = bytes; unit = 'B'; } if (extraUnits) { unit += extraUnits; } return { value, unit }; }, ratio: function(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;