Making more fields us the LiveQuery. Migrated format bytes function. General clean up.

This commit is contained in:
Scott Idem
2024-06-27 10:57:19 -04:00
parent 20e1c46461
commit 8c8748b571
5 changed files with 176 additions and 64 deletions

View File

@@ -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,