mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 16:56:14 -04:00
refactor(validation): simplified validation management with helpers
This commit is contained in:
parent
b38ab82d05
commit
f54223fb0a
5 changed files with 35 additions and 39 deletions
|
@ -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',
|
||||
},
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue