@@ -12,6 +12,36 @@ const props = withDefaults(defineProps<{
1212 unitMinWidth: ' 50px' ,
1313});
1414const { 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+
1545const 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+
2970function 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