summaryrefslogtreecommitdiffstats
path: root/module/web/app/scripts/helpers/formatSize.js
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/app/scripts/helpers/formatSize.js')
-rw-r--r--module/web/app/scripts/helpers/formatSize.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/module/web/app/scripts/helpers/formatSize.js b/module/web/app/scripts/helpers/formatSize.js
new file mode 100644
index 000000000..a50588bc6
--- /dev/null
+++ b/module/web/app/scripts/helpers/formatSize.js
@@ -0,0 +1,13 @@
+// Format bytes in human readable format
+define('helpers/formatSize', ['handlebars'], function(Handlebars) {
+ var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
+ function formatSize(bytes, options) {
+ if (!bytes || bytes === 0) return '0 B';
+ var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+ // round to two digits
+ return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
+ }
+
+ Handlebars.registerHelper('formatSize', formatSize);
+ return formatSize;
+}); \ No newline at end of file