From edfb3f575be10f2021350ed4d84e98c606785eb3 Mon Sep 17 00:00:00 2001 From: ShareVB Date: Thu, 2 Jan 2025 00:18:38 +0100 Subject: [PATCH] fix: allow all units for bitrate ie, in case of download speed in MB/s --- .eslintrc-auto-import.json | 5 +- auto-imports.d.ts | 9 +++ ...ta-transfer-rate-converter.service.test.ts | 16 ++++-- .../data-transfer-rate-converter.service.ts | 10 ++-- .../data-transfer-rate-converter.vue | 56 ++++++++++--------- 5 files changed, 59 insertions(+), 37 deletions(-) diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 4084d922..d4fd5aac 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -286,6 +286,9 @@ "watchTriggerable": true, "watchWithFilter": true, "whenever": true, - "toValue": true + "toValue": true, + "injectLocal": true, + "provideLocal": true, + "useClipboardItems": true } } diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 186963f1..35bda113 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -36,6 +36,7 @@ declare global { const h: typeof import('vue')['h'] const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch'] const inject: typeof import('vue')['inject'] + const injectLocal: typeof import('@vueuse/core')['injectLocal'] const isDefined: typeof import('@vueuse/core')['isDefined'] const isProxy: typeof import('vue')['isProxy'] const isReactive: typeof import('vue')['isReactive'] @@ -65,6 +66,7 @@ declare global { const onUpdated: typeof import('vue')['onUpdated'] const pausableWatch: typeof import('@vueuse/core')['pausableWatch'] const provide: typeof import('vue')['provide'] + const provideLocal: typeof import('@vueuse/core')['provideLocal'] const reactify: typeof import('@vueuse/core')['reactify'] const reactifyObject: typeof import('@vueuse/core')['reactifyObject'] const reactive: typeof import('vue')['reactive'] @@ -128,6 +130,7 @@ declare global { const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation'] const useCached: typeof import('@vueuse/core')['useCached'] const useClipboard: typeof import('@vueuse/core')['useClipboard'] + const useClipboardItems: typeof import('@vueuse/core')['useClipboardItems'] const useCloned: typeof import('@vueuse/core')['useCloned'] const useColorMode: typeof import('@vueuse/core')['useColorMode'] const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog'] @@ -326,6 +329,7 @@ declare module 'vue' { readonly h: UnwrapRef readonly ignorableWatch: UnwrapRef readonly inject: UnwrapRef + readonly injectLocal: UnwrapRef readonly isDefined: UnwrapRef readonly isProxy: UnwrapRef readonly isReactive: UnwrapRef @@ -355,6 +359,7 @@ declare module 'vue' { readonly onUpdated: UnwrapRef readonly pausableWatch: UnwrapRef readonly provide: UnwrapRef + readonly provideLocal: UnwrapRef readonly reactify: UnwrapRef readonly reactifyObject: UnwrapRef readonly reactive: UnwrapRef @@ -418,6 +423,7 @@ declare module 'vue' { readonly useBrowserLocation: UnwrapRef readonly useCached: UnwrapRef readonly useClipboard: UnwrapRef + readonly useClipboardItems: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef @@ -610,6 +616,7 @@ declare module '@vue/runtime-core' { readonly h: UnwrapRef readonly ignorableWatch: UnwrapRef readonly inject: UnwrapRef + readonly injectLocal: UnwrapRef readonly isDefined: UnwrapRef readonly isProxy: UnwrapRef readonly isReactive: UnwrapRef @@ -639,6 +646,7 @@ declare module '@vue/runtime-core' { readonly onUpdated: UnwrapRef readonly pausableWatch: UnwrapRef readonly provide: UnwrapRef + readonly provideLocal: UnwrapRef readonly reactify: UnwrapRef readonly reactifyObject: UnwrapRef readonly reactive: UnwrapRef @@ -702,6 +710,7 @@ declare module '@vue/runtime-core' { readonly useBrowserLocation: UnwrapRef readonly useCached: UnwrapRef readonly useClipboard: UnwrapRef + readonly useClipboardItems: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef diff --git a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.test.ts b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.test.ts index 9e6b9e86..860ed096 100644 --- a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.test.ts +++ b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { amountTransferable, neededRate, transferTimeSeconds } from './data-transfer-rate-converter.service'; +import { amountTransferable, transferSpeedRate, transferTimeSeconds } from './data-transfer-rate-converter.service'; describe('data-transfer-converter', () => { describe('transferTimeSeconds', () => { @@ -12,9 +12,9 @@ describe('data-transfer-converter', () => { })).toBe(80); }); }); - describe('neededRate', () => { - it('compute neededRate', () => { - expect(neededRate({ + describe('transferSpeedRate', () => { + it('compute transferSpeedRate', () => { + expect(transferSpeedRate({ dataSize: 100, dataSizeUnit: 'MB', hours: 0, @@ -22,6 +22,14 @@ describe('data-transfer-converter', () => { seconds: 20, bitRateUnit: 'Mb', })).toBe(10); + expect(transferSpeedRate({ + dataSize: 100, + dataSizeUnit: 'MB', + hours: 0, + minutes: 1, + seconds: 20, + bitRateUnit: 'MB', + })).toBe(1.25); }); }); describe('amountTransferable', () => { diff --git a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.ts b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.ts index 3ef1b7bd..0ececcc1 100644 --- a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.ts +++ b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.service.ts @@ -1,4 +1,4 @@ -import { type AllSupportedUnits, type BitsUnits, convertStorageAndRateUnits } from '../data-storage-unit-converter/data-storage-unit-converter.service'; +import { type AllSupportedUnits, convertStorageAndRateUnits } from '../data-storage-unit-converter/data-storage-unit-converter.service'; export function transferTimeSeconds({ dataSize, @@ -9,14 +9,14 @@ export function transferTimeSeconds({ dataSize: number dataSizeUnit: AllSupportedUnits bitRate: number - bitRateUnit: BitsUnits + bitRateUnit: AllSupportedUnits }): number { const dataSizeInBytes = convertStorageAndRateUnits({ value: dataSize, fromUnit: dataSizeUnit, toUnit: 'B' }); const bitRateInBytes = convertStorageAndRateUnits({ value: bitRate, fromUnit: bitRateUnit, toUnit: 'B' }); return bitRateInBytes > 0 ? dataSizeInBytes / bitRateInBytes : 0; } -export function neededRate({ +export function transferSpeedRate({ dataSize, dataSizeUnit, hours, @@ -29,7 +29,7 @@ export function neededRate({ hours: number minutes: number seconds: number - bitRateUnit: BitsUnits + bitRateUnit: AllSupportedUnits }): number { const dataSizeInBits = convertStorageAndRateUnits({ value: dataSize, fromUnit: dataSizeUnit, toUnit: 'b' }); const timeInSeconds = hours * 3600 + minutes * 60 + seconds; @@ -45,7 +45,7 @@ export function amountTransferable({ dataSizeUnit, }: { bitRate: number - bitRateUnit: BitsUnits + bitRateUnit: AllSupportedUnits hours: number minutes: number seconds: number diff --git a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue index 2be19cbb..a8128dcb 100644 --- a/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue +++ b/src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue @@ -1,7 +1,7 @@