Compare commits

..
Author SHA1 Message Date
ShareVB e97d97896a fix: code style 2024-12-15 13:58:21 +01:00
ShareVB 50ad384e0f Merge remote-tracking branch 'origin/main' into feat/hdd-calculator 2024-12-15 13:48:29 +01:00
ShareVB ae4baa358b fix: better description and use of units 2024-12-15 13:47:01 +01:00
sharevb e46a5ec4d3 feat(new tool): HDD Size Calculator
Fix #974
2024-05-15 22:41:47 +02:00
12 changed files with 8539 additions and 6833 deletions

No files matched your search

+3 -3
View File
@@ -37,7 +37,6 @@ declare module '@vue/runtime-core' {
'CFileUpload.demo': typeof import('./src/ui/c-file-upload/c-file-upload.demo.vue')['default']
ChmodCalculator: typeof import('./src/tools/chmod-calculator/chmod-calculator.vue')['default']
Chronometer: typeof import('./src/tools/chronometer/chronometer.vue')['default']
CidrInCidr: typeof import('./src/tools/cidr-in-cidr/cidr-in-cidr.vue')['default']
CInputText: typeof import('./src/ui/c-input-text/c-input-text.vue')['default']
'CInputText.demo': typeof import('./src/ui/c-input-text/c-input-text.demo.vue')['default']
CKeyValueList: typeof import('./src/ui/c-key-value-list/c-key-value-list.vue')['default']
@@ -84,6 +83,7 @@ declare module '@vue/runtime-core' {
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
HddCalculator: typeof import('./src/tools/hdd-calculator/hdd-calculator.vue')['default']
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
HtmlEntities: typeof import('./src/tools/html-entities/html-entities.vue')['default']
@@ -104,7 +104,6 @@ declare module '@vue/runtime-core' {
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
IpInRange: typeof import('./src/tools/cidr-in-cidr/cidr-in-cidr.vue')['default']
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
@@ -136,13 +135,14 @@ declare module '@vue/runtime-core' {
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NTable: typeof import('naive-ui')['NTable']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
-1
View File
@@ -70,7 +70,6 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-matching": "^2.1.2",
"js-base64": "^3.7.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
+8448 -6650
View File
File diff suppressed because it is too large. Load diff
@@ -1,48 +0,0 @@
import { describe, expect, it } from 'vitest';
import { cidrInCidr } from './cidr-in-cidr.service';
describe('cidr-in-cidr', () => {
describe('cidrInCidr', () => {
it('should return correct inclusion', () => {
expect(cidrInCidr({ baseRange: '192.168.0.0/16', ipOrRangeToTest: '192.168.0.1' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.1.0/24', ipOrRangeToTest: '192.168.0.10' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.1.*', ipOrRangeToTest: '192.168.0.10' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.0/24', ipOrRangeToTest: '192.168.0.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0/24', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.*', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.*', ipOrRangeToTest: '192.168.0.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.12' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.20' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.9-192.168.20.12' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.9-192.168.20.20' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0-192.168.20.255', ipOrRangeToTest: '192.168.20.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0-192.168.20.255', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.0-192.168.1.255', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(true); // NOSONAR
});
it('should return correct subnet', () => {
expect(cidrInCidr({ baseRange: '192.168.0.0/16', ipOrRangeToTest: '192.168.0.1' }).baseSubnets).to.deep.eq([ // NOSONAR
{
cidr: '192.168.0.0/16', // NOSONAR
end: '192.168.255.255', // NOSONAR
start: '192.168.0.0', // NOSONAR
},
]);
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.3', ipOrRangeToTest: '192.168.1.0/28' }).baseSubnets).to.deep.eq([ // NOSONAR
{
cidr: '192.168.20.1/32', // NOSONAR
end: '192.168.20.1', // NOSONAR
start: '192.168.20.1', // NOSONAR
},
{
cidr: '192.168.20.2/31', // NOSONAR
end: '192.168.20.3', // NOSONAR
start: '192.168.20.2', // NOSONAR
},
]);
});
});
});
@@ -1,28 +0,0 @@
import { getMatch } from 'ip-matching';
export function cidrInCidr(
{ baseRange, ipOrRangeToTest }:
{
baseRange: string
ipOrRangeToTest: string
}) {
const baseMatchMasks = getMatch(baseRange)?.convertToMasks() || [];
const ipOrRangeToTestMatchMasks = getMatch(ipOrRangeToTest)?.convertToMasks() || [];
const baseSubnets = baseMatchMasks.map((mask) => {
const subnet = mask.convertToSubnet();
if (!subnet) {
return { cidr: '', start: '', end: '' };
}
return {
cidr: subnet.toString(),
start: subnet.getFirst().toString(),
end: subnet.getLast().toString(),
};
}).filter(subnet => subnet.cidr !== '');
return {
baseSubnets,
isIncluded: baseMatchMasks.some(baseMask => ipOrRangeToTestMatchMasks.every(ipOrRangeMask => ipOrRangeMask.isSubsetOf(baseMask))),
};
}
-80
View File
@@ -1,80 +0,0 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core';
import { Check as CheckIcon, LetterX as CrossIcon } from '@vicons/tabler';
import { getMatch } from 'ip-matching';
import { cidrInCidr } from './cidr-in-cidr.service';
import { withDefaultOnError } from '@/utils/defaults';
import { isNotThrowing } from '@/utils/boolean';
import SpanCopyable from '@/components/SpanCopyable.vue';
const baseRange = useStorage('cidr-in-cidr:range', '192.168.0.1/24'); // NOSONAR
const ipOrRangeToTest = useStorage('cidr-in-cidr:ip', '192.168.0.1'); // NOSONAR
const matchResult = computed(() => withDefaultOnError(
() => cidrInCidr({ baseRange: baseRange.value, ipOrRangeToTest: ipOrRangeToTest.value }),
{ baseSubnets: [], isIncluded: false }));
const rangeValidationRules = [
{
message: 'We cannot parse this CIDR/IP Range/Mask/Wildcard, check the format',
validator: (value: string) => isNotThrowing(() => getMatch(value)) && getMatch(value),
},
];
</script>
<template>
<div>
<c-input-text
v-model:value="baseRange"
label="An IPv4/6 CIDR/Range/Mask/Wildcard (base network)"
placeholder="The ipv4/6 CIDR..."
:validation-rules="rangeValidationRules"
mb-4
/>
<c-input-text
v-model:value="ipOrRangeToTest"
label="An IPv4/6 CIDR/Range/Mask/Wildcard (to test for inclusion)"
placeholder="The An IPv4/6 CIDR/Range/Mask/Wildcard..."
:validation-rules="rangeValidationRules"
mb-4
/>
<n-divider />
<div flex justify-center>
<span v-if="matchResult.isIncluded">
<n-icon color="green">
<CheckIcon />
</n-icon>
Included
</span>
<span v-else>
<n-icon color="red">
<CrossIcon />
</n-icon>
Not included
</span>
</div>
<n-divider />
<c-card title="Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in matchResult.baseSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
</div>
</template>
-13
View File
@@ -1,13 +0,0 @@
import { UnfoldMoreOutlined } from '@vicons/material';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'IPv4-6/IPRange/CIDR in IPRange/CIDR/IPMask',
path: '/cidr-in-cidr',
description: 'Given a CIDR/IP Range/Wildcard IP/IP Mask, tell if a given IPv4-6/Range/CIDR/Wildcard IP/IP Mask is in subnet range',
keywords: ['ip', 'cidr', 'range', 'mask', 'wildcard', 'ipv4', 'ipv6', 'subnet', 'include', 'inclusion'],
component: () => import('./cidr-in-cidr.vue'),
redirectFrom: ['/ip-in-range'],
icon: UnfoldMoreOutlined,
createdAt: new Date('2025-01-12'),
});
@@ -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];
const toUnitBin = unitsConversion[toUnit].bin;
return claimedCapacity * fromUnit.dec / toUnitBin;
};
@@ -0,0 +1,45 @@
<script setup lang="ts">
import InputCopyable from '../../components/InputCopyable.vue';
import type { Units } from './hdd-calculator.service';
import { getRealSize } from './hdd-calculator.service';
const dec_units = [
{ value: 'kb', label: 'kB' },
{ value: 'mb', label: 'MB' },
{ value: 'gb', label: 'GB' },
{ value: 'tb', label: 'TB' },
{ value: 'pb', label: 'PB' },
];
const bin_units = [
{ value: 'kb', label: 'KiB' },
{ value: 'mb', label: 'MiB' },
{ value: 'gb', label: 'GiB' },
{ value: 'tb', label: 'TiB' },
{ value: 'pb', label: 'PiB' },
];
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="dec_units"
/>
<n-divider />
<InputCopyable
v-for="({ value, label }) in bin_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: 'Storage device manufacturers report capacities in decimal form (like GB), while operating systems and other software uses binary form (GiB), although still incorrectly using the decimal unit (GiB). This tool converts decimal form capacity into various binary forms.',
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'),
});
+3 -10
View File
@@ -7,6 +7,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 xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as regexTester } from './regex-tester';
@@ -86,7 +87,6 @@ import { tool as urlParser } from './url-parser';
import { tool as uuidGenerator } from './uuid-generator';
import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
import { tool as cidrInCidr } from './cidr-in-cidr';
import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
@@ -114,6 +114,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
hddCalculator,
xmlToJson,
jsonToXml,
markdownToHtml,
@@ -165,15 +166,7 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
cidrInCidr,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
],
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
},
{
name: 'Math',