feat(new tool): Speed Converter

Fix #305
This commit is contained in:
ShareVB committed 2026-01-31 00:15:42 +01:00
1 parent 9b0b1ee261
commit 6438a366b2
6 files changed
+85 -13

No files matched your search

+1
View File
@@ -333,6 +333,7 @@
"ulid": "^3.0.2",
"unicode-emoji-json": "^0.8.0",
"unique-random": "^4.0.0",
"units-converter": "^1.0.3",
"unixcrypt-browser": "^2.0.4",
"unpdf": "^1.4.0",
"unplugin-auto-import": "^0.16.4",
+8
View File
@@ -888,6 +888,9 @@ importers:
unique-random:
specifier: ^4.0.0
version: 4.0.0
units-converter:
specifier: ^1.0.3
version: 1.0.3
unixcrypt-browser:
specifier: ^2.0.4
version: 2.0.4
@@ -10799,6 +10802,9 @@ packages:
unist-util-visit@5.0.0:
resolution: {integrity: sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==}
units-converter@1.0.3:
resolution: {integrity: sha512-tcAwnZxH8NUx0T/eltQ2CUZ21jJxLRHF7dkPoYDFdX+W+VHxbvb/aH5xXBa0Cdp1tpyFI6rju+Jnpj9seuudqg==}
universalify@0.2.0:
resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==}
engines: {node: '>= 4.0.0'}
@@ -22829,6 +22835,8 @@ snapshots:
unist-util-is: 6.0.0
unist-util-visit-parents: 6.0.1
units-converter@1.0.3: {}
universalify@0.2.0: {}
universalify@2.0.0: {}
+33 -13
View File
@@ -1,17 +1,20 @@
<script setup lang="ts">
import _ from 'lodash';
import convert, { type Unit } from 'convert';
import * as unitsconverter from 'units-converter';
const props = withDefaults(defineProps<{
supportedUnits: { [key: string]: string }
defaultUnit: string
labelWidth?: string
unitMinWidth?: string
converterType: 'convert' | 'frequency' | 'volumeFlowRate' | 'speed' | 'acceleration'
}>(), {
labelWidth: '150px',
unitMinWidth: '50px',
converterType: 'convert',
});
const { supportedUnits, defaultUnit, labelWidth, unitMinWidth } = toRefs(props);
const { supportedUnits, defaultUnit, labelWidth, unitMinWidth, converterType } = toRefs(props);
const SI_PREFIX_NAMES = [
'quetta',
@@ -73,19 +76,36 @@ function update(key: string) {
}
const { ref: value } = units[key];
const converter = convert(value, key as Unit);
if (converterType.value === 'convert') {
const converter = convert(value, key as Unit);
_.chain(units)
.omit(key)
.forEach(({ unit }) => {
try {
units[unit].ref = converter.to(unit as Unit);
}
catch (e: any) {
units[unit].ref = 0;
}
})
.value();
_.chain(units)
.omit(key)
.forEach(({ unit }) => {
try {
units[unit].ref = converter.to(unit as Unit);
}
catch (e: any) {
units[unit].ref = 0;
}
})
.value();
}
else {
const converter = unitsconverter[converterType.value](value).from(key);
_.chain(units)
.omit(key)
.forEach(({ unit }) => {
try {
units[unit].ref = converter.to(unit).value;
}
catch (e: any) {
units[unit].ref = 0;
}
})
.value();
}
}
update(defaultUnit.value);
+13
View File
@@ -39,6 +39,19 @@ declare module 'vite-plugin-splash-screen/runtime' {
export function hideSplashScreen();
}
declare module 'units-converter' {
interface ITo{
to(unit: string): { value: number }
}
interface IFrom{
from(unit: string): ITo
}
export function frequency(value: number): IFrom;
export function volumeFlowRate(value: number): IFrom;
export function acceleration(value: number): IFrom;
export function speed(value: number): IFrom;
}
interface BigInt {
toJSON: () => string;
}
+15
View File
@@ -0,0 +1,15 @@
import { Speedboat } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Speed Converter',
path: '/speed-converter',
description: 'Convert values between speed units',
keywords: ['speed', 'converter',
'units', 'm/s', 'km/h', 'm/h', 'knot', 'ft/s',
],
component: () => import('./speed-converter.vue'),
icon: Speedboat,
createdAt: new Date('2026-01-30'),
category: 'Physics',
});
@@ -0,0 +1,15 @@
<script setup lang="ts">
import UnitsConverter from '@/components/UnitsConverter.vue';
const supportedUnits = {
'm/s': 'meter per second',
'km/h': 'kilometer per hour',
'm/h': 'meter per hour',
'knot': 'knot',
'ft/s': 'feet per second',
}; ;
</script>
<template>
<UnitsConverter default-unit="m/s" converter-type="speed" :supported-units="supportedUnits" label-width="150px" />
</template>