file-size.js 403 B

1234567891011
  1. export default function(bytes) {
  2. if (bytes > 1024 * 1024 * 1024) {
  3. return (Math.round(bytes * 100 / (1024 * 1024 * 1024)) / 100) + ' GB';
  4. } else if (bytes > 1024 * 1024) {
  5. return (Math.round(bytes * 100 / (1024 * 1024)) / 100) + ' MB';
  6. } else if (bytes > 1024) {
  7. return (Math.round(bytes * 100 / 1024) / 100) + ' KB';
  8. } else {
  9. return (Math.round(bytes * 100) / 100) + ' B';
  10. }
  11. }