diff options
author | 2023-05-28 23:13:24 +0200 | |
---|---|---|
committer | 2023-05-28 23:29:14 +0200 | |
commit | 33c9b6643f58a6930043f460d5bfdca4bc1f7222 (patch) | |
tree | f313935e30f7b90ea16e564e7171e2e72319ce29 /src/tools/integer-base-converter/integer-base-converter.vue | |
parent | 4d2b037dbe4e78aa90a4a6d9c7315dcf0a51fed9 (diff) | |
download | it-tools-33c9b6643f58a6930043f460d5bfdca4bc1f7222.tar.gz it-tools-33c9b6643f58a6930043f460d5bfdca4bc1f7222.tar.zst it-tools-33c9b6643f58a6930043f460d5bfdca4bc1f7222.zip |
chore(lint): switched to a better lint config
Diffstat (limited to 'src/tools/integer-base-converter/integer-base-converter.vue')
-rw-r--r-- | src/tools/integer-base-converter/integer-base-converter.vue | 105 |
1 files changed, 58 insertions, 47 deletions
diff --git a/src/tools/integer-base-converter/integer-base-converter.vue b/src/tools/integer-base-converter/integer-base-converter.vue index 058d831..01f6401 100644 --- a/src/tools/integer-base-converter/integer-base-converter.vue +++ b/src/tools/integer-base-converter/integer-base-converter.vue @@ -1,56 +1,103 @@ +<script setup lang="ts"> +import { computed, ref } from 'vue'; +import InputCopyable from '../../components/InputCopyable.vue'; +import { convertBase } from './integer-base-converter.model'; +import { useStyleStore } from '@/stores/style.store'; +import { getErrorMessageIfThrows } from '@/utils/error'; + +const styleStore = useStyleStore(); + +const inputProps = { + 'labelPosition': 'left', + 'labelWidth': '170px', + 'labelAlign': 'right', + 'readonly': true, + 'mb-2': '', +} as const; + +const input = ref('42'); +const inputBase = ref(10); +const outputBase = ref(42); + +function errorlessConvert(...args: Parameters<typeof convertBase>) { + try { + return convertBase(...args); + } + catch (err) { + return ''; + } +} + +const error = computed(() => + getErrorMessageIfThrows(() => + convertBase({ value: input.value, fromBase: inputBase.value, toBase: outputBase.value }), + ), +); +</script> + <template> <div> <c-card> <div v-if="styleStore.isSmallScreen"> <n-input-group> - <n-input-group-label style="flex: 0 0 120px"> Input number: </n-input-group-label> + <n-input-group-label style="flex: 0 0 120px"> + Input number: + </n-input-group-label> <n-input v-model:value="input" w-full :status="error ? 'error' : undefined" /> </n-input-group> <n-input-group> - <n-input-group-label style="flex: 0 0 120px"> Input base: </n-input-group-label> + <n-input-group-label style="flex: 0 0 120px"> + Input base: + </n-input-group-label> <n-input-number v-model:value="inputBase" max="64" min="2" w-full /> </n-input-group> </div> <n-input-group v-else> - <n-input-group-label style="flex: 0 0 120px"> Input number: </n-input-group-label> + <n-input-group-label style="flex: 0 0 120px"> + Input number: + </n-input-group-label> <n-input v-model:value="input" :status="error ? 'error' : undefined" /> - <n-input-group-label style="flex: 0 0 120px"> Input base: </n-input-group-label> + <n-input-group-label style="flex: 0 0 120px"> + Input base: + </n-input-group-label> <n-input-number v-model:value="inputBase" max="64" min="2" /> </n-input-group> - <n-alert v-if="error" style="margin-top: 25px" type="error">{{ error }}</n-alert> + <n-alert v-if="error" style="margin-top: 25px" type="error"> + {{ error }} + </n-alert> <n-divider /> - <input-copyable + <InputCopyable label="Binary (2)" v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 2 })" placeholder="Binary version will be here..." /> - <input-copyable + <InputCopyable label="Octal (8)" v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 8 })" placeholder="Octal version will be here..." /> - <input-copyable + <InputCopyable label="Decimal (10)" v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 10 })" placeholder="Decimal version will be here..." /> - <input-copyable + <InputCopyable label="Hexadecimal (16)" v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 16 })" placeholder="Hexadecimal version will be here..." /> - <input-copyable + <InputCopyable label="Base64 (64)" v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 64 })" @@ -63,7 +110,7 @@ <n-input-number v-model:value="outputBase" max="64" min="2" /> </n-input-group> - <input-copyable + <InputCopyable flex-1 v-bind="inputProps" :value="errorlessConvert({ value: input, fromBase: inputBase, toBase: outputBase })" @@ -74,42 +121,6 @@ </div> </template> -<script setup lang="ts"> -import { computed, ref } from 'vue'; -import { useStyleStore } from '@/stores/style.store'; -import { getErrorMessageIfThrows } from '@/utils/error'; -import { convertBase } from './integer-base-converter.model'; -import InputCopyable from '../../components/InputCopyable.vue'; - -const styleStore = useStyleStore(); - -const inputProps = { - labelPosition: 'left', - labelWidth: '170px', - labelAlign: 'right', - readonly: true, - 'mb-2': '', -} as const; - -const input = ref('42'); -const inputBase = ref(10); -const outputBase = ref(42); - -function errorlessConvert(...args: Parameters<typeof convertBase>) { - try { - return convertBase(...args); - } catch (err) { - return ''; - } -} - -const error = computed(() => - getErrorMessageIfThrows(() => - convertBase({ value: input.value, fromBase: inputBase.value, toBase: outputBase.value }), - ), -); -</script> - <style lang="less" scoped> .n-input-group:not(:first-child) { margin-top: 5px; |