diff options
author | 2022-08-04 21:59:48 +0200 | |
---|---|---|
committer | 2022-08-04 21:59:48 +0200 | |
commit | f54223fb0aaedbd101b5d3dc4176053533bb936a (patch) | |
tree | 7c34fb3c3aff23a88ef03052d66d1507f33cf7f0 /src/tools/url-encoder/url-encoder.vue | |
parent | b38ab82d05147b3c7452e79c6edb07e2ced18267 (diff) | |
download | it-tools-f54223fb0aaedbd101b5d3dc4176053533bb936a.tar.gz it-tools-f54223fb0aaedbd101b5d3dc4176053533bb936a.tar.zst it-tools-f54223fb0aaedbd101b5d3dc4176053533bb936a.zip |
refactor(validation): simplified validation management with helpers
Diffstat (limited to 'src/tools/url-encoder/url-encoder.vue')
-rw-r--r-- | src/tools/url-encoder/url-encoder.vue | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/tools/url-encoder/url-encoder.vue b/src/tools/url-encoder/url-encoder.vue index d48b715..edbb462 100644 --- a/src/tools/url-encoder/url-encoder.vue +++ b/src/tools/url-encoder/url-encoder.vue @@ -60,6 +60,7 @@ <script setup lang="ts"> import { useCopy } from '@/composable/copy'; import { useValidation } from '@/composable/validation'; +import { isNotThrowing } from '@/utils/boolean'; import { withDefaultOnError } from '@/utils/defaults'; import { computed, ref } from 'vue'; @@ -70,14 +71,7 @@ const encodedValidation = useValidation({ source: encodeInput, rules: [ { - validator: (value) => { - try { - encodeURIComponent(value); - return true; - } catch (_) { - return false; - } - }, + validator: (value) => isNotThrowing(() => encodeURIComponent(value)), message: 'Impossible to parse this string', }, ], @@ -92,14 +86,7 @@ const decodeValidation = useValidation({ source: encodeInput, rules: [ { - validator: (value) => { - try { - decodeURIComponent(value); - return true; - } catch (_) { - return false; - } - }, + validator: (value) => isNotThrowing(() => decodeURIComponent(value)), message: 'Impossible to parse this string', }, ], |