Making more fields us the LiveQuery. Migrated format bytes function. General clean up.
This commit is contained in:
@@ -137,6 +137,22 @@ export let iso_datetime_formatter = function iso_datetime_formatter(
|
||||
}
|
||||
|
||||
|
||||
function format_bytes(
|
||||
bytes: number,
|
||||
decimals: number = 2
|
||||
) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
|
||||
/* This utility function will add commas to a number. */
|
||||
function number_w_commas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
@@ -993,6 +1009,7 @@ function return_obj_type_path({obj_type=null, obj_type_prop_name=null}) {
|
||||
|
||||
export let ae_util = {
|
||||
iso_datetime_formatter: iso_datetime_formatter,
|
||||
format_bytes: format_bytes,
|
||||
number_w_commas: number_w_commas,
|
||||
extract_prefixed_form_data: extract_prefixed_form_data,
|
||||
process_data_string: process_data_string,
|
||||
|
||||
Reference in New Issue
Block a user