file-size.js 404 B

123456789101112131415
  1. export default function(bytes) {
  2. if (bytes > 1024 * 1024 * 1024) {
  3. return roundSize(bytes / (1024 * 1024 * 1024)) + " GB"
  4. } else if (bytes > 1024 * 1024) {
  5. return roundSize(bytes / (1024 * 1024)) + " MB"
  6. } else if (bytes > 1024) {
  7. return roundSize(bytes / 1024) + " KB"
  8. } else {
  9. return roundSize(bytes) + " B"
  10. }
  11. }
  12. export function roundSize(value) {
  13. return value.toFixed(1)
  14. }