aboutsummaryrefslogtreecommitdiff
path: root/src/tools/math-evaluator/math-evaluator.vue
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-08-04 22:57:24 +0200
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-08-04 23:14:32 +0200
commitf6cd9b76d38800e1a1f63d07152fc96cda562795 (patch)
tree2e794a084bacab1fbbf62b52b7c94e955a7e8463 /src/tools/math-evaluator/math-evaluator.vue
parent208a373fd08ac550778745eb6e4536bf02537da7 (diff)
downloadit-tools-f6cd9b76d38800e1a1f63d07152fc96cda562795.tar.gz
it-tools-f6cd9b76d38800e1a1f63d07152fc96cda562795.tar.zst
it-tools-f6cd9b76d38800e1a1f63d07152fc96cda562795.zip
refactor(dry): mutualised duplicated code with withDefaultOnError
Diffstat (limited to 'src/tools/math-evaluator/math-evaluator.vue')
-rw-r--r--src/tools/math-evaluator/math-evaluator.vue9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/tools/math-evaluator/math-evaluator.vue b/src/tools/math-evaluator/math-evaluator.vue
index 26fb6b1..59754de 100644
--- a/src/tools/math-evaluator/math-evaluator.vue
+++ b/src/tools/math-evaluator/math-evaluator.vue
@@ -21,18 +21,13 @@
</template>
<script setup lang="ts">
+import { withDefaultOnError } from '@/utils/defaults';
import { evaluate } from 'mathjs';
import { computed, ref } from 'vue';
const expression = ref('');
-const result = computed(() => {
- try {
- return evaluate(expression.value) ?? '';
- } catch (_) {
- return '';
- }
-});
+const result = computed(() => withDefaultOnError(() => evaluate(expression.value) ?? '', ''));
</script>
<style lang="less" scoped></style>