Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/pup/plugins/web-interface/static/js/helpers.js>formatBytes

Universal process manager built in Deno
Go to Latest
function formatBytes
import { formatBytes } from "https://deno.land/x/pup@1.0.0-rc.4/plugins/web-interface/static/js/helpers.js";

Converts the given bytes into a string with a unit. The units used are Bytes, KB, MB, GB and TB. The conversion is made to the smallest unit for which the value is greater than or equal to 1.

Examples

// returns "975 KB" formatBytes(1000000);

// returns "0 Bytes" formatBytes(0);

// returns "4.67 GB" formatBytes(5000000000);

Parameters

bytes
  • The number of bytes to convert.
optional
printUnit = [UNSUPPORTED]
  • Whether or not to include the unit in the returned string.
preferredUnit
  • Preferred unit for the output ('Bytes', 'KB', 'MB', 'GB', 'TB').