Skip to content

Commit

Permalink
Merge branch 'develop' into feature-1654-measurement-types
Browse files Browse the repository at this point in the history
  • Loading branch information
robyngit committed Sep 9, 2024
2 parents a76b32e + 0ebb642 commit d37cd3b
Show file tree
Hide file tree
Showing 15 changed files with 3,625 additions and 3,843 deletions.
1,412 changes: 704 additions & 708 deletions src/js/collections/DataPackage.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/js/common/Utilities.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use strict";

define([], () => {
const KIBIBYTE = 1024;
const MEBIBYTE = KIBIBYTE * 1024;
const GIBIBYTE = MEBIBYTE * 1024;
const TEBIBYTE = GIBIBYTE * 1024;

/**
* @namespace Utilities
* @description A generic utility object that contains functions used throughout MetacatUI to perform useful functions,
Expand Down Expand Up @@ -214,6 +219,35 @@ define([], () => {

return json;
},

/**
* Convert number of bytes into human readable format
* @param integer bytes Number of bytes to convert
* @param integer precision Number of digits after the decimal separator
* @param bytes
* @param precision
* @returns string
*/
bytesToSize(bytes, precision = 0) {
if (typeof bytes === "undefined") return `0 B`;

if (bytes >= 0 && bytes < KIBIBYTE) {
return `${bytes} B`;
}
if (bytes >= KIBIBYTE && bytes < MEBIBYTE) {
return `${(bytes / KIBIBYTE).toFixed(precision)} KiB`;
}
if (bytes >= MEBIBYTE && bytes < GIBIBYTE) {
return `${(bytes / MEBIBYTE).toFixed(precision)} MiB`;
}
if (bytes >= GIBIBYTE && bytes < TEBIBYTE) {
return `${(bytes / GIBIBYTE).toFixed(precision)} GiB`;
}
if (bytes >= TEBIBYTE) {
return `${(bytes / TEBIBYTE).toFixed(precision)} TiB`;
}
return `${bytes} B`;
},
};

return Utilities;
Expand Down
1,445 changes: 701 additions & 744 deletions src/js/models/DataONEObject.js

Large diffs are not rendered by default.

Loading

0 comments on commit d37cd3b

Please sign in to comment.