Skip to content

Commit

Permalink
Merge pull request #2496 from NCEAS/enhancement-2483-2484-FH-2
Browse files Browse the repository at this point in the history
File Hierarchy clean up
  • Loading branch information
robyngit authored Sep 9, 2024
2 parents 53a4059 + 01e7d2f commit b057aab
Show file tree
Hide file tree
Showing 13 changed files with 3,121 additions and 3,291 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 @@
define([], () => {
"use strict";

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 @@ -156,6 +161,35 @@ define([], () => {
}
return 0; // No decimal places
},

/**
* 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 b057aab

Please sign in to comment.