forked from CorentinTh/it-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All units, pressure, power, angle, area, energy, force, length, mass, volume units converter Many Units Converter: convert any unit string (ie 1d 3m) into best unit and selected target unit Fix CorentinTh#571
- Loading branch information
Showing
26 changed files
with
686 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,71 @@ | ||
<script setup lang="ts"> | ||
import _ from 'lodash'; | ||
import convert, { type Unit } from 'convert'; | ||
const props = withDefaults(defineProps<{ | ||
supportedUnits: { [key: string]: string } | ||
defaultUnit: string | ||
labelWidth?: string | ||
unitMinWidth?: string | ||
}>(), { | ||
labelWidth: '150px', | ||
unitMinWidth: '50px', | ||
}); | ||
const { supportedUnits, defaultUnit, labelWidth, unitMinWidth } = toRefs(props); | ||
const units = reactive< | ||
Record< | ||
string, | ||
{ title: string; unit: string; ref: number } | ||
> | ||
>(Object.entries(supportedUnits.value).map(([key, label]) => ({ | ||
title: label, | ||
unit: key, | ||
ref: 1, | ||
})).reduce((prev, current) => ({ | ||
...prev, | ||
[current.unit]: current, | ||
}), {})); | ||
function update(key: string) { | ||
if (!units[key]) { | ||
return; | ||
} | ||
const { ref: value } = units[key]; | ||
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(); | ||
} | ||
update(defaultUnit.value); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<n-input-group v-for="[key, { title, unit }] in Object.entries(units)" :key="key" mb-3 w-full> | ||
<n-input-group-label :style="{ width: labelWidth }"> | ||
{{ title }} | ||
</n-input-group-label> | ||
|
||
<n-input-number | ||
v-model:value="units[key].ref" | ||
style="flex: 1" | ||
@update:value="() => update(key)" | ||
/> | ||
|
||
<n-input-group-label :style="{ minWidth: unitMinWidth }"> | ||
{{ unit }} | ||
</n-input-group-label> | ||
</n-input-group> | ||
</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,16 @@ | ||
<script setup lang="ts"> | ||
import UnitsConverter from '@/components/UnitsConverter.vue'; | ||
const supportedUnits = { | ||
deg: 'degree (°)', | ||
rad: 'radian', | ||
turn: 'turn', | ||
gradian: 'gradian', | ||
grad: 'grad', | ||
gon: 'gon', | ||
}; | ||
</script> | ||
|
||
<template> | ||
<UnitsConverter default-unit="deg" :supported-units="supportedUnits" label-width="150px" /> | ||
</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,12 @@ | ||
import { Angle } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Angle Units Converter', | ||
path: '/angle-converter', | ||
description: 'Convert values between angle units', | ||
keywords: ['angle', 'converter'], | ||
component: () => import('./angle-converter.vue'), | ||
icon: Angle, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
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,35 @@ | ||
<script setup lang="ts"> | ||
import UnitsConverter from '@/components/UnitsConverter.vue'; | ||
const supportedUnits = { | ||
'm²': 'square meter', | ||
'Pm²': 'square petameter', | ||
'Tm²': 'square terameter', | ||
'Gm²': 'square gigameter', | ||
'Mm²': 'square megameter', | ||
'km²': 'square kilometer', | ||
'hm²': 'square hectometer', | ||
'dam²': 'square decameter', | ||
'dm²': 'square decimeter', | ||
'cm²': 'square centimeter', | ||
'mm²': 'square millimeter', | ||
'μm²': 'square micrometer', | ||
'nm²': 'square nanometer', | ||
'pm²': 'square picometer', | ||
'fm²': 'square femtometer', | ||
'ac': 'acre', | ||
'ca': 'centiare', | ||
'da': 'deciare', | ||
'are': 'are', | ||
'daa': 'decare', | ||
'ha': 'hectare', | ||
'ft²': 'square foot (/ft2/sq ft)', | ||
'in²': 'square inch (/in2/sq in)', | ||
'yd²': 'square yard (yd2/sq yd)', | ||
'mi²': 'square mile (mi2/sq mi)', | ||
}; | ||
</script> | ||
|
||
<template> | ||
<UnitsConverter default-unit="m²" :supported-units="supportedUnits" label-width="150px" /> | ||
</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,12 @@ | ||
import { SquaresDiagonal } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Area Units Converter', | ||
path: '/area-converter', | ||
description: 'Convert values between area units', | ||
keywords: ['area', 'converter'], | ||
component: () => import('./area-converter.vue'), | ||
icon: SquaresDiagonal, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
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,40 @@ | ||
<script setup lang="ts"> | ||
import UnitsConverter from '@/components/UnitsConverter.vue'; | ||
const supportedUnits = { | ||
J: 'joule', | ||
PJ: 'petajoule', | ||
TJ: 'terajoule', | ||
GJ: 'gigajoule', | ||
MJ: 'megajoule', | ||
kJ: 'kilojoule', | ||
hJ: 'hectojoule', | ||
daJ: 'decajoule', | ||
dJ: 'decijoule', | ||
cJ: 'centijoule', | ||
mJ: 'millijoule', | ||
µJ: 'microjoule', | ||
nJ: 'nanojoule', | ||
pJ: 'picojoule', | ||
fJ: 'femtojoule', | ||
Wh: 'watt-hour', | ||
PWh: 'petawatt-hour', | ||
TWh: 'terawatt-hour', | ||
GWh: 'gigawatt-hour', | ||
MWh: 'megawatt-hour', | ||
kWh: 'kilowatt-hour', | ||
hWh: 'hectowatt-hour', | ||
daWh: 'decawatt-hour', | ||
dWh: 'deciwatt-hour', | ||
cWh: 'centiwatt-hour', | ||
mWh: 'milliwatt-hour', | ||
µWh: 'microwatt-hour', | ||
nWh: 'nanowatt-hour', | ||
pWh: 'picowatt-hour', | ||
fWh: 'femtowatt-hour', | ||
}; | ||
</script> | ||
|
||
<template> | ||
<UnitsConverter default-unit="J" :supported-units="supportedUnits" label-width="150px" /> | ||
</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,12 @@ | ||
import { Power } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Energy Units Converter', | ||
path: '/energy-converter', | ||
description: 'Convert values between energy units', | ||
keywords: ['energy', 'converter'], | ||
component: () => import('./energy-converter.vue'), | ||
icon: Power, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
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 UnitsConverter from '@/components/UnitsConverter.vue'; | ||
const supportedUnits = { | ||
'N': 'newton', | ||
'PN': 'petanewton', | ||
'TN': 'teranewton', | ||
'GN': 'giganewton', | ||
'MN': 'meganewton', | ||
'kN': 'kilonewton', | ||
'hN': 'hectonewton', | ||
'daN': 'decanewton', | ||
'dN': 'decinewton', | ||
'cN': 'centinewton', | ||
'mN': 'millinewton', | ||
'µN': 'micronewton', | ||
'nN': 'nanonewton', | ||
'pN': 'piconewton', | ||
'fN': 'femtonewton', | ||
'dyn': 'dyne', | ||
'lbf': 'pound of force', | ||
'kip': 'kip', | ||
'klb': 'klb', | ||
'kipf': 'kipf', | ||
'klbf': 'klbf', | ||
'pdl': 'poundal', | ||
'kgf': 'kilogram-force', | ||
'kp': 'kilopond', | ||
'Mp': 'megapond', | ||
'tf': 'tonne-force', | ||
'metric tf': 'metric ton-force', | ||
'megagram-force': 'megagram-force', | ||
}; | ||
</script> | ||
|
||
<template> | ||
<UnitsConverter default-unit="N" :supported-units="supportedUnits" label-width="150px" /> | ||
</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,12 @@ | ||
import { Power } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Force Units Converter', | ||
path: '/force-converter', | ||
description: 'Convert values between force units', | ||
keywords: ['force', 'converter'], | ||
component: () => import('./force-converter.vue'), | ||
icon: Power, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
Oops, something went wrong.