-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #974
- Loading branch information
Showing
6 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { getRealSize } from './hdd-calculator.service'; | ||
|
||
describe('hdd-calculator', () => { | ||
it('Convert Claimed Size to Real Size', async () => { | ||
expect(getRealSize(10, 'gb', 'tb')).to.equal(0.009094947017729282); | ||
expect(getRealSize(10, 'pb', 'mb')).to.equal(9536743164.0625); | ||
expect(getRealSize(100, 'tb', 'gb')).to.equal(93132.25746154785); | ||
expect(getRealSize(1, 'pb', 'gb')).to.equal(931322.5746154785); | ||
expect(getRealSize(1000, 'tb', 'gb')).to.equal(931322.5746154785); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const unitsConversion = { | ||
kb: { dec: 1_000, bin: 1024 }, | ||
mb: { dec: 1_000_000, bin: 1024 * 1024 }, | ||
gb: { dec: 1_000_000_000, bin: 1024 * 1024 * 1024 }, | ||
tb: { dec: 1_000_000_000_000, bin: 1024 * 1024 * 1024 * 1024 }, | ||
pb: { dec: 1_000_000_000_000_000, bin: 1024 * 1024 * 1024 * 1024 * 1024 }, | ||
}; | ||
|
||
export type Units = 'kb' | 'mb' | 'gb' | 'tb' | 'pb'; | ||
export function getRealSize(claimedCapacity: number, claimedUnit: Units, toUnit: Units) { | ||
const fromUnit = unitsConversion[claimedUnit as Units]; | ||
const toUnitBin = unitsConversion[toUnit as Units].bin; | ||
return claimedCapacity * fromUnit.dec / toUnitBin; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script setup lang="ts"> | ||
import InputCopyable from '../../components/InputCopyable.vue'; | ||
import type { Units } from './hdd-calculator.service'; | ||
import { getRealSize } from './hdd-calculator.service'; | ||
const units = [ | ||
{ value: 'kb', label: 'KB' }, | ||
{ value: 'mb', label: 'MB' }, | ||
{ value: 'gb', label: 'GB' }, | ||
{ value: 'tb', label: 'TB' }, | ||
{ value: 'pb', label: 'PB' }, | ||
]; | ||
const claimedCapacity = ref(1); | ||
const claimedUnit = ref('tb'); | ||
</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" | ||
:key="value" | ||
:label="`Capacity in ${label}`" | ||
:value="getRealSize(claimedCapacity, claimedUnit as Units, value as Units).toFixed(5)" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters