mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 16:14:40 +00:00
(ui) add byteFormat to base javascript file
This commit is contained in:
parent
f40a9f73c6
commit
02a40e55f5
@ -29,6 +29,20 @@
|
||||
* 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
|
||||
* @param url endpoint url
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user