Skip to content

Commit d2554a7

Browse files
committed
use built in converter
1 parent ea6b3d0 commit d2554a7

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

src/tools/raid-calculator/raid-calculator.vue

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { isNotThrowing } from '@/utils/boolean';
2+
import { formatBytes, UNIT_BASE } from '@/utils/convert';
33
import { raidCalculations } from './raid-calculator.service';
44
55
const diskTotal = ref(2);
@@ -17,7 +17,7 @@ const calculatedCapacity = computed(() => {
1717
return '';
1818
}
1919
20-
return formatBytes(raidCalculations[raidType.value].capacity(diskTotal.value, diskSize.value, diskUnit.value));
20+
return formatBytes(raidCalculations[raidType.value].capacity(diskTotal.value, diskSize.value, diskUnit.value), 2, UNIT_BASE.BASE_10);
2121
2222
});
2323
@@ -36,19 +36,6 @@ function validateSetup(){
3636
// validate the selected RAID type against parameters
3737
return raidCalculations[raidType.value].validate(diskTotal.value, diskSize.value);
3838
}
39-
40-
// similar to the utility function but uses base 10 instead of base 2
41-
function formatBytes(bytes: number, decimals = 2) {
42-
if (bytes === 0) {
43-
return '0 Bytes';
44-
}
45-
46-
const k = Math.pow(10, 3);
47-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
48-
const i = Math.floor(Math.log(bytes) / Math.log(k));
49-
50-
return `${Number.parseFloat((bytes / k ** i).toFixed(decimals))} ${sizes[i]}`;
51-
}
5239
</script>
5340

5441
<template>

0 commit comments

Comments
 (0)