Skip to content

Commit

Permalink
feat(new tool): HDD Size Calculator
Browse files Browse the repository at this point in the history
Fix #974
  • Loading branch information
sharevb committed Apr 28, 2024
1 parent 9eac9cb commit 7716f61
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/tools/hdd-calculator/hdd-calculator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import InputCopyable from '../../components/InputCopyable.vue';
const units = [
{ value: 'kb', label: 'KB' },
{ value: 'mb', label: 'MB' },
{ value: 'tb', label: 'TB' },
];
const claimedCapacity = ref(1);
const claimedUnit = ref('tb');
const unitsConversion = {
'kb': { dec: 1000, bin: 1024 },
'mb': { dec: 1000000, bin: 1024 * 1024 },
'tb': { dec: 1000000000, bin: 1024 * 1024 * 1024 },
}
type Units = 'kb' | 'mb' | 'tb';
const getRealSize = (toUnit: Units) {
const fromUnitDec = unitsConversion[claimedUnit.value as Units].dec;
const toUnitBin = unitsConversion[toUnit as Units].bin;
return claimedCapacity.value / fromUnitDec * toUnitBin;
}
</script>

<template>
<div>
<n-form-item label="Claimed Capacity:">
<n-input-number v-model:value="claimedCapacity" :min="1" />
</n-form-item>
<c-select
v-model:value="claimedUnit"
label="Unit:"
:options="units"
/>

<n-divider />

<InputCopyable
v-for="({ value, label }) in units"
:label="label"
:value="getRealSize(value as Units).toFixed(5)"
/>
</div>
</template>

<style lang="less" scoped>
</style>
14 changes: 14 additions & 0 deletions src/tools/hdd-calculator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DeviceDesktop } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'HDD calculator',
path: '/hdd-calculator',
description: 'Compute real storage space (binary) from HDD Capacity (decimal)',
keywords: ['hdd', 'calculator', 'size', 'conversion', 'binary', 'decimal',
'gb', 'mb', 'tb',
'gigabyte', 'gibibyte', 'megabyte', 'mebibyte', 'terabyte', 'tebibyte'],
component: () => import('./hdd-calculator.vue'),
icon: DeviceDesktop,
createdAt: new Date('2024-04-07'),
});
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';

import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as hddCalculator } from './hdd-calculator';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
Expand Down Expand Up @@ -107,6 +108,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
hddCalculator,
],
},
{
Expand Down

0 comments on commit 7716f61

Please sign in to comment.