2022-04-13 13:29:44 +02:00
|
|
|
<template>
|
2022-04-24 23:09:12 +02:00
|
|
|
<n-card title="Encode">
|
|
|
|
<n-form-item
|
|
|
|
label="Your string :"
|
|
|
|
:feedback="encodedValidation.message"
|
|
|
|
:validation-status="encodedValidation.status"
|
|
|
|
>
|
|
|
|
<n-input
|
|
|
|
v-model:value="encodeInput"
|
|
|
|
type="textarea"
|
|
|
|
placeholder="The string to encode"
|
|
|
|
:autosize="{ minRows: 2 }"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-24 23:09:12 +02:00
|
|
|
<n-form-item label="Your string encoded :">
|
|
|
|
<n-input
|
|
|
|
:value="encodeOutput"
|
|
|
|
type="textarea"
|
|
|
|
readonly
|
|
|
|
placeholder="Your string encoded"
|
|
|
|
:autosize="{ minRows: 2 }"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-24 23:09:12 +02:00
|
|
|
<n-space justify="center">
|
|
|
|
<n-button secondary @click="copyEncoded"> Copy </n-button>
|
|
|
|
</n-space>
|
|
|
|
</n-card>
|
|
|
|
<n-card title="Decode">
|
|
|
|
<n-form-item
|
|
|
|
label="Your encoded string :"
|
|
|
|
:feedback="decodeValidation.message"
|
|
|
|
:validation-status="decodeValidation.status"
|
|
|
|
>
|
|
|
|
<n-input
|
|
|
|
v-model:value="decodeInput"
|
|
|
|
type="textarea"
|
|
|
|
placeholder="The string to decode"
|
|
|
|
:autosize="{ minRows: 2 }"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-24 23:09:12 +02:00
|
|
|
<n-form-item label="Your string decoded :">
|
|
|
|
<n-input
|
|
|
|
:value="decodeOutput"
|
|
|
|
type="textarea"
|
|
|
|
readonly
|
|
|
|
placeholder="Your string decoded"
|
|
|
|
:autosize="{ minRows: 2 }"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-24 23:09:12 +02:00
|
|
|
<n-space justify="center">
|
|
|
|
<n-button secondary @click="copyDecoded"> Copy </n-button>
|
|
|
|
</n-space>
|
|
|
|
</n-card>
|
2022-04-13 13:29:44 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { useCopy } from '@/composable/copy';
|
|
|
|
import { useValidation } from '@/composable/validation';
|
2022-08-04 22:57:24 +02:00
|
|
|
import { withDefaultOnError } from '@/utils/defaults';
|
2022-04-22 23:31:40 +02:00
|
|
|
import { computed, ref } from 'vue';
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const encodeInput = ref('Hello world :)');
|
2022-08-04 22:57:24 +02:00
|
|
|
const encodeOutput = computed(() => withDefaultOnError(() => encodeURIComponent(encodeInput.value), ''));
|
2022-04-13 13:29:44 +02:00
|
|
|
|
|
|
|
const encodedValidation = useValidation({
|
2022-04-22 23:31:40 +02:00
|
|
|
source: encodeInput,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
validator: (value) => {
|
|
|
|
try {
|
|
|
|
encodeURIComponent(value);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
message: 'Impossible to parse this string',
|
2022-04-16 16:16:00 +02:00
|
|
|
},
|
2022-04-22 23:31:40 +02:00
|
|
|
],
|
|
|
|
});
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const { copy: copyEncoded } = useCopy({ source: encodeOutput, text: 'Encoded string copied to the clipboard' });
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const decodeInput = ref('Hello%20world%20%3A)');
|
2022-08-04 22:57:24 +02:00
|
|
|
const decodeOutput = computed(() => withDefaultOnError(() => decodeURIComponent(decodeInput.value), ''));
|
2022-04-13 13:29:44 +02:00
|
|
|
|
|
|
|
const decodeValidation = useValidation({
|
2022-04-22 23:31:40 +02:00
|
|
|
source: encodeInput,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
validator: (value) => {
|
|
|
|
try {
|
|
|
|
decodeURIComponent(value);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
message: 'Impossible to parse this string',
|
2022-04-16 16:16:00 +02:00
|
|
|
},
|
2022-04-22 23:31:40 +02:00
|
|
|
],
|
|
|
|
});
|
2022-04-13 13:29:44 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded string copied to the clipboard' });
|
2022-04-13 13:29:44 +02:00
|
|
|
</script>
|