Commit 02a40e55 authored by Ad Schellevis's avatar Ad Schellevis

(ui) add byteFormat to base javascript file

parent f40a9f73
...@@ -29,6 +29,20 @@ ...@@ -29,6 +29,20 @@
* User interface shared components, requires opnsense.js for supporting functions. * User interface shared components, requires opnsense.js for supporting functions.
*/ */
/**
* format bytes
* @param bytes number of bytes to format
* @param decimals decimal places
* @return string
*/
function byteFormat(bytes, decimals=0)
{
var kb = 1024;
var ndx = Math.floor( Math.log(bytes) / Math.log(kb) );
var fileSizeTypes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
return (bytes / Math.pow(kb, ndx)).toFixed(decimals) + ' ' + fileSizeTypes[ndx];
}
/** /**
* save form to server * save form to server
* @param url endpoint url * @param url endpoint url
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment