Skip to content

Commit 9a38169

Browse files
committed
Merge branch 'feat/hdd-calculator' into chore/all-my-stuffs
# Conflicts: # components.d.ts # src/tools/index.ts
2 parents fe41995 + e46a5ec commit 9a38169

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

pnpm-lock.yaml

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { getRealSize } from './hdd-calculator.service';
3+
4+
describe('hdd-calculator', () => {
5+
it('Convert Claimed Size to Real Size', async () => {
6+
expect(getRealSize(10, 'gb', 'tb')).to.equal(0.009094947017729282);
7+
expect(getRealSize(10, 'pb', 'mb')).to.equal(9536743164.0625);
8+
expect(getRealSize(100, 'tb', 'gb')).to.equal(93132.25746154785);
9+
expect(getRealSize(1, 'pb', 'gb')).to.equal(931322.5746154785);
10+
expect(getRealSize(1000, 'tb', 'gb')).to.equal(931322.5746154785);
11+
});
12+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const unitsConversion = {
2+
kb: { dec: 1_000, bin: 1024 },
3+
mb: { dec: 1_000_000, bin: 1024 * 1024 },
4+
gb: { dec: 1_000_000_000, bin: 1024 * 1024 * 1024 },
5+
tb: { dec: 1_000_000_000_000, bin: 1024 * 1024 * 1024 * 1024 },
6+
pb: { dec: 1_000_000_000_000_000, bin: 1024 * 1024 * 1024 * 1024 * 1024 },
7+
};
8+
9+
export type Units = 'kb' | 'mb' | 'gb' | 'tb' | 'pb';
10+
export function getRealSize(claimedCapacity: number, claimedUnit: Units, toUnit: Units) {
11+
const fromUnit = unitsConversion[claimedUnit as Units];
12+
const toUnitBin = unitsConversion[toUnit as Units].bin;
13+
return claimedCapacity * fromUnit.dec / toUnitBin;
14+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script setup lang="ts">
2+
import InputCopyable from '../../components/InputCopyable.vue';
3+
import type { Units } from './hdd-calculator.service';
4+
import { getRealSize } from './hdd-calculator.service';
5+
6+
const units = [
7+
{ value: 'kb', label: 'KB' },
8+
{ value: 'mb', label: 'MB' },
9+
{ value: 'gb', label: 'GB' },
10+
{ value: 'tb', label: 'TB' },
11+
{ value: 'pb', label: 'PB' },
12+
];
13+
14+
const claimedCapacity = ref(1);
15+
const claimedUnit = ref('tb');
16+
</script>
17+
18+
<template>
19+
<div>
20+
<n-form-item label="Claimed Capacity:">
21+
<n-input-number v-model:value="claimedCapacity" :min="1" />
22+
</n-form-item>
23+
<c-select
24+
v-model:value="claimedUnit"
25+
label="Unit:"
26+
:options="units"
27+
/>
28+
29+
<n-divider />
30+
31+
<InputCopyable
32+
v-for="({ value, label }) in units"
33+
:key="value"
34+
:label="`Capacity in ${label}`"
35+
:value="getRealSize(claimedCapacity, claimedUnit as Units, value as Units).toFixed(5)"
36+
/>
37+
</div>
38+
</template>

src/tools/hdd-calculator/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { DeviceDesktop } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'HDD calculator',
6+
path: '/hdd-calculator',
7+
description: 'Compute real storage space (binary) from HDD Capacity (decimal)',
8+
keywords: ['hdd', 'calculator', 'size', 'conversion', 'binary', 'decimal',
9+
'gb', 'mb', 'tb',
10+
'gigabyte', 'gibibyte', 'megabyte', 'mebibyte', 'terabyte', 'tebibyte'],
11+
component: () => import('./hdd-calculator.vue'),
12+
icon: DeviceDesktop,
13+
createdAt: new Date('2024-04-07'),
14+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { tool as iso3166Searcher } from './iso-3166-searcher';
3535
import { tool as curlConverter } from './curl-converter';
3636
import { tool as durationCalculator } from './duration-calculator';
3737
import { tool as folderStructureDiagram } from './folder-structure-diagram';
38+
import { tool as hddCalculator } from './hdd-calculator';
3839
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
3940
import { tool as numeronymGenerator } from './numeronym-generator';
4041
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -158,6 +159,7 @@ export const toolsByCategory: ToolCategory[] = [
158159
jsonToXml,
159160
markdownToHtml,
160161
currencyConverter,
162+
hddCalculator,
161163
],
162164
},
163165
{

0 commit comments

Comments
 (0)