From f54223fb0aaedbd101b5d3dc4176053533bb936a Mon Sep 17 00:00:00 2001
From: Corentin Thomasset <corentin.thomasset74@gmail.com>
Date: Thu, 4 Aug 2022 21:59:48 +0200
Subject: refactor(validation): simplified validation management with helpers

---
 src/tools/url-parser/url-parser.vue | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

(limited to 'src/tools/url-parser/url-parser.vue')

diff --git a/src/tools/url-parser/url-parser.vue b/src/tools/url-parser/url-parser.vue
index 78b732a..3b18ca1 100644
--- a/src/tools/url-parser/url-parser.vue
+++ b/src/tools/url-parser/url-parser.vue
@@ -27,10 +27,11 @@
 </template>
 
 <script setup lang="ts">
-import { computed, ref } from 'vue';
-import { SubdirectoryArrowRightRound } from '@vicons/material';
 import { useValidation } from '@/composable/validation';
+import { isNotThrowing } from '@/utils/boolean';
 import { withDefaultOnError } from '@/utils/defaults';
+import { SubdirectoryArrowRightRound } from '@vicons/material';
+import { computed, ref } from 'vue';
 import InputCopyable from '../../components/InputCopyable.vue';
 
 const urlToParse = ref('https://me:pwd@it-tools.tech:3000/url-parser?key1=value&key2=value2#the-hash');
@@ -40,14 +41,7 @@ const validation = useValidation({
   source: urlToParse,
   rules: [
     {
-      validator: (value) => {
-        try {
-          new URL(value);
-          return true;
-        } catch (_) {
-          return false;
-        }
-      },
+      validator: (value) => isNotThrowing(() => new URL(value)),
       message: 'Invalid url',
     },
   ],
-- 
cgit v1.2.3

