Skip to content

Commit da94c09

Browse files
committed
feat(Units Converter): option to exclude SI prefixes
Fix #295
1 parent 88e0e8b commit da94c09

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7682,3 +7682,8 @@ tools:
76827682
tag-esc: ESC
76837683
tag-exit-dead-pixel-mode: ': Exit Dead Pixel Mode'
76847684
tag-start-dead-pixel: Start Dead Pixel
7685+
UnitsConverter:
7686+
texts:
7687+
exclude-si-prefixes: Exclude SI Prefixes
7688+
text:
7689+
si-converter: Goto SI Prefixes Converter

src/components/UnitsConverter.vue

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ const props = withDefaults(defineProps<{
1212
unitMinWidth: '50px',
1313
});
1414
const { supportedUnits, defaultUnit, labelWidth, unitMinWidth } = toRefs(props);
15+
16+
const SI_PREFIX_NAMES = [
17+
'quetta',
18+
'ronna',
19+
'yotta',
20+
'zetta',
21+
'exa',
22+
'peta',
23+
'tera',
24+
'giga',
25+
'mega',
26+
'kilo',
27+
'hecto',
28+
'deca',
29+
'deci',
30+
'centi',
31+
'milli',
32+
'micro',
33+
'nano',
34+
'pico',
35+
'femto',
36+
'atto',
37+
'zepto',
38+
'yocto',
39+
'ronto',
40+
'quecto',
41+
] as const;
42+
43+
const SI_PREFIX_NAMES_REGEX = new RegExp(`^(${SI_PREFIX_NAMES.join('|')})`);
44+
1545
const units = reactive<
1646
Record<
1747
string,
@@ -26,6 +56,17 @@ const units = reactive<
2656
[current.unit]: current,
2757
}), {}));
2858
59+
const excludeSIPrefixes = ref(true);
60+
const filteredUnits = computed(() => {
61+
if (!excludeSIPrefixes.value) {
62+
return Object.entries(units);
63+
}
64+
65+
return Object.entries(units).filter(
66+
([_, { title }]) => !SI_PREFIX_NAMES_REGEX.test(title),
67+
);
68+
});
69+
2970
function update(key: string) {
3071
if (!units[key]) {
3172
return;
@@ -52,7 +93,15 @@ update(defaultUnit.value);
5293

5394
<template>
5495
<div>
55-
<n-input-group v-for="[key, { title, unit }] in Object.entries(units)" :key="key" mb-3 w-full>
96+
<n-space justify="center" mb-3>
97+
<n-checkbox v-model:checked="excludeSIPrefixes">
98+
{{ $t('tools.UnitsConverter.texts.exclude-si-prefixes') }}
99+
</n-checkbox>
100+
<c-link target="_blank" to="/si-prefixes-converter">
101+
{{ $t('tools.UnitsConverter.text.si-converter') }}
102+
</c-link>
103+
</n-space>
104+
<n-input-group v-for="[key, { title, unit }] in filteredUnits" :key="key" mb-3 w-full>
56105
<n-input-group-label :style="{ width: labelWidth }">
57106
{{ title }}
58107
</n-input-group-label>

0 commit comments

Comments
 (0)