2018-02-19 22:56:39 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
Vue.filter('bytes', (v, digits = 0) => {
|
2018-11-03 02:38:00 +00:00
|
|
|
if (v == null) return '?';
|
2019-07-05 12:18:49 +00:00
|
|
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
2018-08-23 23:56:57 +00:00
|
|
|
if (v == 0) return '0';
|
|
|
|
const isMinus = v < 0;
|
|
|
|
if (isMinus) v = -v;
|
2018-02-19 22:56:39 +00:00
|
|
|
const i = Math.floor(Math.log(v) / Math.log(1024));
|
2018-08-23 23:56:57 +00:00
|
|
|
return (isMinus ? '-' : '') + (v / Math.pow(1024, i)).toFixed(digits).replace(/\.0+$/, '') + sizes[i];
|
2018-02-19 22:56:39 +00:00
|
|
|
});
|