Merge branch 'feat/hdd-calculator' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 20:32:04 +01:00
commit 9a38169b22
6 files changed
+84 -3

No files matched your search

+4 -3
View File
@@ -3466,7 +3466,7 @@ packages:
/@types/lodash-es@4.17.10:
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
dependencies:
'@types/lodash': 4.14.200
'@types/lodash': 4.14.192
dev: false
/@types/lodash.defaultsdeep@4.6.9:
@@ -3489,7 +3489,6 @@ packages:
/@types/lodash@4.14.192:
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
dev: true
/@types/lodash@4.14.200:
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
@@ -4545,7 +4544,7 @@ packages:
/@vueuse/shared@10.0.0(vue@3.3.4):
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
dependencies:
vue-demi: 0.14.5(vue@3.3.4)
vue-demi: 0.14.10(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
@@ -7848,6 +7847,7 @@ packages:
/jsesc@2.5.2:
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
engines: {node: '>=4'}
hasBin: true
/jsesc@3.0.2:
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
@@ -11652,6 +11652,7 @@ packages:
/yamljs@0.3.0:
resolution: {integrity: sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==}
hasBin: true
dependencies:
argparse: 1.0.10
glob: 7.2.3
@@ -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);
});
});
@@ -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;
};
@@ -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>
+14
View File
@@ -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
View File
@@ -35,6 +35,7 @@ import { tool as iso3166Searcher } from './iso-3166-searcher';
import { tool as curlConverter } from './curl-converter';
import { tool as durationCalculator } from './duration-calculator';
import { tool as folderStructureDiagram } from './folder-structure-diagram';
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';
@@ -158,6 +159,7 @@ export const toolsByCategory: ToolCategory[] = [
jsonToXml,
markdownToHtml,
currencyConverter,
hddCalculator,
],
},
{